Skip to content

Commit bfce1a0

Browse files
author
yasht01
committed
Add URL checks and endpoint checks
1 parent 235e3eb commit bfce1a0

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/arguments/api_test.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests, json
2+
import re
23

34
class Api_Testing():
45
default_url = "127.0.0.1:8000"
@@ -10,6 +11,17 @@ def get_request(self):
1011
if input_url != '':
1112
request_url = input_url
1213

14+
has_endpoint = self.check_endpoint(request_url)
15+
16+
if not(has_endpoint):
17+
if(request_url[-1] == '/'):
18+
endpoint = input("Input endpoint (Without the starting slash): ")
19+
else:
20+
endpoint = input("Input endpoint (With the starting slash): ")
21+
request_url += endpoint
22+
23+
print("Trying ...\u26A1")
24+
1325
try:
1426
response = requests.get(request_url)
1527
print(f"Reponse Status Code: {response.status_code}")
@@ -20,4 +32,21 @@ def get_request(self):
2032
except requests.exceptions.InvalidSchema:
2133
print("Check whether the URL is valid or check if the localhost server is active or not")
2234
except Exception as e:
23-
print(e)
35+
print(e)
36+
37+
def check_endpoint(url):
38+
check_string = url
39+
is_localhost_url = False
40+
41+
if(len(check_string.split(":")[-1]) <= 5):
42+
is_localhost_url = True
43+
44+
if(is_localhost_url):
45+
check_string = check_string.split(':')[-1]
46+
else:
47+
check_string = check_string.split('.')[-1]
48+
49+
if(len(check_string) <= 5):
50+
return False
51+
else:
52+
return True

0 commit comments

Comments
 (0)