Consider a REST API integration test that sends a GET request to /users/123. The test expects a JSON response with the user's name and status code 200.
What will be the printed output of this test snippet?
response = client.get('/users/123') if response.status_code == 200 and response.json().get('name') == 'Alice': print('Test Passed') else: print('Test Failed')
Check if the response status and JSON content match the expected values.
The test checks if the status code is 200 and the JSON response contains the name 'Alice'. If both are true, it prints 'Test Passed'.
Integration testing usually checks how different parts of a system work together. Which of these is least likely to be tested during REST API integration testing?
Think about what integration testing focuses on versus unit testing.
Integration testing focuses on how components interact, not on isolated function logic which is covered by unit tests.
Given this integration test code snippet that calls an external API endpoint, why does it fail with a timeout error?
response = client.get('/external-data', timeout=0.001) print(response.status_code)
Consider what happens if the timeout is set very low.
The timeout is set to 0.001 seconds, which is too short for the external API to respond, causing a timeout error.
You want to mock a REST API response in your integration test using Python's unittest.mock. Which code snippet correctly mocks the client.get method to return a response with status code 200 and JSON {'success': true}?
Remember that json is a method, not a property.
Option C correctly sets return_value.status_code and mocks json as a lambda function returning the dictionary.
An integration test calls two API endpoints: /products returning 3 items and /categories returning 2 items. The test aggregates both JSON lists into one list.
How many items will the combined list contain?
products = client.get('/products').json() # returns list of 3 items categories = client.get('/categories').json() # returns list of 2 items combined = products + categories print(len(combined))
Think about how list concatenation works in Python.
Concatenating two lists of lengths 3 and 2 results in a list of length 5.