Skip to content

Commit

Permalink
rf#255 Remove redundant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Feb 13, 2019
1 parent 65ba872 commit befba00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- db
volumes:
- ./../:$SRC_DIR # code volume
command: python manage.py test
command: sleep infinity

db:
image: postgres:9.5
Expand Down
49 changes: 9 additions & 40 deletions tests/catalog/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,28 @@ def mocked_ctx(qs_attrs=None, context_attrs=None):
class ProductsContext(TestCase):

fixtures = ['catalog.json']
per_page = 30

def context(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.context()
self.assertEqual(
list(products_ctx.qs().order_by(order_by)),
list(context.products.OrderedProducts(products_ctx, 1).qs()),
)
PER_PAGE = 30

def test_paginated_qs(self):
with override_settings(CATEGORY_STEP_MULTIPLIERS=[self.per_page]):
products = self.context()
left_qs, right_qs = 2 * (catalog_models.MockProduct.objects.all(), )
with override_settings(CATEGORY_STEP_MULTIPLIERS=[self.PER_PAGE]):
self.assertEqual(
list(products.qs()[:self.per_page]),
list(left_qs[:self.PER_PAGE]),
list(context.products.PaginatedProducts(
products, '', 1, self.per_page,
).qs()),
right_qs, '', 1, self.PER_PAGE,
).products),
)

def test_paginated_404(self):
page_number = 1
with override_settings(CATEGORY_STEP_MULTIPLIERS=[self.per_page]):
with override_settings(CATEGORY_STEP_MULTIPLIERS=[self.PER_PAGE]):
with self.assertRaises(Http404):
# per_page not in CATEGORY_STEP_MULTIPLIERS
context.products.PaginatedProducts(None, '', page_number, self.per_page-1)
context.products.PaginatedProducts(None, '', page_number, self.PER_PAGE - 1)

with self.assertRaises(Http404):
# page number doesn't exist
context.products.PaginatedProducts(None, '', page_number-1, self.per_page)

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)
context.products.PaginatedProducts(None, '', page_number - 1, self.PER_PAGE)


class TagsContext(TestCase):
Expand Down

0 comments on commit befba00

Please sign in to comment.