Example #1
0
 def _create_pets(self, count):
     """Factory method to create pets in bulk"""
     pets = []
     for _ in range(count):
         test_pet = PetFactory()
         response = self.client.post(BASE_URL, json=test_pet.serialize())
         self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                          "Could not create test pet")
         new_pet = response.get_json()
         test_pet.id = new_pet["id"]
         pets.append(test_pet)
     return pets
Example #2
0
 def test_read_a_pet(self):
     """It should Read a Pet"""
     pet = PetFactory()
     logging.debug(pet)
     pet.id = None
     pet.create()
     self.assertIsNotNone(pet.id)
     # Fetch it back
     found_pet = Pet.find(pet.id)
     self.assertEqual(found_pet.id, pet.id)
     self.assertEqual(found_pet.name, pet.name)
     self.assertEqual(found_pet.category, pet.category)
Example #3
0
 def _create_pets(self, count):
     """Factory method to create pets in bulk"""
     pets = []
     for _ in range(count):
         test_pet = PetFactory()
         logging.info(f"PetFactory: {test_pet.serialize()}")
         resp = self.app.post(
             BASE_URL, json=test_pet.serialize(), content_type=CONTENT_TYPE_JSON
         )
         self.assertEqual(
             resp.status_code, status.HTTP_201_CREATED, "Could not create test pet"
         )
         new_pet = resp.get_json()
         logging.info(f"JSON Returned: {new_pet}")
         test_pet.id = new_pet["_id"]
         pets.append(test_pet)
     return pets
Example #4
0
 def test_update_a_pet(self):
     """It should Update a Pet"""
     pet = PetFactory()
     logging.debug(pet)
     pet.id = None
     pet.create()
     logging.debug(pet)
     self.assertIsNotNone(pet.id)
     # Change it an save it
     pet.category = "k9"
     original_id = pet.id
     pet.update()
     self.assertEqual(pet.id, original_id)
     self.assertEqual(pet.category, "k9")
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     pets = Pet.all()
     self.assertEqual(len(pets), 1)
     self.assertEqual(pets[0].id, original_id)
     self.assertEqual(pets[0].category, "k9")
Example #5
0
 def test_update_no_id(self):
     """It should not Update a Pet with no id"""
     pet = PetFactory()
     logging.debug(pet)
     pet.id = None
     self.assertRaises(DataValidationError, pet.update)