Skip to content
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

rf#140 Change redirects dep #384

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
# contains refarm-site modules
- $DEPS_DIR
# Thus, you can work with apps related to the refarm-site
# - $REFARM_SRC/search:/root/.local/lib/python3.6/site-packages/search
#- $REFARM_DIR/search:/root/.local/lib/python3.6/site-packages/search
command: python manage.py runserver 0.0.0.0:$VIRTUAL_HOST_PORT

nodejs:
Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
beautifulsoup4
celery
celery==4.1.0
Django==1.10
django-debug-toolbar
django-redis
django-mptt==0.8.7
django-widget-tweaks
ipython
openpyxl==2.4.2
pillow
psycopg2-binary
openpyxl==2.5.2
Pillow==5.1.0
psycopg2-binary==2.7.4
requests
selenium
selenium-requests
tblib
unidecode
ua-parser==0.7.3
user-agents==1.0.1
selenium==3.11.0
selenium-requests==1.3
tblib==1.3.2
Unidecode==1.0.22
ua-parser==0.8.0
user-agents==1.1.0
sorl-thumbnail==12.4a1
https://github.com/selwin/django-user_agents/archive/master.zip
https://github.com/fidals/refarm-site/archive/0.1.0.zip
https://github.com/fidals/refarm-site/archive/0.1.3.zip
2 changes: 1 addition & 1 deletion shopelectro/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.redirects.models import Redirect
from redirects.models import Redirect
from django.db import models as django_models
from django.urls import reverse
from django.utils.html import format_html
Expand Down
4 changes: 2 additions & 2 deletions shopelectro/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.messages',
'django.contrib.redirects',
'django.contrib.sessions',
'django.contrib.sitemaps',
'django.contrib.sites',
Expand All @@ -66,6 +65,7 @@
'catalog',
'search',
'ecommerce',
'refarm_redirects',
'shopelectro',
]

Expand All @@ -78,10 +78,10 @@
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django_user_agents.middleware.UserAgentMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'refarm_redirects.middleware.RedirectFallbackMiddleware',
]

ROOT_URLCONF = 'shopelectro.urls'
Expand Down
29 changes: 29 additions & 0 deletions shopelectro/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
They all should be using Django's TestClient.
"""
import json
import unittest
from functools import partial
from itertools import chain
from operator import attrgetter
Expand All @@ -13,11 +14,13 @@

from bs4 import BeautifulSoup
from django.conf import settings
from django.contrib.sites.models import Site
from django.db.models import Q
from django.http import HttpResponse
from django.test import TestCase
from django.urls import reverse
from django.utils.translation import ugettext as _
from redirects.models import Redirect

from shopelectro.models import Category, Product, Tag, TagGroup, TagQuerySet, serialize_tags_to_url
from shopelectro.views.service import generate_md5_for_ya_kassa, YANDEX_REQUEST_PARAM
Expand Down Expand Up @@ -516,3 +519,29 @@ def test_admin_autocomplete_has_no_model_pages(self):
f'?term={self.QUOTED_SIGNLE_RESULT_TERM}&pageType=category'
)
self.assertTrue(len(json_to_dict(response)) == 1)


class Redirects(TestCase):

fixtures = ['dump.json']

def test_redirect_on_existing_page(self):
"""DB based redirect from existing url should do, but should not avoid it."""
# take some existing `url_from`
url_from = '/catalog/categories/category-0/tags/6-v/'
response = self.client.get(url_from)
self.assertEqual(response.status_code, 200)

# create redirect from `url_from` to another existing one - `url_to`
url_to = '/catalog/categories/category-0/'
Redirect.objects.create(
site=Site.objects.first(),
old_path=url_from,
new_path=url_to
)

# `url_from` should redirect to `url_to`
response = self.client.get(url_from)
self.assertEqual(response.status_code, 301)
response = self.client.get(url_from, follow=True)
self.assertEqual(response.status_code, 200)