Skip to content

Commit

Permalink
Apply the review's fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemijRodionov committed Nov 13, 2018
1 parent cba2594 commit c17daf1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
5 changes: 3 additions & 2 deletions catalog/newcontext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# @todo #183:120m Implement Page, PaginatedProducts context classes.
from . import context, products, tags
# @todo #207:120m Implement Page, PaginatedProducts context classes.
from . import products, tags
from .context import Context, Contexts, ModelContext, Products, Tags
32 changes: 20 additions & 12 deletions tests/catalog/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ def mocked_ctx(qs_attrs=None, context_attrs=None):

class ProductsContext(TestCase):

@override_settings(CATEGORY_SORTING_OPTIONS={
1: {'label': 'price', 'field': 'price', 'direction': ''}
})
fixtures = ['catalog.json']

def products_ctx(self, qs=None) -> context.context.Products:
return context.context.Products(qs or catalog_models.MockProduct.objects.all())

def test_ordered_products(self):
products_ctx = mocked_ctx()
context.products.OrderedProducts(products_ctx, {'sorting': 1}).qs()
self.assertTrue(products_ctx.qs().order_by.called)
self.assertEqual(products_ctx.qs().order_by.call_args[0][0], 'price')
order_by = 'price'
with override_settings(CATEGORY_SORTING_OPTIONS={
1: {'label': order_by, 'field': order_by, 'direction': ''}
}):
products_ctx = self.products_ctx()
self.assertEqual(
list(products_ctx.qs().order_by(order_by)),
list(context.products.OrderedProducts(products_ctx, {'sorting': 1}).qs()),
)

def test_tagged_products(self):
products_ctx = mocked_ctx()
Expand All @@ -48,14 +55,15 @@ class TagsContext(TestCase):

def test_parsed_tags(self):
tags_ctx = mocked_ctx()
raw_tags = 'test'
context.tags.ParsedTags(tags_ctx, {'tags': raw_tags}).qs()
context.tags.ParsedTags(tags_ctx, {'tags': 'test'}).qs()
self.assertTrue(tags_ctx.qs().parsed.called)

def test_unparsed_tags(self):
tags_ctx = mocked_ctx()
context.tags.ParsedTags(tags_ctx, {}).qs()
self.assertFalse(tags_ctx.qs().parsed.called)
self.assertFalse(
context.tags.ParsedTags(
mocked_ctx(qs_attrs={'none.return_value': []}), {},
).qs()
)

def test_404_check_tags(self):
with self.assertRaises(Http404):
Expand Down

0 comments on commit c17daf1

Please sign in to comment.