Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test new script #1596

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
74b7ef7
Fix script
petechd Jan 15, 2025
bd76d5f
Add bad schema
petechd Jan 15, 2025
5da587e
Add summary statement
petechd Jan 15, 2025
ade416a
Add echo exit status
petechd Jan 15, 2025
96382e2
Change scrypt to use python
petechd Jan 15, 2025
dd51ef0
Add poetry
petechd Jan 15, 2025
8c4fd2a
Add colour print statements
petechd Jan 15, 2025
2735002
Fix print statements
petechd Jan 15, 2025
a725c64
Add retries and linting
petechd Jan 15, 2025
5786a00
Fix schema
petechd Jan 15, 2025
6bbdbd9
Add linting
petechd Jan 16, 2025
27b2aaa
Add back schemas
petechd Jan 16, 2025
589262c
Add logger lines
petechd Jan 16, 2025
a561ddd
Fix Makefile and add logger to script
petechd Jan 16, 2025
5abf7f5
Fix logger info final statement
petechd Jan 16, 2025
694dd6b
Move global vars inside the function
petechd Jan 28, 2025
345ac74
Add standard library logging
petechd Jan 28, 2025
7249e77
Add pylint exceptions
petechd Jan 28, 2025
8af0753
Try correct string interpolation
petechd Jan 28, 2025
79e05ea
Add remaining logging in correct format
petechd Jan 28, 2025
7033f7b
Add interpolation and vaiable fixes
petechd Jan 28, 2025
7c58666
Rename actions job
petechd Jan 28, 2025
9e4594a
Move code to separate functions
petechd Jan 28, 2025
25cc0e0
Merge branch 'main' into validation-test
petechd Jan 29, 2025
153b931
Add broken test scheam
VirajP1002 Jan 30, 2025
49bb10d
Revert broken schema
VirajP1002 Jan 30, 2025
55fb715
Add 2 broken schemas
VirajP1002 Jan 30, 2025
1474b52
Merge branch 'main' into test-new-script
VirajP1002 Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add retries and linting
petechd committed Jan 15, 2025
commit a725c64e795387c6f29c6d75366da1335fbc141d
51 changes: 42 additions & 9 deletions scripts/validate_test_schemas.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import json
import subprocess
import os
import re
import subprocess
import sys
import time
from concurrent.futures import ThreadPoolExecutor, as_completed

error = False
passed = 0
failed = 0


def validate_schema(schema_path):
try:
result = subprocess.run(
['curl', '-s', '-w', 'HTTPSTATUS:%{http_code}', '-X', 'POST', '-H', 'Content-Type: application/json', '-d', f'@{schema_path}',
'http://localhost:5001/validate'],
capture_output=True,
text=True,
check=True
check=True,
)
return schema_path, result.stdout
except subprocess.CalledProcessError as e:
@@ -25,23 +27,55 @@ def validate_schema(schema_path):


def main():
file_path = './schemas/test/en'
schemas = [os.path.join(file_path, f) for f in os.listdir(file_path) if f.endswith('.json')]
checks = 4

while checks > 0:
response = subprocess.run(
['curl', '-so', '/dev/null', '-w', '%{http_code}', 'http://localhost:5002/status'],
capture_output=True,
text=True
).stdout.strip()

if response != "200":
print(f"\033[31m---Error: Schema Validator Not Reachable---\033[0m")
print(f"\033[31mHTTP Status: {response}\033[0m")
if checks != 1:
print(f"Retrying...\n")
time.sleep(5)
else:
print(f"Exiting...\n")
sys.exit(1)
checks -= 1
else:
checks = 0

if len(sys.argv) == 1 or sys.argv[1] == "--local":
file_path = "./schemas/test/en"
else:
file_path = sys.argv[1]

print(f"--- Testing Schemas in {file_path} ---")

schemas = [
os.path.join(file_path, f) for f in os.listdir(file_path) if f.endswith(".json")
]

with ThreadPoolExecutor(max_workers=20) as executor:
future_to_schema = {executor.submit(validate_schema, schema): schema for schema in schemas}
future_to_schema = {
executor.submit(validate_schema, schema): schema for schema in schemas
}
for future in as_completed(future_to_schema):
schema = future_to_schema[future]
try:
schema_path, result = future.result()
# Extract HTTP body
http_body = re.sub(r'HTTPSTATUS:.*', '', result)
http_body = re.sub(r"HTTPSTATUS:.*", "", result)

# Convert HTTP body to JSON
http_body_json = json.loads(http_body)

# Extract HTTP status code
result_response = re.search(r'HTTPSTATUS:(\d+)', result)[1]
result_response = re.search(r"HTTPSTATUS:(\d+)", result)[1]

if result_response == "200" and http_body_json == {}:
print(f"\033[32m{schema_path}: PASSED\033[0m")
@@ -51,9 +85,8 @@ def main():
print(f"\033[31m{schema_path}: FAILED\033[0m")
print(f"\033[31mHTTP Status @ /validate: {result_response}\033[0m")
print(f"\033[31mHTTP Status: {http_body_json}\033[0m")
global error
global error, failed
error = True
global failed
failed += 1
except Exception as e:
print(f"\033[31mError processing {schema}: {e}\033[0m")