Skip to content

Commit 3500d3b

Browse files
committed
Fix broken tests
1 parent a843974 commit 3500d3b

File tree

4 files changed

+70
-40
lines changed

4 files changed

+70
-40
lines changed

tests/schemas/test_login.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ def test_login_schema_reads_correct_json():
2525

2626

2727
def test_login_response_schema_dumps_correct_json():
28+
time = datetime.now()
2829
schema = LoginResponseSchema()
2930
user = User(id='12345', name='Hello', designation='Developer',
3031
team_name='Engineering', username='hello',
3132
email='hello@example.com',
33+
created_at=time,
3234
profile_pic='https://example.com/picture.jpg')
3335

34-
time = datetime.now()
3536
login = schema.dump({
3637
'token': '12345',
3738
'expiry': time,
@@ -49,7 +50,8 @@ def test_login_response_schema_dumps_correct_json():
4950
'teamName': 'Engineering',
5051
'username': 'hello',
5152
'email': 'hello@example.com',
52-
'profilePic': 'https://example.com/picture.jpg'
53+
'profilePic': 'https://example.com/picture.jpg',
54+
'createdAt': time.isoformat()
5355
}
5456
}
5557

tests/schemas/test_notification.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
11
from datetime import datetime
2+
from unittest.mock import patch
23

3-
import pytest
4-
5-
from snowflake import app as flask_app
6-
from snowflake.models import User, Notification
4+
from snowflake import app
5+
from snowflake.models import User, Notification, Appreciation
76
from snowflake.models.notification import TYPE_APPRECIATION
87
from snowflake.schemas.notification import NotificationSchema
98

109

11-
@pytest.fixture(scope="module", autouse=True)
12-
def app():
13-
yield flask_app
14-
15-
1610
def test_notification_schema_dumps_json_correctly():
1711
created_at = datetime.now()
1812
user = User(id='12345', name='Hello', designation='Developer',
1913
team_name='Engineering', username='hello',
2014
email='hello@example.com',
15+
created_at=created_at,
2116
profile_pic='https://example.com/picture.jpg')
22-
notification = Notification(
23-
id=1,
24-
created_at=created_at,
25-
user=user,
26-
type=TYPE_APPRECIATION,
27-
object_id='1',
28-
read=False,
29-
)
30-
31-
schema = NotificationSchema()
32-
33-
expected = {
34-
'id': 1,
35-
'createdAt': created_at.isoformat(),
36-
'type': TYPE_APPRECIATION,
37-
'objectId': '1',
38-
'read': False,
39-
}
40-
41-
assert schema.dump(notification) == expected
17+
appreciation = Appreciation(content="blah", id=1, created_at=created_at, created_by=user)
18+
with app.app_context():
19+
with patch('snowflake.models.notification.Appreciation.get') as get_func:
20+
get_func.return_value = appreciation
21+
22+
notification = Notification(
23+
id=1,
24+
created_at=created_at,
25+
user=user,
26+
type=TYPE_APPRECIATION,
27+
object_id='1',
28+
read=False,
29+
)
30+
31+
schema = NotificationSchema()
32+
33+
expected = {
34+
'id': 1,
35+
'createdAt': created_at.isoformat(),
36+
'type': TYPE_APPRECIATION,
37+
'objectId': '1',
38+
'read': False,
39+
'object': {
40+
'created_at': created_at.isoformat(),
41+
'created_by': {
42+
'createdAt': created_at.isoformat(),
43+
'designation': 'Developer',
44+
'email': 'hello@example.com',
45+
'name': 'Hello',
46+
'profilePic': 'https://example.com/picture.jpg',
47+
'teamName': 'Engineering',
48+
'username': 'hello'
49+
}
50+
},
51+
}
52+
53+
actual = schema.dump(notification)
54+
assert actual == expected

tests/schemas/test_one_on_one.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ def app():
1414
yield flask_app
1515

1616

17+
time = datetime.now()
1718
user = User(id='12345', name='Hello', designation='Developer',
1819
team_name='Engineering', username='hello',
1920
email='hello@example.com',
21+
created_at=time,
2022
profile_pic='https://example.com/picture.jpg')
2123

22-
time = datetime.now()
2324
one_on_one = OneOnOne(
2425
id=1,
2526
created_by=user,
@@ -40,12 +41,15 @@ def test_one_on_one_action_item_schema():
4041

4142
expected = {
4243
'content': 'hello',
43-
'createdBy': {'designation': 'Developer',
44-
'email': 'hello@example.com',
45-
'name': 'Hello',
46-
'profilePic': 'https://example.com/picture.jpg',
47-
'teamName': 'Engineering',
48-
'username': 'hello'},
44+
'createdBy': {
45+
'designation': 'Developer',
46+
'email': 'hello@example.com',
47+
'name': 'Hello',
48+
'profilePic': 'https://example.com/picture.jpg',
49+
'teamName': 'Engineering',
50+
'username': 'hello',
51+
'createdAt': time.isoformat(),
52+
},
4953
'id': 1,
5054
'state': True
5155
}
@@ -69,6 +73,7 @@ def test_one_on_one_schema():
6973
expected = {
7074
'createdAt': time.isoformat(),
7175
'createdBy': {
76+
'createdAt': time.isoformat(),
7277
'designation': 'Developer',
7378
'email': 'hello@example.com',
7479
'name': 'Hello',
@@ -78,6 +83,7 @@ def test_one_on_one_schema():
7883
},
7984
'id': 1,
8085
'user': {
86+
'createdAt': time.isoformat(),
8187
'designation': 'Developer',
8288
'email': 'hello@example.com',
8389
'name': 'Hello',
@@ -97,6 +103,7 @@ def test_get_one_on_one_schema():
97103
{
98104
'content': 'hello',
99105
'createdBy': {
106+
'createdAt': time.isoformat(),
100107
'designation': 'Developer',
101108
'email': 'hello@example.com',
102109
'name': 'Hello',
@@ -109,6 +116,7 @@ def test_get_one_on_one_schema():
109116
{
110117
'content': 'world',
111118
'createdBy': {
119+
'createdAt': time.isoformat(),
112120
'designation': 'Developer',
113121
'email': 'hello@example.com',
114122
'name': 'Hello',
@@ -127,10 +135,12 @@ def test_get_one_on_one_schema():
127135
'name': 'Hello',
128136
'profilePic': 'https://example.com/picture.jpg',
129137
'teamName': 'Engineering',
130-
'username': 'hello'
138+
'username': 'hello',
139+
'createdAt': time.isoformat(),
131140
},
132141
'id': 1,
133142
'user': {
143+
'createdAt': time.isoformat(),
134144
'designation': 'Developer',
135145
'email': 'hello@example.com',
136146
'name': 'Hello',

tests/schemas/test_user.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime
2+
13
import pytest
24

35
from snowflake import app as flask_app
@@ -11,9 +13,11 @@ def app():
1113

1214

1315
def test_user_schema_dumps_json_correctly():
16+
time = datetime.now()
1417
user = User(id='12345', name='Hello', designation='Developer',
1518
team_name='Engineering', username='hello',
1619
email='hello@example.com',
20+
created_at=time,
1721
profile_pic='https://example.com/picture.jpg')
1822

1923
schema = UserSchema()
@@ -24,7 +28,8 @@ def test_user_schema_dumps_json_correctly():
2428
'teamName': 'Engineering',
2529
'username': 'hello',
2630
'email': 'hello@example.com',
27-
'profilePic': 'https://example.com/picture.jpg'
31+
'profilePic': 'https://example.com/picture.jpg',
32+
'createdAt': time.isoformat()
2833
}
2934

3035
assert expected == schema.dump(user)

0 commit comments

Comments
 (0)