Skip to content

Commit ba4608f

Browse files
committed
Make code changes as per review
1 parent 473510d commit ba4608f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/arguments/api_test.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class ApiTesting():
55
default_url = "https://127.0.0.1:8000"
66
default_headers = {}
7-
InvalidSchemaMessage = "Check whether the URL is valid or check if" + "the localhost server is active or not"
7+
invalid_schema_message = "Check whether the URL is valid or check if" + "the localhost server is active or not"
88
# fetches the input data for making a request
99
@classmethod
1010
def fetch_input_url(cls):
@@ -51,6 +51,9 @@ def save_response_data(cls,response_data):
5151
with open('response_data.json', 'w') as jsonFile:
5252
json.dump(response_data, jsonFile, indent=4)
5353
print("Response data stored in response_data.json")
54+
else:
55+
print(f"You have entered {store_data}, please enter 'Y' or 'y' to store the output")
56+
5457
# formats the response data and prints it in json on console
5558
@classmethod
5659
def print_response_json(cls,response):
@@ -60,7 +63,6 @@ def print_response_json(cls,response):
6063
output_json = highlight(parsed_json, lexers.JsonLexer(),
6164
formatters.TerminalFormatter())
6265
print(output_json)
63-
return response_data
6466

6567
# Make GET request
6668
@classmethod
@@ -69,27 +71,29 @@ def get_request(cls):
6971
# Make GET request and store the response in response_data.json
7072
try:
7173
response = requests.get(request_data["request_url"], headers= request_data["request_headers"])
72-
response_data = cls.print_response_json(response)
74+
cls.print_response_json(response)
75+
response_data = json.loads(response.content)
7376
cls.save_response_data(response_data)
7477

7578
except requests.exceptions.InvalidSchema:
76-
print(cls.InvalidSchemaMessage)
77-
except Exception as e:
78-
print(e)
79+
print(cls.invalid_schema_message)
80+
except Exception as exception_obj:
81+
print(exception_obj)
7982
# Make a delete request
8083
@classmethod
81-
def delete_endpoint_request(cls):
84+
def delete_request(cls):
8285
# request_data contains dictionary of inputs entered by user
8386
request_data = cls.fetch_input_url()
8487
try:
8588
response = requests.delete(request_data["request_url"], headers= request_data["request_headers"])
86-
response_data = cls.print_response_json(response)
89+
cls.print_response_json(response)
90+
response_data = json.loads(response.content)
8791
cls.save_response_data(response_data)
8892

8993
except requests.exceptions.InvalidSchema:
90-
print(cls.InvalidSchemaMessage)
91-
except Exception as e:
92-
print(e)
94+
print(cls.invalid_schema_message)
95+
except Exception as exception_obj:
96+
print(exception_obj)
9397

9498
@classmethod
9599
def __check_endpoint(cls, request_url):

src/arguments/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def search_args(self):
5555
elif self.arguments.GET:
5656
self.api_test_object.get_request()
5757
elif self.arguments.DELETE:
58-
self.api_test_object.delete_endpoint_request()
58+
self.api_test_object.delete_request()
5959
elif self.arguments.notion:
6060
NotionClient().get_tokenv2_cookie()
6161

0 commit comments

Comments
 (0)