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)
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)
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)
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)
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 == RemovedInWshop20Warning for item in warning_list)) # Check that alerts were still sent self.assertEqual(len(mail.outbox), 1)
def send_product_alerts(sender, instance, created, **kwargs): if kwargs.get('raw', False): return from wshop.apps.customer.alerts import utils utils.send_product_alerts(instance.product)
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)
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)