Kaynağa Gözat

Fix broken functional tests!

I forgot to modify the test config to account for django-compressor.
master
David Winterbottom 13 yıl önce
ebeveyn
işleme
80c1b0b1a7
2 değiştirilmiş dosya ile 56 ekleme ve 0 silme
  1. 3
    0
      tests/config.py
  2. 53
    0
      tests/unit/offer/custom_benefit_tests.py

+ 3
- 0
tests/config.py Dosyayı Görüntüle

26
                 'django.contrib.sites',
26
                 'django.contrib.sites',
27
                 'django.contrib.flatpages',
27
                 'django.contrib.flatpages',
28
                 'sorl.thumbnail',
28
                 'sorl.thumbnail',
29
+                'compressor',
29
                 ] + OSCAR_CORE_APPS,
30
                 ] + OSCAR_CORE_APPS,
30
             TEMPLATE_CONTEXT_PROCESSORS=(
31
             TEMPLATE_CONTEXT_PROCESSORS=(
31
                 "django.contrib.auth.context_processors.auth",
32
                 "django.contrib.auth.context_processors.auth",
58
             },
59
             },
59
             ROOT_URLCONF='tests._site.urls',
60
             ROOT_URLCONF='tests._site.urls',
60
             LOGIN_REDIRECT_URL='/accounts/',
61
             LOGIN_REDIRECT_URL='/accounts/',
62
+            STATIC_URL='/static/',
63
+            COMPRESS_ENABLED=False,
61
             DEBUG=False,
64
             DEBUG=False,
62
             SITE_ID=1,
65
             SITE_ID=1,
63
             APPEND_SLASH=True,
66
             APPEND_SLASH=True,

+ 53
- 0
tests/unit/offer/custom_benefit_tests.py Dosyayı Görüntüle

1
+from decimal import Decimal as D
2
+
3
+from django.test import TestCase
4
+from django.contrib.auth.models import User
5
+from django_dynamic_fixture import G
6
+import mock
7
+
8
+from oscar.apps.offer import custom, models
9
+from oscar.apps.basket.models import Basket
10
+
11
+
12
+class ChangesOwnerName(models.Benefit):
13
+
14
+    class Meta:
15
+        proxy = True
16
+
17
+    def apply(self, basket, condition, offer=None):
18
+        basket.owner.first_name = "Terry"
19
+        basket.owner.save()
20
+        return D('0.00')
21
+
22
+    @property
23
+    def description(self):
24
+        return 'Changes owners name'
25
+
26
+
27
+class NoDescription(models.Benefit):
28
+
29
+    class Meta:
30
+        proxy = True
31
+
32
+    def apply(self, basket, condition, offer=None):
33
+        return D('0.00')
34
+
35
+
36
+class TestACustomBenefit(TestCase):
37
+
38
+    def test_must_implement_a_description_property(self):
39
+        with self.assertRaises(RuntimeError):
40
+            custom.create_benefit(NoDescription)
41
+
42
+
43
+class TestCustomBenefit(TestCase):
44
+
45
+    def setUp(self):
46
+        self.benefit = custom.create_benefit(ChangesOwnerName)
47
+        self.condition = mock.Mock()
48
+        self.basket = Basket()
49
+
50
+    def test_applies_correctly(self):
51
+        self.basket.owner = G(User, first_name="Alan")
52
+        self.benefit.proxy().apply(self.basket, self.condition)
53
+        self.assertEqual("Terry", self.basket.owner.first_name)

Loading…
İptal
Kaydet