-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_the_api.py
More file actions
153 lines (116 loc) · 3.76 KB
/
test_the_api.py
File metadata and controls
153 lines (116 loc) · 3.76 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import requests
def get(url, id=None):
if not id:
get_response = requests.get(f"{url}")
else:
get_response = requests.get(f"{url}/{id}")
if get_response.status_code == 200:
return get_response.json()
else:
print("Non-200 status code:", get_response.status_code)
return
def test_get_char():
id = input("Enter Character ID: ")
character = get(character_url, id)
pretty_print_character(character)
return character
def test_get_all_char():
characters = get(character_url)
for character in characters:
pretty_print_character(character)
return characters
def test_get_df():
id = input("Enter Devil Fruit ID: ")
df = get(df_url, id)
pretty_print_df(df)
return df
def test_get_all_df():
dfs = get(df_url)
for df in dfs:
pretty_print_df(df)
return dfs
def test_get_location():
id = input("Enter Location ID: ")
location = get(location_url, id)
pretty_print_location(location)
return location
def test_get_all_locations():
locations = get(location_url)
for location in locations:
pretty_print_location(location)
return locations
def test_get_artifact():
id = input("Enter Artifact ID: ")
artifact = get(artifact_url, id)
if artifact:
print_pretty_artifact(artifact)
return artifact
def test_get_all_artifacts():
artifacts = get(artifact_url)
if artifacts:
for art in artifacts:
print_pretty_artifact(art)
return artifacts
def pretty_print_character(char):
print("=" * 40)
print(f"Name: {char.get('name')}")
print(f"ID: {char.get('id')}")
print(f"Age: {char.get('age')}")
print(f"Bounty: {char.get('bounty'):,} Berries" if char.get("bounty") else "Bounty: N/A")
print(f"Affiliation: {char.get('affiliation')}")
print(f"Origin: {char.get('origin')}")
print(f"Status: {char.get('status')}")
haki = char.get("haki")
if haki:
print("Haki:")
for haki_type, details in haki.items():
status = "Awakened" if details.get("awakened") else "Not Awakened"
print(f" - {haki_type.title()}: {status}")
else:
print("Haki: None")
df = char.get("devil_fruit")
pretty_print_df(df)
print(f"{'=' * 40}\n")
def pretty_print_df(df):
if df:
print("Devil Fruit:")
print(f" Name: {df['name']}")
print(f" Type: {df['type'].title()}")
print(f" Awakened: {'Yes' if df['awakened'] else 'No'}")
else:
print("Devil Fruit: None")
def pretty_print_location(loc):
print("=" * 40)
print(f"Location: {loc.get('name')}")
print(f"Affiliation: {loc.get('affiliation') or 'None'}")
description = loc.get('description')
if description:
print("Description:")
print(f" {description}")
else:
print("Description: None")
print("=" * 40 + "\n")
def print_pretty_artifact(artifact):
print("=" * 40)
print(f"Artifact: {artifact.get('name')}")
print(f"Origin: {artifact.get('origin') or 'Unknown'}")
description = artifact.get('description')
if description:
print("Description:")
print(f" {description}")
else:
print("Description: None")
print("=" * 40 + "\n")
if __name__ == "__main__":
character_url = "http://localhost:8080/characters"
df_url = "http://localhost:8080/devil_fruits"
location_url = "http://localhost:8080/locations"
artifact_url = "http://localhost:8080/artifacts"
# test_get_all_char()
# test_get_char()
# test_get_all_df()
# test_get_df()
# test_get_all_locations()
# test_get_location()
# test_get_all_artifacts()
# test_get_artifact()