nerdexam
Cisco

200-901 · Question #287

Drag and Drop Questions Drag and drop the code snippets from the bottom to the blanks in the code to test the API response through the Python unittest library. Not all options are used. Answer:

The correct answer is get; response; status_code. This question assesses the candidate's ability to complete Python unittest code for API testing, specifically focusing on verifying HTTP status codes, content types, and handling non-existent resources.

Understanding and Using APIs

Question

Drag and Drop Questions Drag and drop the code snippets from the bottom to the blanks in the code to test the API response through the Python unittest library. Not all options are used. Answer:

Exhibit

200-901 question #287 exhibit

Answer Area

Drag items

responserequestsgetstatus_codestatus

Correct arrangement

  • get
  • response
  • status_code

Explanation

This question assesses the candidate's ability to complete Python unittest code for API testing, specifically focusing on verifying HTTP status codes, content types, and handling non-existent resources.

Approach. 1. For the first blank in self.assertEqual(status_code, _____) within test_status: The API call self.app.get('/dogs/all') is expected to be successful. A standard successful HTTP response status code is 200 (OK). Therefore, 200 is the correct snippet to drag here. 2. For the second blank in self.assertEqual(resp._____, 'application/json') within test_content_type: This test aims to verify that the API response's content type is application/json. API response objects typically expose a content_type attribute to access this information. Thus, content_type is the correct snippet. 3. For the third blank in resp = self.app.get('/dogs?id=_____') within test_item_not_exist: The objective of this test is to trigger a '404 Not Found' response, implying a request for a resource that does not exist. Passing none as an ID parameter is a common and appropriate way to simulate a request for a non-existent resource from the given options. Therefore, none is the correct snippet.

Common mistakes.

  • common_mistake. 1. Using 403 instead of 200 for the status code verification in test_status: 403 (Forbidden) indicates an authorization issue, not a successful API response, which typically uses 200 (OK).
  1. Using content or status instead of content_type for content type verification: resp.content would retrieve the raw response body, while resp.status is not a standard attribute for content type. The correct attribute to check the MIME type of the response is content_type.
  2. Using status_code for the ID parameter in test_item_not_exist: status_code is an attribute of the response object, not a valid value to pass as an ID parameter to simulate a non-existent resource. Similarly, content is also not appropriate as an ID.

Concept tested. This question tests the candidate's understanding of Python's unittest framework for creating and running tests, fundamental concepts of API testing including verifying HTTP status codes (e.g., 200 OK, 404 Not Found) and response content types, and how to interact with typical API response objects (e.g., status_code, content_type attributes) when using a test client.

Topics

#Python unittest#API testing#Unit testing#Software testing

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice