Ejemplo n.º 1
0
    def test_hurry_mode_not_set_when_stock_high(self):
        # One alert, 5 items in stock. No need to hurry.
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(1, len(mail.outbox))
        self.assertNotIn('Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Ejemplo n.º 2
0
    def test_hurry_mode_not_set_multiple_stockrecords(self):
        # Two stockrecords, 5 items in stock for one. No need to hurry.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertNotIn('Beware that the amount of items in stock is limited',
                         mail.outbox[0].body)
Ejemplo n.º 3
0
    def test_hurry_mode_not_set_when_stock_high(self):
        # One alert, 5 items in stock. No need to hurry.
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(1, len(mail.outbox))
        self.assertNotIn('Beware that the amount of items in stock is limited',
                         mail.outbox[0].body)
Ejemplo n.º 4
0
    def test_hurry_mode_not_set_multiple_stockrecords(self):
        # Two stockrecords, 5 items in stock for one. No need to hurry.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertNotIn('Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Ejemplo n.º 5
0
    def test_hurry_mode_set_multiple_stockrecords(self):
        # Two stockrecords, low stock on both. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertIn('Beware that the amount of items in stock is limited',
                      mail.outbox[0].body)
Ejemplo n.º 6
0
    def test_hurry_mode_set_when_stock_low(self):
        # Two alerts, 1 item in stock. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(2, len(mail.outbox))
        self.assertIn('Beware that the amount of items in stock is limited',
                      mail.outbox[0].body)
Ejemplo n.º 7
0
    def test_hurry_mode_set_multiple_stockrecords(self):
        # Two stockrecords, low stock on both. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertIn('Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Ejemplo n.º 8
0
    def test_hurry_mode_set_when_stock_low(self):
        # Two alerts, 1 item in stock. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(2, len(mail.outbox))
        self.assertIn('Beware that the amount of items in stock is limited',
            mail.outbox[0].body)
Ejemplo n.º 9
0
    def test_deprecated_alert_templates_work(self, mock_loader):
        """
        This test can be removed when support for the deprecated templates is
        dropped.
        """
        mock_loader.side_effect = self._load_deprecated_template
        with warnings.catch_warnings(record=True) as warning_list:
            warnings.simplefilter("always")

            ProductAlert.objects.create(user=self.user, product=self.product)
            send_product_alerts(self.product)
            # Check that warnings were raised
            self.assertTrue(any(item.category == RemovedInOscar20Warning
                                                    for item in warning_list))
            # Check that alerts were still sent
            self.assertEqual(len(mail.outbox), 1)
Ejemplo n.º 10
0
    def test_deprecated_alert_templates_work(self, mock_loader):
        """
        This test can be removed when support for the deprecated templates is
        dropped.
        """
        mock_loader.side_effect = self._load_deprecated_template
        with warnings.catch_warnings(record=True) as warning_list:
            warnings.simplefilter("always")

            ProductAlert.objects.create(user=self.user, product=self.product)
            send_product_alerts(self.product)
            # Check that warnings were raised
            self.assertTrue(
                any(item.category == RemovedInOscar20Warning
                    for item in warning_list))
            # Check that alerts were still sent
            self.assertEqual(len(mail.outbox), 1)
Ejemplo n.º 11
0
 def test_alert_uses_dispatcher(self, mock_dispatch):
     ProductAlert.objects.create(user=self.user, product=self.product)
     send_product_alerts(self.product)
     self.assertEqual(mock_dispatch.call_count, 1)
     self.assertEqual(mock_dispatch.call_args[0][0], self.user)
Ejemplo n.º 12
0
def send_product_alerts(sender, instance, created, **kwargs):
    from oscar.apps.customer.alerts import utils
    utils.send_product_alerts(instance.product)
Ejemplo n.º 13
0
 def test_alert_creates_email_obj(self):
     ProductAlert.objects.create(user=self.user, product=self.product)
     send_product_alerts(self.product)
     self.assertEqual(self.user.emails.count(), 1)
Ejemplo n.º 14
0
 def test_alert_uses_dispatcher(self, mock_dispatch):
     ProductAlert.objects.create(user=self.user, product=self.product)
     send_product_alerts(self.product)
     self.assertEqual(mock_dispatch.call_count, 1)
     self.assertEqual(mock_dispatch.call_args[0][0], self.user)
Ejemplo n.º 15
0
 def test_alert_creates_email_obj(self):
     ProductAlert.objects.create(user=self.user, product=self.product)
     send_product_alerts(self.product)
     self.assertEqual(self.user.emails.count(), 1)
Ejemplo n.º 16
0
def send_product_alerts(sender, instance, created, **kwargs):
    if kwargs.get('raw', False):
        return
    from oscar.apps.customer.alerts import utils
    utils.send_product_alerts(instance.product)
Ejemplo n.º 17
0
def send_product_alerts(sender, instance, created, **kwargs):
    from oscar.apps.customer.alerts import utils
    utils.send_product_alerts(instance.product)