-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
115 lines (98 loc) · 3.42 KB
/
tests.py
File metadata and controls
115 lines (98 loc) · 3.42 KB
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
"""
Integration tests for API (clientside)
"""
import unittest
import requests
from api import tests
class TestIntegrationAPISync(unittest.TestCase):
"""
Sync testing API works
"""
test_counter = 10
headers = {"Content-Type": "application/json"}
__username1 = "test1"
__sha_pass1 = "1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014"
__username2 = "test2"
__sha_pass2 = "60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752"
def test_available_route_add_note(self):
"""
Testing conn to route `/add_note/`
"""
response = requests.post("http://0.0.0.0:8000/add_note/", timeout=10)
self.assertLess(response.status_code, 500)
def test_available_route_notes(self):
"""
Testing conn to route `/notes/`
"""
response = requests.get("http://0.0.0.0:8000/notes/", timeout=10)
self.assertLess(response.status_code, 500)
def test_available_speller(self):
"""
Testing conn to Yandex.Speller
"""
response = requests.get(
"https://speller.yandex.net/services/spellservice.json/checkText", timeout=10
)
self.assertEqual(response.status_code, 200)
def test_invalid_user(self):
"""
Testing Auth
"""
response = requests.get(
"http://0.0.0.0:8000/notes/",
params={"username": self.__username1, "sha_password": self.__sha_pass2}, timeout=10,
)
self.assertGreater(response.status_code, 400)
def test_add_note(self):
"""
Testing works route `/add_note/`
"""
json_body = {
"note": "test1 note",
"have_typo": False,
"username": self.__username1,
"sha_password": self.__sha_pass1,
}
response = requests.post(
"http://0.0.0.0:8000/add-note/",
json=json_body,
headers=self.headers, timeout=10,
)
self.assertLess(response.status_code, 300)
json_body = {
"note": "test2 note",
"have_typo": False,
"username": self.__username2,
"sha_password": self.__sha_pass2,
}
response = requests.post(
"http://0.0.0.0:8000/add-note/",
headers=self.headers,
json=json_body, timeout=10,
)
self.assertLess(response.status_code, 300)
def test_notes(self):
"""
Testing correct works route `/notes/` for specific users
"""
response = requests.get(
"http://0.0.0.0:8000/notes/",
headers=self.headers,
params={"username": self.__username1, "sha_password": self.__sha_pass1}, timeout=10,
)
json = response.json()
self.assertIsNotNone(json["notes"])
self.assertEqual(json["notes"]["note_0"]["username"], "test1")
response = requests.get(
"http://0.0.0.0:8000/notes/",
headers=self.headers,
params={"username": self.__username2, "sha_password": self.__sha_pass2}, timeout=10,
)
json = response.json()
self.assertIsNotNone(json["notes"])
self.assertEqual(json["notes"]["note_0"]["username"], "test2")
if __name__ == "__main__":
suite_other = unittest.TestLoader().loadTestsFromModule(tests)
unittest.TextTestRunner(verbosity=2).run(suite_other)
print()
unittest.main(verbosity=2)