-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
64 lines (57 loc) · 2.31 KB
/
test_app.py
File metadata and controls
64 lines (57 loc) · 2.31 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
import ast
import json
from app import app
client = app.test_client()
no_whitespace_or_punct = {
"input": "thisTestInputH4sNoWh1tespaceOrPunctuation"
}
with_whitespace_and_punct = {
"input": "this is some test input! 10:30am!!!!!"
}
def test_hello():
response = client.get("/")
assert response.status_code == 200
def test_stringinate():
response = client.post("/stringinate",
json=no_whitespace_or_punct)
assert response.status_code == 200
expected_response = ast.literal_eval(response.data.decode("utf-8"))
assert expected_response["input"] == no_whitespace_or_punct["input"]
assert expected_response["length"] == 41
assert expected_response["most_common_character"] == "t"
assert expected_response["occurences_of_most_common_character"] == 6
def test_whitespace_and_punctuation_not_included_in_count():
response = client.post("/stringinate", json=with_whitespace_and_punct)
assert response.status_code == 200
expected_response = ast.literal_eval(response.data.decode("utf-8"))
assert expected_response["input"] == with_whitespace_and_punct["input"]
assert expected_response["length"] == 37
assert expected_response["most_common_character"] == "t"
assert expected_response["occurences_of_most_common_character"] == 4
def test_stats():
response = client.get("/stats")
assert response.status_code == 200
expected_response = ast.literal_eval(response.data.decode("utf-8"))
assert expected_response["inputs"] == {
no_whitespace_or_punct["input"]: 1,
with_whitespace_and_punct["input"]: 1,
}
def test_stats_gives_most_popular_string():
client.post("/stringinate", json=with_whitespace_and_punct)
response = client.get("/stats")
assert response.status_code == 200
expected_response = ast.literal_eval(response.data.decode("utf-8"))
assert expected_response["inputs"] == {
no_whitespace_or_punct["input"]: 1,
with_whitespace_and_punct["input"]: 2,
}
assert expected_response["most_popular"] == with_whitespace_and_punct["input"]
def test_stats_gives_longest_input_received():
response = client.get("/stats")
assert response.status_code == 200
expected_response = ast.literal_eval(response.data.decode("utf-8"))
assert expected_response["inputs"] == {
no_whitespace_or_punct["input"]: 1,
with_whitespace_and_punct["input"]: 2,
}
assert expected_response["longest_input_received"] == no_whitespace_or_punct["input"]