-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#207 Context classes #212
#207 Context classes #212
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# @todo #183:120m Implement Page, PaginatedProducts, ProductBrands, ProductsImages context classes. | ||
# @todo #183:120m Implement Page, PaginatedProducts context classes. | ||
from . import context, products, tags |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import unittest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this tests we don't document=test contexts functionality, but it's inner (and temporary because of it) realization. But maybe it's about taste and my school There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @duker33 I agree with the point, but unfortunately we still haven't
It is rather about a difference between the black box testing and the white box testing |
||
|
||
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): | ||
|
||
@override_settings(CATEGORY_SORTING_OPTIONS={ | ||
1: {'label': 'price', 'field': 'price', 'direction': ''} | ||
}) | ||
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') | ||
|
||
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() | ||
raw_tags = 'test' | ||
context.tags.ParsedTags(tags_ctx, {'tags': raw_tags}).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) | ||
|
||
def test_404_check_tags(self): | ||
with self.assertRaises(Http404): | ||
context.tags.Checked404Tags(mocked_ctx(qs_attrs={'exists.return_value': False})).qs() |
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.
#183
->#207