Repository: fidals/shopelectro

Issue:
tests_selenium.py:395-397: Load the cart lazily. It will...
The puzzle `783-dbb67fb4` from #783 has to be resolved: 

https://github.com/fidals/shopelectro/blob/63cb15c122aec4ac4992e292aefcfecf5057d0b3/shopelectro/tests/tests_selenium.py#L395-L397

The puzzle was created by Artemiy on 24-Mar-19. 

  

If you have any technical questions, don't ask me, submit new tickets instead. The task will be \"done\" when the problem is fixed and the text of the puzzle is _removed_ from the source code. Here is more about [PDD](http://www.yegor256.com/2009/03/04/pdd.html) and [about me](http://www.yegor256.com/2017/04/05/pdd-in-action.html). 



Discussion:
@artemiyds2 @duker33 please pay attention to this new issue.

Resolving patch:
diff --git a/shopelectro/settings/base.py b/shopelectro/settings/base.py
--- a/shopelectro/settings/base.py
+++ b/shopelectro/settings/base.py
@@ -77,18 +77,20 @@
     'shopelectro',
 ]
 
+# Stick to this ordering
+# https://docs.djangoproject.com/en/1.11/ref/middleware/#middleware-ordering
 MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.cache.UpdateCacheMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.locale.LocaleMiddleware',
     'django.middleware.common.CommonMiddleware',
-    'django.middleware.cache.FetchFromCacheMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.cache.FetchFromCacheMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
-    'django.middleware.locale.LocaleMiddleware',
     'django_user_agents.middleware.UserAgentMiddleware',
     'debug_toolbar.middleware.DebugToolbarMiddleware',
     'refarm_redirects.middleware.RedirectAllMiddleware',
diff --git a/shopelectro/urls.py b/shopelectro/urls.py
--- a/shopelectro/urls.py
+++ b/shopelectro/urls.py
@@ -87,6 +87,7 @@ def cache_page(arg):  # Ignore PyFlakesBear
 ]
 
 ecommerce_urls = [
+    url(r'^cart-get/$', never_cache(views.Cart.as_view()), name='cart_get'),
     url(r'^cart-add/$', views.AddToCart.as_view(), name='cart_add'),
     url(r'^cart-change/$', views.ChangeCount.as_view(), name='cart_set_count'),
     url(r'^cart-flush/$', views.FlushCart.as_view(), name='cart_flush'),
diff --git a/shopelectro/views/ecommerce.py b/shopelectro/views/ecommerce.py
--- a/shopelectro/views/ecommerce.py
+++ b/shopelectro/views/ecommerce.py
@@ -34,6 +34,19 @@ def get_context_data(self, request, **kwargs):
         }
 
 
+# @todo #789:60m Make cart routes REST style instead of RPC.
+
+
+class Cart(ec_views.CartModifier):
+
+    cart = SECart
+    position_model = Product
+    order_form = OrderForm
+
+    def get(self, request):
+        return self.json_response(request)
+
+
 class AddToCart(ec_views.AddToCart):
     cart = SECart
     position_model = Product


Test patch:
diff --git a/shopelectro/tests/tests_views.py b/shopelectro/tests/tests_views.py
--- a/shopelectro/tests/tests_views.py
+++ b/shopelectro/tests/tests_views.py
@@ -788,3 +788,21 @@ def test_disabled_cache(self):
             self.client.get(url)['Cache-Control'],
             'max-age=0, no-cache, no-store, must-revalidate',
         )
+
+
+@tag('fast')
+class Cart(TestCase):
+
+    fixtures = ['dump.json']
+
+    def test_get_cart(self):
+        response = self.client.get(reverse('cart_get'))
+        self.assertEqual(response.status_code, 200)
+        self.assertTrue(json_to_dict(response))
+
+    def test_disabled_cache(self):
+        """Cache-Control is disabled for the cart-get."""
+        self.assertEqual(
+            self.client.get(reverse('cart_get'))['Cache-Control'],
+            'max-age=0, no-cache, no-store, must-revalidate',
+        )