This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests_models.py
71 lines (57 loc) · 2.45 KB
/
tests_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from django.test import TestCase, tag
from pages import models as pages_models
from stroyprombeton import models as stb_models
@tag('fast')
class Category_(TestCase):
fixtures = ['dump.json']
def test_series(self):
option = stb_models.Option.objects.first()
least = option.product.category
root = least.get_root()
self.assertNumQueries(2, lambda: len(root.get_series()))
self.assertIn(option.series, least.get_series())
self.assertIn(option.series, root.get_series())
def test_min_price(self):
"""Non-leaf category should find min price recursively."""
option = stb_models.Option.objects.filter(price__gt=0).first()
category = option.product.category.parent
self.assertNumQueries(1, category.get_min_price)
self.assertGreater(category.get_min_price(), 0)
self.assertLessEqual(category.get_min_price(), option.price)
@tag('fast')
class Section(TestCase):
fixtures = ['dump.json']
def test_min_price(self):
"""Non-leaf category should find min price recursively."""
option = stb_models.Option.objects.filter(price__gt=0).first()
section = option.product.section
self.assertNumQueries(1, section.get_min_price)
self.assertGreater(section.get_min_price(), 0)
self.assertLessEqual(section.get_min_price(), option.price)
@tag('fast')
class Option_(TestCase):
def get_min_price_test_box(self, in_prices, out_price):
product = stb_models.Product.objects.create(
name='some_name',
category=stb_models.Category.objects.create(name='some_name'),
page=pages_models.Page.objects.create(
name='some_name',
is_active=True,
)
)
options = [
stb_models.Option.objects.create(
mark='some_mark',
price=price,
product=product,
) for price in in_prices
]
qs = stb_models.Option.objects.filter(id__in=[o.id for o in options])
self.assertEqual(out_price, qs.min_price())
# page is not deleted by products cascade by unknown for me reason
product.page.delete()
product.category.delete()
def test_get_min_price(self):
self.get_min_price_test_box(in_prices=[], out_price=0.0)
self.get_min_price_test_box(in_prices=[0.0], out_price=0.0)
self.get_min_price_test_box(in_prices=[20.0, 10.0], out_price=10.0)