def test_create_pet_bad_available(self): """It should not Create a Pet with bad available data""" test_pet = PetFactory() logging.debug(test_pet) # change available to a string test_pet.available = "true" response = self.client.post(BASE_URL, json=test_pet.serialize()) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_purchase_not_available(self): """Purchase a Pet that is not available""" pet = PetFactory() pet.available = False resp = self.app.post( BASE_URL, json=pet.serialize(), content_type=CONTENT_TYPE_JSON ) self.assertEqual(resp.status_code, status.HTTP_201_CREATED) pet_data = resp.get_json() pet_id = pet_data["_id"] logging.info(f"Created Pet with id {pet_id} = {pet_data}") # Request to purchase a Pet should fail resp = self.app.put(f"{BASE_URL}/{pet_id}/purchase") self.assertEqual(resp.status_code, status.HTTP_409_CONFLICT)
def test_purchase_a_pet(self): """Purchase a Pet""" pet = PetFactory() pet.available = True resp = self.app.post( BASE_URL, json=pet.serialize(), content_type=CONTENT_TYPE_JSON ) self.assertEqual(resp.status_code, status.HTTP_201_CREATED) pet_data = resp.get_json() pet_id = pet_data["_id"] logging.info(f"Created Pet with id {pet_id} = {pet_data}") # Request to purchase a Pet resp = self.app.put(f"{BASE_URL}/{pet_id}/purchase") self.assertEqual(resp.status_code, status.HTTP_200_OK) # Retrieve the Pet and make sue it is no longer available resp = self.app.get(f"{BASE_URL}/{pet_id}") self.assertEqual(resp.status_code, status.HTTP_200_OK) pet_data = resp.get_json() self.assertEqual(pet_data["_id"], pet_id) self.assertEqual(pet_data["available"], False)