Validate API version 1 endpoint
This commit is contained in:
parent
cac2094b4c
commit
edfece52b5
@ -1,4 +1,4 @@
|
|||||||
import argparse, json, os, time
|
import argparse, json, os, random, time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Server address
|
# Server address
|
||||||
@ -40,6 +40,13 @@ def parse_args():
|
|||||||
metavar="FILENAME",
|
metavar="FILENAME",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--skip-analysis",
|
||||||
|
help="Skip reanalyzing episodes and just validate timestamps and API versioning",
|
||||||
|
dest="skip",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -81,7 +88,7 @@ def close_enough(expected, actual):
|
|||||||
return abs(expected - actual) <= 2
|
return abs(expected - actual) <= 2
|
||||||
|
|
||||||
|
|
||||||
# Validate that all episodes in actual have a similar entry in expected.
|
# Validate that all episodes in expected have a similar entry in actual.
|
||||||
def validate(expected, actual):
|
def validate(expected, actual):
|
||||||
good = 0
|
good = 0
|
||||||
bad = 0
|
bad = 0
|
||||||
@ -142,13 +149,17 @@ def main():
|
|||||||
|
|
||||||
print(f"[+] Found {len(expected)} expected timestamps\n")
|
print(f"[+] Found {len(expected)} expected timestamps\n")
|
||||||
|
|
||||||
# Erase old intro timestamps
|
if not args.skip:
|
||||||
print("[+] Erasing previously discovered introduction timestamps")
|
# Erase old intro timestamps
|
||||||
send("/Intros/EraseTimestamps", "POST")
|
print("[+] Erasing previously discovered introduction timestamps")
|
||||||
|
send("/Intros/EraseTimestamps", "POST")
|
||||||
|
|
||||||
# Run analyze episodes task
|
# Run analyze episodes task
|
||||||
print("[+] Starting episode analysis task")
|
print("[+] Starting episode analysis task")
|
||||||
send(f"/ScheduledTasks/Running/{taskId}", "POST")
|
send(f"/ScheduledTasks/Running/{taskId}", "POST")
|
||||||
|
else:
|
||||||
|
print("[+] Not running episode analysis")
|
||||||
|
args.frequency = 0
|
||||||
|
|
||||||
# Poll for completion
|
# Poll for completion
|
||||||
print("[+] Waiting for analysis task to complete")
|
print("[+] Waiting for analysis task to complete")
|
||||||
@ -190,8 +201,28 @@ def main():
|
|||||||
|
|
||||||
validate(expected, actual)
|
validate(expected, actual)
|
||||||
|
|
||||||
# TODO: Pick 5 random intros and verify deeply equal to v1
|
# Select some episodes to validate
|
||||||
# this should be done by getting the versioned endpoint and non-versioned
|
keys = []
|
||||||
|
for i in expected:
|
||||||
|
keys.append(i)
|
||||||
|
keys = random.choices(keys, k=min(len(keys), 10))
|
||||||
|
|
||||||
|
# Validate API version 1 (both implicitly and explicitly versioned)
|
||||||
|
for version in ["v1 (implicit)", "v1 (explicit)"]:
|
||||||
|
print()
|
||||||
|
print(f"[+] Validating API version: {version} with {len(keys)} episodes")
|
||||||
|
|
||||||
|
if version.find("implicit") != -1:
|
||||||
|
version = ""
|
||||||
|
else:
|
||||||
|
version = "v1"
|
||||||
|
|
||||||
|
for episode in keys:
|
||||||
|
ac = send(
|
||||||
|
f"/Episode/{episode}/IntroTimestamps/{version}", "GET", False
|
||||||
|
).json()
|
||||||
|
|
||||||
|
print(ac)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user