diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 217e7d2..02054e0 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -16,7 +16,7 @@ services: - db volumes: - ./../:$SRC_DIR # code volume - command: python manage.py test + command: sleep infinity db: image: postgres:9.5 diff --git a/tests/catalog/test_context.py b/tests/catalog/test_context.py index a38b3a9..a087b2f 100644 --- a/tests/catalog/test_context.py +++ b/tests/catalog/test_context.py @@ -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):