Exemplo n.º 1
0
    def create(self, validated_data):
        parcel = search_parcel(validated_data.pop('formatted_address'))
        for attr, val in validated_data.items():
            setattr(parcel, attr, val)
        parcel.save()

        return parcel
Exemplo n.º 2
0
 def setUp(self):
     Owner.objects.create(
         first_name='Nathan',
         last_name='Margaglio',
         home=search_parcel('18 vera ave, buffalo, ny 14225'))
     self.user = User.objects.create(username='******',
                                     email='*****@*****.**')
Exemplo n.º 3
0
    def update(self, instance, validated_data):
        home_data = validated_data['home']
        parcel = search_parcel(home_data['formatted_address'])
        instance.home = parcel

        instance.first_name = validated_data.get('first_name',
                                                 instance.first_name)
        instance.last_name = validated_data.get('last_name',
                                                instance.last_name)
        instance.phone_number = validated_data.get('phone_number',
                                                   instance.phone_number)
        instance.phone_verified = validated_data.get('phone_verified',
                                                     instance.phone_verified)
        instance.do_not_contact = validated_data.get('do_not_contact',
                                                     instance.do_not_contact)
        instance.email_address = validated_data.get('email_address',
                                                    instance.email_address)
        instance.age = validated_data.get('age', instance.age)
        instance.gender = validated_data.get('gender', instance.gender)

        parcel.contact = instance
        parcel.save()
        instance.save()

        return instance
Exemplo n.º 4
0
    def update(self, instance, validated_data):
        home_data = validated_data['home']
        parcel = search_parcel(home_data['formatted_address'])
        instance.home = parcel
        parcel.contact = instance
        parcel.save()
        instance.save()

        return instance
Exemplo n.º 5
0
    def create(self, validated_data):
        home_data = validated_data.pop('home')
        owner = Owner.objects.create(**validated_data)
        owner.home = search_parcel(home_data['formatted_address'])
        owner.home.contact = owner
        owner.home.save()
        owner.save()

        return owner
Exemplo n.º 6
0
    def update(self, instance, validated_data):
        # We don't let Parcel objects update address data
        # Since every address given exists, we want a new
        # Parcel instance to be created instead.
        parcel = search_parcel(validated_data.pop('formatted_address'))
        if parcel is not None and parcel.formatted_address != instance.formatted_address:
            return parcel

        for attr, val in validated_data.items():
            setattr(instance, attr, val)
        instance.save()

        return instance
Exemplo n.º 7
0
    def test_search_parcel_function(self):
        """
        #TODO: Fill this out.
        """
        parcel = search_parcel('18 Vera Ave, Buffalo, NY 14225')

        self.assertEqual(parcel.street_number, '18')
        self.assertEqual(parcel.route, 'Vera Ave')
        self.assertEqual(parcel.city, 'Buffalo')
        self.assertEqual(parcel.state, 'NY')
        self.assertEqual(parcel.postal_code, '14225')

        parcel = search_parcel('1600 Ampitheatre Pkwy Mountain View CA 94043')

        self.assertEqual(parcel.street_number, '1600')
        self.assertEqual(parcel.route, 'Amphitheatre Pkwy')
        self.assertEqual(parcel.city, 'Mountain View')
        self.assertEqual(parcel.state, 'CA')
        self.assertEqual(parcel.postal_code, '94043')

        parcel = search_parcel('Vera Ave, Buffalo, NY 14225')

        self.assertIsNone(parcel)