-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugserver.py
99 lines (87 loc) · 2.53 KB
/
debugserver.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
"""Модуль сервера разработчика для отладки бота."""
from http.server import BaseHTTPRequestHandler, HTTPServer
HOST = '127.0.0.1'
PORT = 8080
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
}
'''
SAMPLE_RESPONSE_WITH_SERVER_ERROR = '''{
"homeworks":[],
"current_date":1581604970,
"error": "Тест ошибки"
}'''
INCORRECT_JSON = '''{
homeworks":
{
"id":124,
"reviewer_comment":"Код не по PEP8, нужно исправить",
"date_updated":"2020-02-13T16:42:47Z",
"lesson_name":"Итоговый проект"
}
],
"current_date":1581604970
}
'''
class DebugServer(BaseHTTPRequestHandler):
"""Имитатор сервиса сообщения статуса домашней работы."""
def do_GET(self):
"""Формирование ответа на запрос."""
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(bytes(SAMPLE_HOMEWORK_ILL_FORMED, 'utf-8'))
if __name__ == '__main__':
server = HTTPServer((HOST, PORT), DebugServer)
print('Server started http://%s:%s' % (HOST, PORT))
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.server_close()
print("Server stopped.")