-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
119 lines (106 loc) · 3.11 KB
/
test.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
from unittest import main, mock, TestCase
import homework
SAMPLE_NO_HOMEWORKS = '''{
"current_date":1581604970
}
'''
SAMPLE_EMPTY_HOMEWORKS = '''{
"homeworks":[],
"current_date":1581604970
}
'''
SAMPLE_HOMEWORK = '''{
"homeworks":[
{
"id":124,
"status":"rejected",
"homework_name":"username__hw_python_oop.zip",
"reviewer_comment":"Код не по PEP8, нужно исправить",
"date_updated":"2020-02-13T16:42:47Z",
"lesson_name":"Итоговый проект"
}
],
"current_date":1581604970
}
'''
SAMPLE_HOMEWORK_WRONG_STATUS = '''{
"homeworks":[
{
"id":124,
"status":"undefined status",
"homework_name":"username__hw_python_oop.zip",
"reviewer_comment":"Код не по PEP8, нужно исправить",
"date_updated":"2020-02-13T16:42:47Z",
"lesson_name":"Итоговый проект"
}
],
"current_date":1581604970
}
'''
SAMPLE_HOMEWORK_ILL_FORMED = '''{
"homeworks":[
{
"id":124,
"reviewer_comment":"Код не по PEP8, нужно исправить",
"date_updated":"2020-02-13T16:42:47Z",
"lesson_name":"Итоговый проект"
}
],
"current_date":1581604970
}
'''
INCORRECT_JSON = '''{
homeworks":
{
"id":124,
"reviewer_comment":"Код не по PEP8, нужно исправить",
"date_updated":"2020-02-13T16:42:47Z",
"lesson_name":"Итоговый проект"
}
],
"current_date":1581604970
}
'''
class TestRequest(TestCase):
"""Проверка обработки ошибок при запросе."""
def setUp(self):
pass
def test_request_error(self):
cases = [
('http://0.0.0.0', ConnectionError),
('http://unknown_address.yandex.ru', ValueError)
]
for url, error in cases:
with mock.patch('homework.ENDPOINT', url):
self.assertRaises(
error, homework.get_api_answer, current_timestamp=0
)
# @mock.patch('requests.get')
# def test_request_json(self, requests_get):
# cases = ['{ homework": [] }']
# response = mock.Mock()
# for json in cases:
# response.json = mock.Mock(return_value=json)
# response.status_code = 200
# requests_get.return_value = response
# self.assertRaises(
# homework.JSONDecodeError,
# homework.get_api_answer,
# current_timestamp=0
# )
def test_check_response(self):
cases = [
([], TypeError),
({"current_date": 1581604970}, KeyError),
({"homeworks": {"name": "some_name"}}, TypeError),
({"homeworks": []}, None)
]
for json_data, error in cases:
if error:
self.assertRaises(
error, homework.check_response, response=json_data
)
def test_parse_status(self):
pass
if __name__ == '__main__':
main()