コード例 #1
0
    def test_cancel_populate(self):

        c1 = Customer(
            email="*****@*****.**",
            first_name="all",
            last_name="Holmgren",
            postal_code="92294",
            city="Tvärålund",
            phone="0730241790",
            week_0=True,
            week_1=True,
        )
        c1.save()
        c2 = Customer(email="*****@*****.**",
                      first_name="all2",
                      last_name="Holmgren",
                      postal_code="92294",
                      city="Tvärålund",
                      phone="0730241790",
                      week_0=True,
                      week_1=True)
        c2.save()
        d = Delivery(date=date(2030, 1, 1))
        d.save()
        c1.cancel(d)
        d.save()
        d.populate()
        self.assertEqual(d.receiver.all().count(), 1)
        self.assertEqual(
            d.receiver.filter(customer__first_name="all2").count(), 1)
コード例 #2
0
    def test_populate(self):
        c1 = Customer(
            email="*****@*****.**",
            first_name="all",
            last_name="Holmgren",
            postal_code="92294",
            city="Tvärålund",
            phone="0730241790",
            week_0=True,
            week_1=True,
        )
        c1.save()
        c2 = Customer(email="*****@*****.**",
                      first_name="week_0",
                      last_name="Holmgren",
                      postal_code="92294",
                      city="Tvärålund",
                      phone="0730241790",
                      week_0=True,
                      week_1=False)
        c2.save()
        c3 = Customer(email="*****@*****.**",
                      first_name="week_1",
                      last_name="Holmgren",
                      postal_code="92294",
                      city="Tvärålund",
                      phone="0730241790",
                      week_0=False,
                      week_1=True)
        c3.save()

        week_0_delivery = Delivery(date=date(year=2024, month=1, day=8))
        week_0_delivery.save()
        week_0_delivery.populate()

        self.assertEqual(
            week_0_delivery.receiver.filter(
                customer__first_name="week_0").count(), 1)
        self.assertEqual(
            week_0_delivery.receiver.filter(
                customer__first_name="all").count(), 1)
        self.assertEqual(
            week_0_delivery.receiver.filter(
                customer__first_name="week_1").count(), 0)

        week_1_delivery = Delivery(date=date(year=2024, month=1, day=15))
        week_1_delivery.save()
        week_1_delivery.populate()
        self.assertEqual(
            week_1_delivery.receiver.filter(
                customer__first_name="week_0").count(), 0)
        self.assertEqual(
            week_1_delivery.receiver.filter(
                customer__first_name="all").count(), 1)
        self.assertEqual(
            week_1_delivery.receiver.filter(
                customer__first_name="week_1").count(), 1)
コード例 #3
0
 def test_double_populate(self):
     d = Delivery(date=date(year=2025, month=1, day=1))
     d.populate()
     self.assertRaises(AttributeError, d.populate)