Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epicadk committed May 9, 2021
1 parent 1a562ff commit 3c90293
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
6 changes: 3 additions & 3 deletions app/database/models/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def delete_from_db(self) -> None:
@validates("notes")
def validate(self, key, value):
if key == "notes":
assert value is not None
value = str(value).strip()
assert len(value.strip()) > 2
if value is not None:
value = str(value).strip()
assert len(value.strip()) > 2
return value
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_dao_create_mentorship_relation_with_good_args_but_invalid_timestamp(sel
data = dict(
mentor_id=self.first_user.id,
mentee_id=self.second_user.id,
end_date=1580338800000000,
end_date=158033880000,
notes=self.notes_example,
tasks_list=TasksListModel(),
)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
}

test_admin_user_2 = {
"name": "Admin_2",
"name": "Adminb",
"email": "[email protected]",
"username": "admin2_username",
"password": "admin2_pwd",
"terms_and_conditions_checked": True,
}

test_admin_user_3 = {
"name": "Admin_3",
"name": "Adminc",
"email": "[email protected]",
"username": "admin3_username",
"password": "admin3_pwd",
Expand All @@ -42,23 +42,23 @@
}

user3 = {
"name": "s_t-r$a/n'ge name",
"name": "strange name",
"email": "[email protected]",
"username": "user3",
"password": "user3_pwd",
"terms_and_conditions_checked": True,
}

user4 = {
"name": "[email protected]",
"name": "userc",
"email": "[email protected]",
"username": "user4",
"password": "user4_pwd",
"terms_and_conditions_checked": True,
}

user5 = {
"name": "[email protected]",
"name": "userd",
"email": "[email protected]",
"username": "user5",
"password": "user5_pwd",
Expand Down
2 changes: 1 addition & 1 deletion tests/users/test_api_change_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
super().setUp()
self.first_user = UserModel(
password=user1["password"],
name="User1",
name="User",
email="[email protected]",
username="user_not_admin",
terms_and_conditions_checked=True,
Expand Down
28 changes: 14 additions & 14 deletions tests/users/test_api_home_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class TestHomeStatisticsApi(BaseTestCase):
def setUp(self):
super().setUp()

self.user1 = UserModel("User1", "user1", "__test__", "[email protected]", True)
self.user2 = UserModel("User2", "user2", "__test__", "[email protected]", True)
self.user1 = UserModel("UserA", "user1", "__test__", "[email protected]", True)
self.user2 = UserModel("UserB", "user2", "__test__", "[email protected]", True)
self.user1.available_to_mentor = True
self.user1.is_email_verified = True
self.user2.need_mentoring = True
Expand Down Expand Up @@ -56,14 +56,14 @@ def test_pending_requests_auth(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.PENDING,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()
expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 1,
"accepted_requests": 0,
"rejected_requests": 0,
Expand Down Expand Up @@ -92,14 +92,14 @@ def test_accepted_requests_auth(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.ACCEPTED,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()
expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 0,
"accepted_requests": 1,
"rejected_requests": 0,
Expand Down Expand Up @@ -128,14 +128,14 @@ def test_rejected_requests(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.REJECTED,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()
expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 0,
"accepted_requests": 0,
"rejected_requests": 1,
Expand Down Expand Up @@ -164,14 +164,14 @@ def test_completed_relations(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.COMPLETED,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()
expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 0,
"accepted_requests": 0,
"rejected_requests": 0,
Expand Down Expand Up @@ -199,14 +199,14 @@ def test_cancelled_relations(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.CANCELLED,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()
expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 0,
"accepted_requests": 0,
"rejected_requests": 0,
Expand Down Expand Up @@ -253,15 +253,15 @@ def test_achievements(self):
creation_date=start_date,
end_date=end_date,
state=MentorshipRelationState.ACCEPTED,
notes="",
notes=None,
tasks_list=tasks_list,
)

db.session.add(mentorship_relation)
db.session.commit()

expected_response = {
"name": "User1",
"name": "UserA",
"pending_requests": 0,
"accepted_requests": 1,
"rejected_requests": 0,
Expand Down
3 changes: 2 additions & 1 deletion tests/users/test_api_list_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ def test_list_users_api_with_a_search_query_with_spaces_resource_auth(self):
self.assertEqual(HTTPStatus.OK, actual_response.status_code)
self.assertEqual(expected_response, json.loads(actual_response.data))

# invalid test case
def test_list_users_api_with_search_with_special_characters_resource_auth(self):
auth_header = get_test_request_header(self.admin_user.id)
expected_response = [marshal(self.second_user, public_user_api_model)]
actual_response = self.client.get(
f"/users?search=s_t-r%24a%2Fn'ge",
f"/users?search=strange%20%20name",
follow_redirects=True,
headers=auth_header,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/users/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestUserDao(BaseTestCase):
def test_dao_create_user(self):
dao = UserDAO()
data = dict(
name="User2",
name="UserB",
username="user2",
email="[email protected]",
password="test_password",
Expand All @@ -30,7 +30,7 @@ def test_dao_create_user(self):
user = UserModel.query.filter_by(email="[email protected]").first()
self.assertTrue(user is not None)
self.assertTrue(user.id is not None)
self.assertTrue(user.name == "User2")
self.assertTrue(user.name == "UserB")
self.assertTrue(user.username == "user2")
self.assertTrue(user.email == "[email protected]")
self.assertFalse(user.is_admin)
Expand Down
4 changes: 2 additions & 2 deletions tests/users/test_database_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_is_first_user_admin(self):

def test_second_user_cannot_be_admin(self):
user = UserModel(
name="User1",
name="UserA",
email="[email protected]",
username="user_not_admin",
password="user1_password",
Expand All @@ -44,7 +44,7 @@ def test_second_user_cannot_be_admin(self):
user = UserModel.query.filter_by(email="[email protected]").first()
self.assertTrue(user is not None)
self.assertTrue(user.id is not None)
self.assertTrue(user.name == "User1")
self.assertTrue(user.name == "UserA")
self.assertTrue(user.username == "user_not_admin")
self.assertTrue(user.email == "[email protected]")
self.assertFalse(user.password_hash == "user1_password")
Expand Down

0 comments on commit 3c90293

Please sign in to comment.