Exemplo n.º 1
0
    def test_remove_all_addresses(self):
        """ Remove all addresses """
        custs = Customer.all()
        self.assertEqual(custs, [])
        cust = Customer(first_name="Marry",
                        last_name="Wang",
                        user_id="marrywang",
                        password="******",
                        active=True)
        self.assertTrue(cust != None)
        self.assertEqual(cust.customer_id, None)
        self.assertEqual(cust.address_id, None)

        cust.save()

        addr = Address(
            street="100 W 100th St.",
            apartment="100",
            city="New York",
            state="New York",
            zip_code="10035",
        )
        addr.customer_id = cust.customer_id
        addr.save()
        all_addresses = Address.all()
        self.assertEquals(len(all_addresses), 1)

        addr.remove_all()
        all_addresses = Address.all()
        self.assertEquals(len(all_addresses), 0)
Exemplo n.º 2
0
    def test_delete_a_customer(self):
        """ Delete a customer """
        customer = Customer(first_name="Marry",
                            last_name="Wang",
                            user_id="marrywang",
                            password="******",
                            active=True)
        customer.save()
        address = Address(street="100 W 100 St.",
                          apartment="100",
                          city="New York",
                          state="New York",
                          zip_code="100")
        address.customer_id = customer.customer_id
        address.save()
        customer.address_id = address.id
        customer.save()

        self.assertEqual(len(Customer.all()), 1)
        self.assertEqual(len(Address.all()), 1)

        # delete the customer and make sure it isn't in the database
        customer.delete()
        self.assertEqual(len(Customer.all()), 0)
        self.assertEqual(len(Address.all()), 0)