def test_quote_age_less_than_one(self):
     cat_dict = {
         'id': 1,
         'age': 0,
         'breed': 'siamese',
         'zip_code': '10704',
         'gender': 'male',
         'name': 'Fluffy',
         'species': 'cat'
     }
     cat = PetFactory(**cat_dict)
     self.assertEqual(cat.quote(), 181.0350)
 def test_quote_age_greater_than_eight(self):
     cat_dict = {
         'id': 1,
         'age': 9,
         'breed': 'siamese',
         'zip_code': '10704',
         'gender': 'male',
         'name': 'Fluffy',
         'species': 'cat'
     }
     cat = PetFactory(**cat_dict)
     self.assertEqual(cat.quote(), 183.0600)
 def test_quote_default_zip_code(self):
     cat_dict = {
         'id': 1,
         'age': 2,
         'breed': 'siamese',
         'zip_code': '10704',
         'gender': 'male',
         'name': 'Fluffy',
         'species': 'cat'
     }
     cat = PetFactory(**cat_dict)
     self.assertEqual(cat.quote(), 181.4400)
 def test_quote_dog_default_breed(self):
     dog_dict = {
         'id': 1,
         'age': 3,
         'breed': 'bull_dog',
         'zip_code': '02481',
         'gender': 'male',
         'name': 'Spot',
         'species': 'dog'
     }
     dog = PetFactory(**dog_dict)
     self.assertEqual(dog.quote(), 182.1600)
 def test_quote_cat_default_breed(self):
     cat_dict = {
         'id': 1,
         'age': 2,
         'breed': 'angora',
         'zip_code': '02481',
         'gender': 'male',
         'name': 'Fluffy',
         'species': 'cat'
     }
     cat = PetFactory(**cat_dict)
     self.assertEqual(cat.quote(), 181.4850)
 def test_quote_dog(self):
     dog_dict = {
         'id': 1,
         'age': 3,
         'breed': 'golden_retriever',
         'zip_code': '02481',
         'gender': 'male',
         'name': 'Spot',
         'species': 'dog'
     }
     dog = PetFactory(**dog_dict)
     self.assertEqual(dog.quote(), 182.3850)
 def test_quote_cat(self):
     cat_dict = {
         'id': 1,
         'age': 2,
         'breed': 'siamese',
         'zip_code': '90210',
         'gender': 'male',
         'name': 'Fluffy',
         'species': 'cat'
     }
     cat = PetFactory(**cat_dict)
     self.assertEqual(cat.quote(), 181.3050)
Esempio n. 8
0
    def insert_pet(self, **kwargs):
        if kwargs.get('id') is not None:
            del kwargs['id']

        pet = PetFactory(**kwargs)
        resp = self.client.put_item(TableName=self.config.get('PETS_TABLE'),
                                    Item={
                                        'id': {
                                            'S': pet.id
                                        },
                                        'name': {
                                            'S': pet.name
                                        },
                                        'age': {
                                            'N': str(pet.age)
                                        },
                                        'breed': {
                                            'S': pet.breed
                                        },
                                        'gender': {
                                            'S': pet.gender
                                        },
                                        'species': {
                                            'S': pet.species
                                        },
                                        'zip_code': {
                                            'S': pet.zip_code
                                        }
                                    })

        return pet
    def test_species_validation(self):
        pet_dict = {
            'age': 2,
            'breed': 'golden_retriever',
            'zip_code': '10704',
            'gender': 'male',
            'name': 'Spot',
            'species': 1
        }

        with self.assertRaises(TypeError):
            pet = PetFactory(**pet_dict)

        pet_dict['species'] = 'whale'
        with self.assertRaises(ValueError):
            pet = PetFactory(**pet_dict)
    def test_breed_validation(self):
        pet_dict = {
            'age': 2,
            'breed': 1,
            'zip_code': '10704',
            'gender': 'male',
            'name': 'Spot',
            'species': 'dog'
        }

        with self.assertRaises(TypeError):
            pet = PetFactory(**pet_dict)

        pet_dict['breed'] = ''

        with self.assertRaises(ValueError):
            pet = PetFactory(**pet_dict)
    def test_set_species(self):
        '''Should not be able to set species of specialized pet'''
        pet_species = ['dog', 'cat']
        for species in pet_species:
            pet_dict = {
                'id': 1,
                'age': 9,
                'breed': 'siamese',
                'zip_code': '10704',
                'gender': 'male',
                'name': 'Fluffy',
                'species': 'cat'
            }

            pet = PetFactory(**pet_dict)
            with self.assertRaises(AttributeError):
                pet.species = 'test'
Esempio n. 12
0
 def get_pets(self):
     resp = self.client.scan(TableName=self.config.get('PETS_TABLE'))
     for item in resp.get('Items'):
         yield PetFactory(
             id=item.get('id').get('S'),
             name=item.get('name').get('S'),
             age=int(item.get('age').get('N')),
             breed=item.get('breed').get('S'),
             gender=item.get('gender').get('S'),
             species=item.get('species').get('S'),
             zip_code=item.get('zip_code').get('S'),
         )
    def test_age_validation(self):
        pet_dict = {
            'age': '2',
            'breed': 'golden_retriever',
            'zip_code': '10704',
            'gender': 'male',
            'name': 'Spot',
            'species': 'dog'
        }

        with self.assertRaises(TypeError):
            pet = PetFactory(**pet_dict)
    def test_unsupported_species(self):
        bird_dict = {
            'id': 1,
            'age': 9,
            'breed': 'siamese',
            'zip_code': '10704',
            'gender': 'male',
            'name': 'Fluffy',
            'species': 'bird'
        }

        with self.assertRaises(ValueError):
            bird = PetFactory(**bird_dict)
 def test_properties(self):
     pet_dict = {
         'id': 1,
         'age': 2,
         'breed': 'golden_retriever',
         'zip_code': '10704',
         'gender': 'male',
         'name': 'Spot',
         'species': 'dog'
     }
     pet = PetFactory(**pet_dict)
     self.assertEqual(pet.id, 1)
     self.assertEqual(pet.age, 2)
     self.assertEqual(pet.breed, 'golden_retriever')
     self.assertEqual(pet.zip_code, '10704')
     self.assertEqual(pet.gender, 'male')
     self.assertEqual(pet.name, 'Spot')
     self.assertEqual(pet.species, 'dog')
Esempio n. 16
0
    def get_pet(self, pet_id):
        resp = self.client.get_item(TableName=self.config.get('PETS_TABLE'),
                                    Key={'id': {
                                        'S': pet_id
                                    }})

        item = resp.get('Item')
        if not item:
            raise DoesNotExist()

        return PetFactory(
            id=item.get('id').get('S'),
            name=item.get('name').get('S'),
            age=int(item.get('age').get('N')),
            breed=item.get('breed').get('S'),
            gender=item.get('gender').get('S'),
            species=item.get('species').get('S'),
            zip_code=item.get('zip_code').get('S'),
        )