Answer the question
In order to leave comments, you need to log in
What is the best practice for api testing?
there is a function
def is_car_exist(make, model):
url = f'https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMake/\
{make.capitalize()}?format=json'
data = requests.get(url).json()['Results']
return any(model.capitalize() == car['Model_Name'] for car in data)
Answer the question
In order to leave comments, you need to log in
This one - no way. At a minimum, you need to get rid of the hardcoded domain and put it in the config. Further options are possible:
1. Wiremock - creates a local server and responds to requests to it. That is, it "pretends to be" an external service for your program.
2. Unit tests. But for them, it is necessary to isolate calls to the external service and "close" them with an interface, instead of which the test implementation of the external service will be substituted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question