def test_update_pet(): generated_pet = test_utils.generate_pet() pet_id = generated_pet['id'] logger.info('POST pet: {0}'.format(generated_pet)) response = api_methods.post_pet(generated_pet) test_utils.verify_pet_from_api(generated_pet, response) # Add database check to verify pet is created api_response = api_methods.get_pet_by_id(pet_id) assert api_response.status_code == constants.HTTP_OK assert generated_pet == api_response.json() # Generate a new pet and set the id to the id from original pet updated_generated_pet = test_utils.generate_pet() updated_generated_pet['id'] = pet_id logger.info('PUT updated pet with same id: {0} and new values: {1}'.format(pet_id, updated_generated_pet)) updated_response = api_methods.put_pet(updated_generated_pet) test_utils.verify_pet_from_api(updated_generated_pet, updated_response) # Add database check to verify pet is updated updated_api_response = api_methods.get_pet_by_id(pet_id) test_utils.verify_pet_from_api(updated_generated_pet, updated_api_response)
def test_update_pet_invalid_body(): generated_pet = test_utils.generate_pet() pet_id = generated_pet['id'] logger.info('POST pet: {0}'.format(generated_pet)) response = api_methods.post_pet(generated_pet) test_utils.verify_pet_from_api(generated_pet, response) # Add database check to verify pet is created api_response = api_methods.get_pet_by_id(pet_id) test_utils.verify_pet_from_api(generated_pet, api_response) # Generate a new pet with required missing field and set the id to the id from original pet updated_generated_pet = test_utils.generate_pet_missing_field('name') updated_generated_pet['id'] = pet_id logger.info('PUT updated pet with same id: {0} and new values: {1} (missing \'name\')'. format(pet_id, updated_generated_pet)) updated_response = api_methods.put_pet(updated_generated_pet) # Based on Swagger documentation, 'name' field is required (red *) so this should be 405 test_utils.verify_pet_from_api(updated_generated_pet, updated_response) # Add database check to verify pet is updated updated_api_response = api_methods.get_pet_by_id(pet_id) test_utils.verify_pet_from_api(updated_generated_pet, updated_api_response);
def test_update_pet(): generated_pet = test_utils.generate_pet() pet_id = generated_pet['id'] logger.info('POST pet: {0}'.format(generated_pet)) response = api_methods.post_pet(generated_pet) test_utils.verify_pet_from_api(generated_pet, response) # Add database check to verify pet is created api_response = api_methods.get_pet_by_id(pet_id) test_utils.verify_pet_from_api(generated_pet, api_response) # Update pet with form api_methods.post_pet_by_id(pet_id, "new_name", "new_status") # Add database check to verify pet is updated updated_api_response = api_methods.get_pet_by_id(pet_id) updated_expected_object = copy.deepcopy(generated_pet) updated_expected_object['name'] = "new_name" updated_expected_object['status'] = "new_status" test_utils.verify_pet_from_api(updated_expected_object, updated_api_response)
def test_delete_by_id(): pet_id = api_methods.post_pet(test_utils.generate_pet()).json()['id'] logger.info('Posted pet with id: {0} for deletion'.format(pet_id)) response = api_methods.get_pet_by_id(pet_id) assert response.status_code == constants.HTTP_OK logger.info('Deleting the pet with id: {0}'.format(pet_id)) assert api_methods.delete_pet_by_id( pet_id).status_code == constants.HTTP_OK assert api_methods.get_pet_by_id( pet_id).status_code == constants.HTTP_NOT_FOUND
def test_get_by_id(): generated_pet = test_utils.generate_pet() logger.info('Posting pet: {0}'.format(generated_pet)) api_methods.post_pet(generated_pet) response = api_methods.get_pet_by_id(generated_pet['id']) test_utils.verify_pet_from_api(generated_pet, response)
def test_add_new_valid_pet(): generated_pet = test_utils.generate_pet() logger.info('Posting pet: {0}'.format(generated_pet)) response = api_methods.post_pet(generated_pet) test_utils.verify_pet_from_api(generated_pet, response) # Add database check to verify pet is created api_response = api_methods.get_pet_by_id(generated_pet['id']) test_utils.verify_pet_from_api(generated_pet, api_response)
def test_get_by_invalid_id(): logger.info('Find a pet with invalid id: {0}'.format(constants.INVALID_ID)) assert api_methods.get_pet_by_id( constants.INVALID_ID).status_code == constants.HTTP_NOT_FOUND
def test_get_by_nonexistent_id(): pet_id = random.randint(900000000, 999999999) logger.info('Find a nonexistent pet with id: {0}'.format(pet_id)) assert api_methods.get_pet_by_id( pet_id).status_code == constants.HTTP_NOT_FOUND