-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooth_tests.py
53 lines (41 loc) · 1.54 KB
/
booth_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
from flask import Flask
import application
import unittest
import models as db
import create_user
TEST_USERNAME = 'booth_test'
TEST_PASSWORD = 'test_secret'
TEST_STATION_ID = 1
TEST_VOTE_URL = "http://results.eelection.co.uk/"
TEST_PUBLIC_KEY = 123123
BAD_LOGIN = 'bad'
class BoothTestCase(unittest.TestCase):
def setUp(self):
application.application.config['TESTING'] = True
self.application = application.application.test_client()
create_user.create_user(TEST_USERNAME, TEST_PASSWORD, TEST_STATION_ID, TEST_VOTE_URL, TEST_PUBLIC_KEY)
def tearDown(self):
db.deleteUser('booth_test')
# Login booth helper function
def login(self):
self.application.post('/login', data=dict(
username=TEST_USERNAME,
password=TEST_PASSWORD
))
def test_home_status_code_not_logged_in(self):
# sends HTTP GET request to the application
# on the specified path
result = self.application.get('/')
# assert the status code of the response for redirection
self.assertEqual(result.status_code, 302)
def test_home_status_code_logged_in(self):
self.login()
result = self.application.get('/')
# assert the status code of the response for redirection
self.assertEqual(result.status_code, 200)
def test_enter_pin_field_logged_in(self):
self.login()
result = self.application.get('/')
assert b'Type in your 6 digit PIN and press Enter' in result.data
if __name__ == '__main__':
unittest.main()