Complex Testing Solutions

import requestsBASE_URL="https://project-dev.cz/"file = open('profiles.txt', 'r')
lines = file.readlines()

for line in lines:
response = requests.get(f"{BASE_URL}{line.strip()}")
if response.status_code != 200:
print(f"{response.status_code} - {BASE_URL}{line.strip()}")
500 - https://project-dev.cz/profil/846087403
500 - https://project-dev.cz/profil/692174806
500 - https://project-dev.cz/profil/405455479
...
import requests
import random
import sys
FILENAME = "profiles.txt"
BASE_URL = "https://project-dev.cz/"
def random_unique_indexes(max, num):
indexes = []
for i in range(0, num):
indexes.append(random.randint(0, max))
return set(indexes)
def file_lines(filename = FILENAME):
return sum(1 for line in open(filename))
def gather_endpoints(indexes, filename = FILENAME):
endpoints_to_check = []
with open(filename, "r") as fp:
index = 0
for line in fp:
if index in indexes:
endpoints_to_check.append(line.strip())
index += 1
return endpoints_to_check
def check_endpoints(endpoints):
index = 0
for endpoint in endpoints:
result = requests.get(f"{BASE_URL}{endpoint}")
if result.status_code != 200:
print(f"{result.status_code} - {BASE_URL}{endpoint}")
if index % 100 == 0 and index != 0:
print(index)
index += 1
if __name__ == '__main__':
requested_indexes = random_unique_indexes(file_lines() - 1, int(sys.argv[1]) if len(sys.argv) > 1 else 10)
print(len(requested_indexes))
check_endpoints(gather_endpoints(requested_indexes))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store