-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement ProductBrands class * Implement ProductImages class * Create tests: ProductsContext and TagsContext. Fix a lot of code. * Apply the review's fixes
- Loading branch information
1 parent
3a11d7d
commit 4b333aa
Showing
6 changed files
with
138 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# @todo #183:120m Implement Page, PaginatedProducts, ProductBrands, ProductsImages context classes. | ||
# @todo #207:120m Implement Page, PaginatedProducts context classes. | ||
from . import products, tags | ||
from .context import Context, Contexts, ModelContext, Products, Tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import unittest | ||
|
||
from django.test import TestCase, override_settings | ||
from django.http import Http404 | ||
|
||
from catalog import newcontext as context | ||
from tests.catalog import models as catalog_models | ||
|
||
|
||
def mocked_ctx(qs_attrs=None, context_attrs=None): | ||
ctx = unittest.mock.Mock() | ||
ctx.qs.return_value = unittest.mock.Mock(**(qs_attrs or {})) | ||
ctx.context.return_value = unittest.mock.Mock(**(context_attrs or {})) | ||
|
||
return ctx | ||
|
||
|
||
class ProductsContext(TestCase): | ||
|
||
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): | ||
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() | ||
context.products.TaggedProducts( | ||
products_ctx, mocked_ctx(qs_attrs={'exists.return_value': True}), | ||
).qs() | ||
|
||
self.assertTrue(products_ctx.qs().tagged.called) | ||
|
||
def test_non_tagged_products(self): | ||
"""If there are no tags, then products don't changed.""" | ||
products_ctx = mocked_ctx() | ||
context.products.TaggedProducts( | ||
products_ctx, mocked_ctx(qs_attrs={'exists.return_value': False}), | ||
).qs() | ||
|
||
self.assertFalse(products_ctx.qs().tagged.called) | ||
|
||
|
||
class TagsContext(TestCase): | ||
|
||
def test_parsed_tags(self): | ||
tags_ctx = mocked_ctx() | ||
context.tags.ParsedTags(tags_ctx, {'tags': 'test'}).qs() | ||
self.assertTrue(tags_ctx.qs().parsed.called) | ||
|
||
def test_unparsed_tags(self): | ||
self.assertFalse( | ||
context.tags.ParsedTags( | ||
mocked_ctx(qs_attrs={'none.return_value': []}), {}, | ||
).qs() | ||
) | ||
|
||
def test_404_check_tags(self): | ||
with self.assertRaises(Http404): | ||
context.tags.Checked404Tags(mocked_ctx(qs_attrs={'exists.return_value': False})).qs() |
4b333aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
183-d6341b3e
disappeared fromcatalog/context/__init__.py
, that's why I closed #207. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.4b333aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
207-854acb10
discovered incatalog/newcontext/__init__.py
and submitted as #213. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.