Repository: fidals/shopelectro

Issue:
Add absolute urls to the canonical links. stb2
Необходимо поправить построение канонических ссылок на сайте
Адрес в канонической ссылке должен быть обязательно абсолютный
<link rel="canonical" href="https://www.сайт.ру/адрес_страницы" >
а не так
<link rel="canonical" href="/адрес_страницы" > - это неверно
Поисковики игнорируют этот тег, если указан относительный адрес в теге...
У меня при скане появляется много страниц дублей (пагинация), в коде указан каноникал. а при сканировании методом аналогичным поисковому роботу сраницы как канонические не помечаются

Вероятно, на STB нужно сделать так же. 


Discussion:
at the STB resolved with https://github.com/fidals/stroyprombeton/pull/655

Resolving patch:
diff --git a/shopelectro/context_processors.py b/shopelectro/context_processors.py
--- a/shopelectro/context_processors.py
+++ b/shopelectro/context_processors.py
@@ -11,6 +11,6 @@ def shop(request):
     return {
         'shop': settings.SHOP,
         'DEBUG': settings.DEBUG,
-        'BASE_URL': settings.BASE_URL,
+        'base_url': settings.BASE_URL,
         'SENTRY_FRONT_DSN': settings.SENTRY_FRONT_DSN,
     }


Test patch:
diff --git a/shopelectro/tests/tests_selenium_mobile.py b/shopelectro/tests/tests_selenium_mobile.py
--- a/shopelectro/tests/tests_selenium_mobile.py
+++ b/shopelectro/tests/tests_selenium_mobile.py
@@ -4,6 +4,8 @@
 If you need to create new test-suite, subclass it from SeleniumTestCase class.
 Every Selenium-based test suite uses fixture called dump.json.
 """
+import unittest
+
 from django.conf import settings
 from django.test import LiveServerTestCase, override_settings, tag
 from django.urls import reverse
@@ -11,8 +13,8 @@
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support import expected_conditions as EC
 
-from shopelectro.selenium import SiteDriver
 from shopelectro.models import Category, Product
+from shopelectro.selenium import SiteDriver
 
 
 class MobileSeleniumTestCase(LiveServerTestCase):
@@ -64,6 +66,8 @@ def wait_page_loading(self):
             )
         )
 
+    # @todo #850:60m  Fix Mobile.search tests group.
+    #  search_input property doesn't input content.
     @property
     def search_input(self):
         return self.wait.until(EC.visibility_of_element_located(
@@ -81,6 +85,8 @@ def submit_search(self):
         )).click()
         self.wait.until(EC.url_contains('/search/'))
 
+    # waiting self.search_input fix
+    @unittest.skip
     def test_ui(self):
         """
         Test mobile ui.
@@ -93,10 +99,15 @@ def test_ui(self):
         self.toggle_menu()
         self.assertTrue(self.search_input.is_displayed())
 
+    # waiting self.search_input fix
+    @unittest.skip
     def test_search_autocomplete(self):
         """Autocomplete in mobile search should work."""
         self.toggle_menu()
+        print('before input')
+
         self.search_input.send_keys('Cate')
+        print('after input')
         suggestions = self.wait.until(EC.visibility_of_any_elements_located(
             (By.CLASS_NAME, 'autocomplete-suggestion')
         ))
@@ -104,6 +115,8 @@ def test_search_autocomplete(self):
         for item in suggestions[:-1]:
             self.assertTrue(item.get_attribute('data-val') == 'Cate')
 
+    # waiting self.search_input fix
+    @unittest.skip
     def test_search_submit(self):
         """Mobile search form has submit button."""
         self.toggle_menu()
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
@@ -6,6 +6,7 @@
 """
 import json
 from functools import partial
+from itertools import chain
 from operator import attrgetter
 from urllib.parse import urlparse, quote
 from xml.etree import ElementTree as ET
@@ -17,17 +18,15 @@
 from django.test import override_settings, TestCase, tag
 from django.urls import reverse
 from django.utils.translation import ugettext as _
-from itertools import chain
 
 from catalog.helpers import reverse_catalog_url
-from pages.urls import reverse_custom_page
 from pages.models import CustomPage
-
+from pages.urls import reverse_custom_page
 from shopelectro import models
 from shopelectro import views
 from shopelectro.views.service import generate_md5_for_ya_kassa, YANDEX_REQUEST_PARAM
 
-CANONICAL_HTML_TAG = '<link rel="canonical" href="{path}">'
+CANONICAL_HTML_TAG = '<link rel="canonical" href="{base_url}{path}">'
 
 
 def get_page_number(response):
@@ -494,7 +493,10 @@ def test_canonical_meta_tag(self):
         self.assertEqual(response.status_code, 200)
         self.assertContains(
             response,
-            CANONICAL_HTML_TAG.format(path=path),
+            CANONICAL_HTML_TAG.format(
+                base_url=settings.BASE_URL,
+                path=path
+            ),
         )
 
     def test_tags_pagination_has_canonical_links(self):
@@ -519,7 +521,10 @@ def test_tags_pagination_has_canonical_links(self):
         )
         response = self.client.get(paginated_url)
         self.assertContains(
-            response, CANONICAL_HTML_TAG.format(path=not_paginated_url)
+            response, CANONICAL_HTML_TAG.format(
+                base_url=settings.BASE_URL,
+                path=not_paginated_url
+            )
         )
 
     def test_category_matrix_page(self):