Skip to content

Commit e29728b

Browse files
author
yasht01
committed
Add protocol check and specify class methods
1 parent bf632a3 commit e29728b

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/arguments/api_test.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
from pygments import highlight, lexers, formatters
33

44
class ApiTesting():
5-
default_url = "127.0.0.1:8000"
5+
default_url = "https://127.0.0.1:8000"
66

77
# Make GET request
88
@classmethod
9-
def get_request(cls):
10-
request_url = ApiTesting.default_url
9+
def get_request(self):
10+
request_url = self.default_url
1111
input_url = input('Enter URL: ')
1212
if input_url != '':
1313
request_url = input_url
1414

1515
# Check whether the request_url has an endpoint or not
16-
has_endpoint = ApiTesting.check_endpoint(request_url)
16+
has_endpoint = self.__check_endpoint(request_url)
17+
18+
# Check if http:// or https:// is present in request_url
19+
has_protocol = self.__check_protocol(request_url)
20+
21+
if not(has_protocol):
22+
request_url = "https://" + request_url
1723

1824
# Ask the user for endpoint if not present in request_url
1925
if not(has_endpoint):
@@ -45,25 +51,16 @@ def get_request(cls):
4551
except Exception as e:
4652
print(e)
4753

48-
# This method works by first checking whether the url is a localhost url
49-
# If it is, the length of the substring after ':' (Example, 127.0.0.1:8000) is checked
50-
# The length should be less than 6 as either 8000 or 8000/ can be possible (No endpoint)
51-
# If the url is not a localhost url
52-
# The length of the substring after '.' is checked
53-
# The length should be less than 5 (Example: com/, com, io/, io) (For no endpoint)
54-
def check_endpoint(url):
55-
check_string = url
56-
is_localhost_url = False
57-
58-
if(len(check_string.split(":")[-1]) <= 5):
59-
is_localhost_url = True
60-
61-
if(is_localhost_url):
62-
check_string = check_string.split(':')[-1]
54+
@classmethod
55+
def __check_endpoint(self, request_url):
56+
if(request_url == self.default_url):
57+
return False
6358
else:
64-
check_string = check_string.split('.')[-1]
59+
return True
6560

66-
if(len(check_string) <= 5):
67-
return False
61+
@classmethod
62+
def __check_protocol(self, request_url):
63+
if(request_url[:4] == 'http'):
64+
return True
6865
else:
69-
return True
66+
return False

0 commit comments

Comments
 (0)