-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
42 lines (34 loc) · 1.04 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import random
import json
import requests
import pprint
# Endpoint of the API
url="http://127.0.0.1:8000/search_movie/"
# Function to get a random request from a JSON file
def get_random_payload(file_path):
with open(file_path, "r") as file:
data = json.load(file)
# Convert the dictionary keys to a list
payload_keys = list(data.keys())
# Randomly select a payload key
selected_payload_key = random.choice(payload_keys)
# Get the selected payload using the key
selected_payload = data[selected_payload_key]
return selected_payload
# Test the API
request = get_random_payload("test.json")
response = requests.post(url, params=request)
# Handle the response
if response.status_code == 200:
# Request successful
list_movies = response.json()
print('\n')
print("******** Given request: ********")
pprint.pprint(request)
print('\n')
print("******** Recommended movies: ********")
pprint.pprint(list_movies)
print('\n')
else:
# Request failed
print("Error:", response.status_code)