-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_project.py
141 lines (105 loc) · 3.8 KB
/
test_project.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pytest
from website import create_app, db
from website.models import User
from flask import Flask
from werkzeug.security import generate_password_hash, check_password_hash
from flask_login import login_user, login_required, logout_user, current_user
@pytest.fixture()
def app():
app = create_app()
with app.app_context():
db.create_all()
yield app
@pytest.fixture()
def client(app):
return app.test_client()
@pytest.fixture
def runner(app):
return app.test_cli_runner()
def test_sign_up_success(client):
response = client.post('/sign-up', data={
'email': '[email protected]',
'firstName': 'John',
'password1': 'password123',
'password2': 'password123',
'role': 'candidate'
}, follow_redirects=True)
assert response.status_code == 200
def test_sign_up_existing_email(client):
response = client.post('/sign-up', data={
'email': '[email protected]',
'firstName': 'John',
'password1': 'password123',
'password2': 'password123',
'role': 'candidate'
}, follow_redirects=True)
assert response.status_code == 200
assert b'Email already exists.' in response.data
def test_login_success(client):
with client:
response = client.post('/login', data={
'email': '[email protected]',
'password': 'password123'
}, follow_redirects=True)
assert response.status_code == 200
assert b'Logged in successfully!' in response.data
def test_login_incorrect_password(client):
with client:
response = client.post('/login', data={
'email': '[email protected]',
'password': 'wrongpassword'
}, follow_redirects=True)
assert response.status_code == 200
assert b'Incorrect password, try again.' in response.data
def test_login_email_not_exist(client):
with client:
response = client.post('/login', data={
'email': '[email protected]',
'password': 'password123'
}, follow_redirects=True)
assert response.status_code == 200
assert b'Email does not exist.' in response.data
def test_cv_success(client):
response = client.post('/cv', data={
'ProgrammingLanguage': 'Python',
'EngineeringSkill': 'Mechanical Engineering',
'ITSkill': 'Network Administration',
'ManagementSkill': 'Project Management',
'MarketingSkill': 'Digital Marketing',
}, follow_redirects=True)
print(response.status_code)
print(response.data)
assert response.status_code == 200
def test_home_success(client):
with client:
with client.session_transaction() as session:
session['role'] = 'admin'
response = client.post('/', data={
'title': 'Test Note',
'note': 'This is a test note.'
}, follow_redirects=True)
assert response.status_code == 200
def test_create_test_success(client):
with client:
with client.session_transaction() as session:
session['role'] = 'admin'
client.post('/create_test', data={
'test_name': 'Sample Test',
'question_count': '2',
'question_1': 'Question 1',
'option1_1': 'Option 1.1',
'option2_1': 'Option 1.2',
'option3_1': 'Option 1.3',
'option4_1': 'Option 1.4',
'correct_answer_1': 'Option 1.3',
'question_2': 'Question 2',
'option1_2': 'Option 2.1',
'option2_2': 'Option 2.2',
'option3_2': 'Option 2.3',
'option4_2': 'Option 2.4',
'correct_answer_2': 'Option 2.2'
})
response = client.get('/create_test')
print(response.status_code)
print(response.data)
assert response.status_code == 302