Пример #1
0
    def test_modified_save_function_super_save(self):

        first_address = Address()
        first_address.house_number = '3509'
        first_address.road = 'Pelican Brief Ln'
        first_address.postcode = '89084'
        first_address.city = "North Las Vegas"
        first_address.state = 'NV'

        first_address.save()

        saved_addresses = Address.objects.all()
        self.assertEqual(saved_addresses.count(), 1)

        first_saved_address = saved_addresses[0]
        first_saved_address.house_number = '3520'
        first_saved_address.save(update_fields=['house_number'])

        self.assertEqual(str(first_saved_address),
                         '3520 Pelican Brief Ln, North Las Vegas, NV 89084')

        second_address = Address()
        second_address.po_box = '17'
        second_address.city = 'henderson'
        second_address.state = 'nv'
        second_address.postcode = '89119'
        second_address.county = 'Clark'
        second_address.save()

        saved_addresses = Address.objects.all()
        self.assertEqual(saved_addresses.count(), 2)

        second_saved_address = saved_addresses[1]
        self.assertEqual(second_saved_address.county, 'Clark')
Пример #2
0
    def test_modified_save_function_pobox_vs_house(self):

        first_address = Address()
        first_address.house_number = '3509'
        first_address.road = 'pelican brief ln'
        first_address.postcode = '89084'
        first_address.city = "north las vegas"
        first_address.state = 'nevada'

        first_address.save()

        second_address = Address()
        second_address.po_box = '17'
        second_address.city = 'henderson'
        second_address.state = 'nv'
        second_address.postcode = '89119'

        second_address.save()

        saved_addresses = Address.objects.all()
        self.assertEqual(saved_addresses.count(), 2)

        first_saved_address = saved_addresses[0]
        second_saved_address = saved_addresses[1]

        self.assertEqual(str(first_saved_address),
                         '3509 Pelican Brief Ln, North Las Vegas, NV 89084')
        self.assertEqual(str(second_saved_address),
                         'PO Box 17, Henderson, NV 89119')
Пример #3
0
    def test_save_unit_address(self):

        first_address = Address()
        first_address.house_number = '3509'
        first_address.road = 'pelican brief ln'
        first_address.unit = '2B'
        first_address.postcode = '89084'
        first_address.city = "north las vegas"
        first_address.state = 'nevada'

        first_address.save()

        saved_addresses = Address.objects.all()
        first_saved_address = saved_addresses[0]
        self.assertEqual(
            str(first_saved_address),
            '3509 Pelican Brief Ln, 2B, North Las Vegas, NV 89084')
Пример #4
0
    def test_creating_containers_with_addresses(self):

        first_address = Address()
        first_address.house_number = '3509'
        first_address.road = 'Pelican Brief Ln'
        first_address.postcode = '89084'
        first_address.city = 'North Las Vegas'
        first_address.state = 'Nevada'
        first_address.country = 'USA'
        first_address.save()

        first_container = Container()
        first_container.name = 'Tardis'
        first_container.save()
        first_container.address.add(first_address)

        saved_containers = Container.objects.all()
        self.assertEqual(saved_containers.count(), 1)

        first_saved_container = saved_containers[0]
        self.assertEqual(first_saved_container.address.all()[0].city,
                         'North Las Vegas')