Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created January 30, 2013 20:45
Show Gist options
  • Save wesrog/4676770 to your computer and use it in GitHub Desktop.
Save wesrog/4676770 to your computer and use it in GitHub Desktop.
from base import BaseTestCase
from tests.lib.actions import HtmlDocument, click_link, click_button, fill_in
from tests.lib.exceptions import LinkNotFound, ButtonNotFound, InputNotFound
from werkzeug.wrappers import Response
class TestLibActions(BaseTestCase):
def test_click_link(self):
self.assertEqual(click_link(response, 'Explore Releases'), '/releases')
self.assertRaises(LinkNotFound, click_link, response, 'wat')
def test_click_button(self):
self.assertEqual(
click_button(response, 'Create Account')['action'],
'/users/new'
)
self.assertRaises(ButtonNotFound, click_button, response, 'wat')
def test_fill_in(self):
self.assertIn(
'john@example.com',
fill_in(response, 'Email', 'john@example.com')
)
self.assertRaises(InputNotFound, fill_in, response, 'First Name')
response = Response('''
<html>
<head>
<title>Discogs</title>
</head>
<body>
<h1>Discogs</h1>
<p><a href="/releases">Explore Releases</a></p>
<form action="/users/new" method="post">
<p>
<label for="email">Email</label>
<input type="text" name="email" id="email" />
</p>
<p>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" value="Create Account" />
</p>
</form>
</body>
</html>
''')
doc = HtmlDocument(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment