/
tests.py
82 lines (59 loc) · 2.7 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
flask-fillin-tests
~~~~~~~~~~~~~~~~~~
:copyright: (c) 2012 by Christoph Heer.
:license: BSD, see LICENSE for more details.
"""
import unittest
from test_app import app
from flask.testing import FlaskClient
from flask.ext.fillin import FormWrapper
class fillinTest(unittest.TestCase):
def setUp(self):
self.app = app
self.app.testing = True
self.client = FlaskClient(self.app, response_wrapper=FormWrapper)
def tearDown(self):
pass
def test_login_form(self):
response = self.client.get('/login-form')
response.form.fields['username'] = "test"
assert 'Missing password' in response.form.submit(self.client).data
response = self.client.get('/login-form')
response.form.fields['password'] = "secret"
assert 'Missing username' in response.form.submit(self.client).data
response = self.client.get('/login-form')
response.form.fields['username'] = "test"
response.form.fields['password'] = "secret"
assert 'Welcome test' in response.form.submit(self.client).data
def test_data_injection(self):
response = self.client.get('/login-form')
response.form.fields['password'] = "secret"
inject_data = {'username': 'test'}
response = response.form.submit(self.client, data=inject_data)
assert 'Welcome test' in response.data
def test_hidden_field_form(self):
response = self.client.get('/hidden-field-form')
response = response.form.submit(self.client)
assert 'Hidden field received' in response.data
response = self.client.post('/hidden-field-form')
assert 'Missing the hidden field' in response.data
def test_checkbox_form(self):
response = self.client.get('/checkbox-field-form')
response = response.form.submit(self.client)
assert "Checkbox did not check" in response.data
response.form.fields['checkbox_field'] = True
response = response.form.submit(self.client)
assert "Checkbox checked" in response.data
def test_links_get(self):
response = self.client.get('/link')
self.assertEquals(2, len(response.links()), '2 links are parsed from the source')
self.assertEquals('link1', response.link('#link1').text)
self.assertEquals('link2', response.link('.link').text)
def test_link_click(self):
response = self.client.get('/link')
response = response.link("#link1").click(self.client)
self.assertEquals(200, response.status_code)
if __name__ == '__main__':
unittest.main()