-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_suite.py
139 lines (108 loc) · 3.64 KB
/
test_suite.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
import lc_data_access
import pytest
from unittest.mock import Mock
import json
# To run these tests, simply run `pytest` in the terminal.
@pytest.fixture
def mock_post(mocker):
mock = [Mock()]
mocker.patch('grequests.map', return_value=mock)
return mock
@pytest.fixture
def lc_access(tmpdir):
print("\nsetting up")
fake_user_store_filepath = tmpdir.join("fake_user_store.txt")
fake_user_store_filepath.write("fake_user ")
lc_access = lc_data_access.LcAccess(fake_user_store_filepath)
yield lc_access
print("\ntearing down")
def test_lc_access_intialization(lc_access):
assert len(lc_access.users) == 1
assert 'fake_user' in lc_access.users
def test_add_duplicate_user(lc_access):
username = "fake_user"
assert lc_access.add_user(username) == "{} is already on the list!".format(username)
def test_add_new_user(lc_access):
username = "new_user"
assert lc_access.add_user(username) == "Added {} to the list!".format(username)
assert sorted(lc_access.users_filepath.read().split()) == ['fake_user', 'new_user']
def test_remove_user(lc_access):
username = "new_user"
lc_access.add_user(username)
assert lc_access.remove_user(username) == 1
assert lc_access.users_filepath.read() == "fake_user "
def test_remove_missing_user(lc_access):
username = "user_not_in_our_list"
lc_access.add_user(username)
assert lc_access.remove_user(username) == 0
assert lc_access.users_filepath.read() == "fake_user "
def test_get_user_most_recent(lc_access, mock_post):
mock_post[0].status_code = 200
mock_post[0].text = json.dumps(fake_lc_api_response)
# Test getting a user's most recent submission
recent = lc_access.get_user_most_recent('fake_user')
assert type(recent) == str
assert 'Fail' not in recent
# print(recent)
assert recent == """
Problem Title: Complement of Base 10 Integer
Submit Time: 2022-09-16 13:09:05
Result: Accepted
Language: python3
"""
def test_users_recents(lc_access, mock_post):
mock_post[0].status_code = 200
mock_post[0].text = json.dumps(fake_lc_api_response)
recents = lc_access.recent_submissions_for_each_user()
assert recents == """
fake_user's most recent submission:
Problem Title: Complement of Base 10 Integer
Submit Time: 2022-09-16 13:09:05
Result: Accepted
Language: python3
"""
def test_weekly_recap(lc_access, mock_post):
mock_post[0].status_code = 200
mock_post[0].text = json.dumps(fake_lc_api_response)
recents = lc_access.weekly_recap_leaderboard()
assert recents == """Weekly Recap:
`fake_user 0 problems solved.
`"""
fake_lc_api_response = {
"data": {
"recentSubmissionList": [
{
"title": "Complement of Base 10 Integer",
"titleSlug": "complement-of-base-10-integer",
"timestamp": "1663358945",
"statusDisplay": "Accepted",
"lang": "python3",
"__typename": "SubmissionDumpNode"
},
{
"title": "Partition Equal Subset Sum",
"titleSlug": "partition-equal-subset-sum",
"timestamp": "1663350477",
"statusDisplay": "Accepted",
"lang": "python3",
"__typename": "SubmissionDumpNode"
},
{
"title": "Letter Combinations of a Phone Number",
"titleSlug": "letter-combinations-of-a-phone-number",
"timestamp": "1663350348",
"statusDisplay": "Accepted",
"lang": "python3",
"__typename": "SubmissionDumpNode"
}
],
"languageList": [
{
"id": 0,
"name": "cpp",
"verboseName": "C++",
"__typename": "LanguageNode"
}
]
}
}