-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
47 lines (37 loc) · 1.85 KB
/
tests.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
import unittest
import requests
import os
# Sends values in the correct format
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
# Sets the domain
DOMAIN = os.getenv("DOMAIN", default="http://flask-env.eba-pxjvpazg.us-east-2.elasticbeanstalk.com/")
# The Unit Test for the Trie
class TestTrie(unittest.TestCase):
# Make sure all endpoints return valid json responses
def test_errors(self):
self.assertIsNotNone(requests.get(DOMAIN + "/display").json().get("Result"))
self.assertIsNotNone(
requests.post(DOMAIN + "/add", headers=headers, data={"key": "atest"}).json().get("Result"))
self.assertIsNotNone(
requests.post(DOMAIN + "/search", headers=headers, data={"key": "atest"}).json().get("Result"))
self.assertNotEqual(
requests.post(DOMAIN + "/autocomplete", headers=headers, data={"key": "atest"}).json().get("Result"),
["Invalid key! Please enter a valid string to find autocomplete suggestions for."])
self.assertIsNotNone(
requests.post(DOMAIN + "/delete", headers=headers, data={"key": "atest"}).json().get("Result"))
# Tests the global state of the Trie
# Also tests the order of processing the requests
def test_global_state(self):
# Adding the string to the Trie
requests.post(DOMAIN + "/add", headers=headers, data={"key": "thisisatest"})
# Asserting to see if it exists
self.assertTrue(
requests.post(DOMAIN + "/search", headers=headers, data={"key": "thisisatest"}).json()["Result"],
"The key should exist when searching, since it was added")
# Deleting the added string to not make an impact on the global Trie
requests.post(DOMAIN + "/delete", headers=headers, data={"key": "thisisatest"})
if __name__ == "__main__":
# Run the Unit Test
unittest.main()