-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
102 lines (79 loc) · 2.46 KB
/
tests.py
File metadata and controls
102 lines (79 loc) · 2.46 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
import sys
import requests
filename = input("filename=")
# The first will handle the logs. (a)
# The second will handle all user-related tasks. (b)
# The third will handle all cost-related tasks. (c)
# The fourth will handle any admin-related tasks (e.g. developers details) (d)
a = "https://logs-service-qa7i.onrender.com"
b = "https://users-service-tiv3.onrender.com"
c = "https://costs-service-nyve.onrender.com"
d = "https://admin-service-7rrv.onrender.com"
# Redirect all prints to a file
output = open(filename, "w", encoding="utf-8")
sys.stdout = output
print("a=" + a)
print("b=" + b)
print("c=" + c)
print("d=" + d)
print()
print("testing getting the about")
print("-------------------------")
try:
url = d + "/api/about/"
data = requests.get(url)
print("url=" + url)
print("data.status_code=" + str(data.status_code))
print("data.content=" + str(data.content))
print("data.text=" + data.text)
# if response isn't JSON, this may throw -> handled by except
print("data.json()=" + str(data.json()))
except Exception as e:
print("problem")
print(e)
print()
print("testing getting the report - 1")
print("------------------------------")
try:
url = c + "/api/report/?id=123123&year=2026&month=1"
data = requests.get(url)
print("url=" + url)
print("data.status_code=" + str(data.status_code))
print("data.content=" + str(data.content))
print("data.text=" + data.text)
except Exception as e:
print("problem")
print(e)
print()
print("testing adding cost item")
print("----------------------------------")
try:
url = c + "/api/add/"
data = requests.post(
url,
json={"userid": 123123, "description": "milk 9", "category": "food", "sum": 8}
)
print("url=" + url)
print("data.status_code=" + str(data.status_code))
print("data.content=" + str(data.content))
print("data.text=" + data.text)
except Exception as e:
print("problem")
print(e)
print()
print("testing getting the report - 2")
print("------------------------------")
try:
url = c + "/api/report/?id=123123&year=2026&month=1"
data = requests.get(url)
print("url=" + url)
print("data.status_code=" + str(data.status_code))
print("data.content=" + str(data.content))
print("data.text=" + data.text)
except Exception as e:
print("problem")
print(e)
# Close the file and restore stdout (nice cleanup)
output.close()
sys.stdout = sys.__stdout__
print(f"Done. Output written to {filename}")