0
0
Testing Fundamentalstesting~10 mins

Contract testing basics in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a contract test that checks the provider's response status.

Testing Fundamentals
def test_provider_response():
    response = provider.get_data()
    assert response.status_code == [1]
Drag options to blanks, or click blank then click option'
A200
B404
C500
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means 'Not Found' instead of 200.
Using 500 which means server error.
2fill in blank
medium

Complete the code to verify the provider returns the expected JSON key in the contract test.

Testing Fundamentals
def test_provider_data_keys():
    data = provider.get_data().json()
    assert '[1]' in data
Drag options to blanks, or click blank then click option'
Astatus
Berror
CuserId
Dmessage
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'error' key which is for error responses.
Using 'message' which is usually for status messages.
3fill in blank
hard

Fix the error in the assertion to correctly check the provider's response content type.

Testing Fundamentals
def test_content_type():
    response = provider.get_data()
    assert response.headers['Content-Type'] == [1]
Drag options to blanks, or click blank then click option'
A'application/xml'
B'text/html'
C'multipart/form-data'
D'application/json'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/html' which is for web pages.
Using 'application/xml' which is for XML data.
4fill in blank
hard

Fill both blanks to create a contract test that checks the provider's response time and status code.

Testing Fundamentals
def test_response_time_and_status():
    response = provider.get_data()
    assert response.elapsed.total_seconds() [1] 1.0
    assert response.status_code [2] 200
Drag options to blanks, or click blank then click option'
A<
B==
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' for response time which would allow slow responses.
Using '!=' for status code which would accept errors.
5fill in blank
hard

Fill all three blanks to write a contract test that verifies the provider's JSON response structure.

Testing Fundamentals
def test_json_structure():
    data = provider.get_data().json()
    assert isinstance(data, [1])
    assert '[2]' in data
    assert isinstance(data['[2]'], [3])
Drag options to blanks, or click blank then click option'
Adict
Buser
Clist
Dstr
Attempts:
3 left
💡 Hint
Common Mistakes
Assuming the top-level JSON is a list instead of a dictionary.
Checking for a key other than 'user'.
Expecting the 'user' value to be a string instead of a dictionary.