Skip to content

Commit 3c90293

Browse files
committed
fix tests
1 parent 1a562ff commit 3c90293

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

app/database/models/mentorship_relation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def delete_from_db(self) -> None:
128128
@validates("notes")
129129
def validate(self, key, value):
130130
if key == "notes":
131-
assert value is not None
132-
value = str(value).strip()
133-
assert len(value.strip()) > 2
131+
if value is not None:
132+
value = str(value).strip()
133+
assert len(value.strip()) > 2
134134
return value

tests/mentorship_relation/test_dao_creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def test_dao_create_mentorship_relation_with_good_args_but_invalid_timestamp(sel
237237
data = dict(
238238
mentor_id=self.first_user.id,
239239
mentee_id=self.second_user.id,
240-
end_date=1580338800000000,
240+
end_date=158033880000,
241241
notes=self.notes_example,
242242
tasks_list=TasksListModel(),
243243
)

tests/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
}
88

99
test_admin_user_2 = {
10-
"name": "Admin_2",
10+
"name": "Adminb",
1111
"email": "[email protected]",
1212
"username": "admin2_username",
1313
"password": "admin2_pwd",
1414
"terms_and_conditions_checked": True,
1515
}
1616

1717
test_admin_user_3 = {
18-
"name": "Admin_3",
18+
"name": "Adminc",
1919
"email": "[email protected]",
2020
"username": "admin3_username",
2121
"password": "admin3_pwd",
@@ -42,23 +42,23 @@
4242
}
4343

4444
user3 = {
45-
"name": "s_t-r$a/n'ge name",
45+
"name": "strange name",
4646
"email": "[email protected]",
4747
"username": "user3",
4848
"password": "user3_pwd",
4949
"terms_and_conditions_checked": True,
5050
}
5151

5252
user4 = {
53-
"name": "[email protected]",
53+
"name": "userc",
5454
"email": "[email protected]",
5555
"username": "user4",
5656
"password": "user4_pwd",
5757
"terms_and_conditions_checked": True,
5858
}
5959

6060
user5 = {
61-
"name": "[email protected]",
61+
"name": "userd",
6262
"email": "[email protected]",
6363
"username": "user5",
6464
"password": "user5_pwd",

tests/users/test_api_change_password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def setUp(self):
2626
super().setUp()
2727
self.first_user = UserModel(
2828
password=user1["password"],
29-
name="User1",
29+
name="User",
3030
3131
username="user_not_admin",
3232
terms_and_conditions_checked=True,

tests/users/test_api_home_statistics.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class TestHomeStatisticsApi(BaseTestCase):
1515
def setUp(self):
1616
super().setUp()
1717

18-
self.user1 = UserModel("User1", "user1", "__test__", "[email protected]", True)
19-
self.user2 = UserModel("User2", "user2", "__test__", "[email protected]", True)
18+
self.user1 = UserModel("UserA", "user1", "__test__", "[email protected]", True)
19+
self.user2 = UserModel("UserB", "user2", "__test__", "[email protected]", True)
2020
self.user1.available_to_mentor = True
2121
self.user1.is_email_verified = True
2222
self.user2.need_mentoring = True
@@ -56,14 +56,14 @@ def test_pending_requests_auth(self):
5656
creation_date=start_date,
5757
end_date=end_date,
5858
state=MentorshipRelationState.PENDING,
59-
notes="",
59+
notes=None,
6060
tasks_list=tasks_list,
6161
)
6262

6363
db.session.add(mentorship_relation)
6464
db.session.commit()
6565
expected_response = {
66-
"name": "User1",
66+
"name": "UserA",
6767
"pending_requests": 1,
6868
"accepted_requests": 0,
6969
"rejected_requests": 0,
@@ -92,14 +92,14 @@ def test_accepted_requests_auth(self):
9292
creation_date=start_date,
9393
end_date=end_date,
9494
state=MentorshipRelationState.ACCEPTED,
95-
notes="",
95+
notes=None,
9696
tasks_list=tasks_list,
9797
)
9898

9999
db.session.add(mentorship_relation)
100100
db.session.commit()
101101
expected_response = {
102-
"name": "User1",
102+
"name": "UserA",
103103
"pending_requests": 0,
104104
"accepted_requests": 1,
105105
"rejected_requests": 0,
@@ -128,14 +128,14 @@ def test_rejected_requests(self):
128128
creation_date=start_date,
129129
end_date=end_date,
130130
state=MentorshipRelationState.REJECTED,
131-
notes="",
131+
notes=None,
132132
tasks_list=tasks_list,
133133
)
134134

135135
db.session.add(mentorship_relation)
136136
db.session.commit()
137137
expected_response = {
138-
"name": "User1",
138+
"name": "UserA",
139139
"pending_requests": 0,
140140
"accepted_requests": 0,
141141
"rejected_requests": 1,
@@ -164,14 +164,14 @@ def test_completed_relations(self):
164164
creation_date=start_date,
165165
end_date=end_date,
166166
state=MentorshipRelationState.COMPLETED,
167-
notes="",
167+
notes=None,
168168
tasks_list=tasks_list,
169169
)
170170

171171
db.session.add(mentorship_relation)
172172
db.session.commit()
173173
expected_response = {
174-
"name": "User1",
174+
"name": "UserA",
175175
"pending_requests": 0,
176176
"accepted_requests": 0,
177177
"rejected_requests": 0,
@@ -199,14 +199,14 @@ def test_cancelled_relations(self):
199199
creation_date=start_date,
200200
end_date=end_date,
201201
state=MentorshipRelationState.CANCELLED,
202-
notes="",
202+
notes=None,
203203
tasks_list=tasks_list,
204204
)
205205

206206
db.session.add(mentorship_relation)
207207
db.session.commit()
208208
expected_response = {
209-
"name": "User1",
209+
"name": "UserA",
210210
"pending_requests": 0,
211211
"accepted_requests": 0,
212212
"rejected_requests": 0,
@@ -253,15 +253,15 @@ def test_achievements(self):
253253
creation_date=start_date,
254254
end_date=end_date,
255255
state=MentorshipRelationState.ACCEPTED,
256-
notes="",
256+
notes=None,
257257
tasks_list=tasks_list,
258258
)
259259

260260
db.session.add(mentorship_relation)
261261
db.session.commit()
262262

263263
expected_response = {
264-
"name": "User1",
264+
"name": "UserA",
265265
"pending_requests": 0,
266266
"accepted_requests": 1,
267267
"rejected_requests": 0,

tests/users/test_api_list_users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ def test_list_users_api_with_a_search_query_with_spaces_resource_auth(self):
124124
self.assertEqual(HTTPStatus.OK, actual_response.status_code)
125125
self.assertEqual(expected_response, json.loads(actual_response.data))
126126

127+
# invalid test case
127128
def test_list_users_api_with_search_with_special_characters_resource_auth(self):
128129
auth_header = get_test_request_header(self.admin_user.id)
129130
expected_response = [marshal(self.second_user, public_user_api_model)]
130131
actual_response = self.client.get(
131-
f"/users?search=s_t-r%24a%2Fn'ge",
132+
f"/users?search=strange%20%20name",
132133
follow_redirects=True,
133134
headers=auth_header,
134135
)

tests/users/test_dao.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TestUserDao(BaseTestCase):
1818
def test_dao_create_user(self):
1919
dao = UserDAO()
2020
data = dict(
21-
name="User2",
21+
name="UserB",
2222
username="user2",
2323
2424
password="test_password",
@@ -30,7 +30,7 @@ def test_dao_create_user(self):
3030
user = UserModel.query.filter_by(email="[email protected]").first()
3131
self.assertTrue(user is not None)
3232
self.assertTrue(user.id is not None)
33-
self.assertTrue(user.name == "User2")
33+
self.assertTrue(user.name == "UserB")
3434
self.assertTrue(user.username == "user2")
3535
self.assertTrue(user.email == "[email protected]")
3636
self.assertFalse(user.is_admin)

tests/users/test_database_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_is_first_user_admin(self):
3232

3333
def test_second_user_cannot_be_admin(self):
3434
user = UserModel(
35-
name="User1",
35+
name="UserA",
3636
3737
username="user_not_admin",
3838
password="user1_password",
@@ -44,7 +44,7 @@ def test_second_user_cannot_be_admin(self):
4444
user = UserModel.query.filter_by(email="[email protected]").first()
4545
self.assertTrue(user is not None)
4646
self.assertTrue(user.id is not None)
47-
self.assertTrue(user.name == "User1")
47+
self.assertTrue(user.name == "UserA")
4848
self.assertTrue(user.username == "user_not_admin")
4949
self.assertTrue(user.email == "[email protected]")
5050
self.assertFalse(user.password_hash == "user1_password")

0 commit comments

Comments
 (0)