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
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='*****@*****.**')
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
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
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
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
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)