Skip to content

Commit

Permalink
Merge pull request saleor#1718 from patrys/django-20
Browse files Browse the repository at this point in the history
Django 2.0 support
  • Loading branch information
Marcin Gębala authored Feb 1, 2018
2 parents bd66cd6 + 5ca6f90 commit 8bcfe17
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 39 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,8 @@ env:
- DJANGO="master"
matrix:
allow_failures:
- python: "3.4"
env: DJANGO="2.0"
- python: "3.5"
env: DJANGO="2.0"
- python: "3.5"
env: DJANGO="master"
- python: "3.6"
env: DJANGO="2.0"
- python: "3.6"
env: DJANGO="master"
exclude:
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Babel>=2.5
boto3
cairosvg
Django<2.0.0
Django>=1.11
dj_database_url>=0.3.0
dj_email_url>=0.0.4
django-babel>=0.6.1
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ django-redis==4.8.0
django-render-block==0.5 # via django-templated-email
django-storages==1.6.5
django-templated-email==2.2.0
django-versatileimagefield==1.8.1
django-versatileimagefield==1.9
django-webpack-loader==0.5.0
django==1.11.9
django==2.0.1
docutils==0.14 # via botocore
elasticsearch-dsl==5.4.0
elasticsearch==5.5.2
Expand Down Expand Up @@ -83,7 +83,7 @@ pyphen==0.9.4 # via weasyprint
pytest-django==3.1.2
pytest-mock==1.6.3
pytest-vcr==0.3.0
pytest==3.3.2
pytest==3.4.0
python-dateutil==2.6.1 # via botocore, elasticsearch-dsl, faker, freezegun
python3-openid==3.1.0 # via social-auth-core
pytz==2017.3 # via babel, celery, django
Expand Down
2 changes: 1 addition & 1 deletion saleor/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def impersonate(request, uid):
return response


def handle_404(request):
def handle_404(request, exception=None):
return TemplateResponse(request, '404.html', status=404)


Expand Down
8 changes: 4 additions & 4 deletions saleor/dashboard/collection/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.template.response import TemplateResponse
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.core.urlresolvers import reverse
from django.http import JsonResponse
from django.shortcuts import redirect, get_object_or_404
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import reverse
from django.utils.translation import pgettext_lazy

from ...product.models import Collection
from ...core.utils import get_paginator_items
from ...product.models import Collection
from ..views import staff_member_required
from .filters import CollectionFilter
from .forms import CollectionForm
Expand Down
2 changes: 1 addition & 1 deletion saleor/dashboard/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def send_set_password_email(staff):
ctx = {'protocol': 'http',
'domain': site.domain,
'site_name': site.name,
'uid': urlsafe_base64_encode(force_bytes(staff.pk)),
'uid': urlsafe_base64_encode(force_bytes(staff.pk)).decode(),
'token': default_token_generator.make_token(staff)}
send_templated_mail(
template_name='dashboard/staff/set_password',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Migration(migrations.Migration):

dependencies = [
('order', '0031_auto_20180119_0405'),
('product', '0048_product_class_to_type')
]

operations = [
Expand Down
6 changes: 5 additions & 1 deletion saleor/product/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class Product(models.Model, ItemRange):
ProductType, related_name='products', on_delete=models.CASCADE)
name = models.CharField(max_length=128)
description = models.TextField()
category = models.ForeignKey(Category, related_name='products')
category = models.ForeignKey(
Category, related_name='products', on_delete=models.CASCADE)
price = PriceField(
currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)
available_on = models.DateField(blank=True, null=True)
Expand Down Expand Up @@ -386,6 +387,9 @@ class Collection(models.Model):
products = models.ManyToManyField(
Product, blank=True, related_name='collections')

class Meta:
ordering = ['pk']

def __str__(self):
return self.name

Expand Down
43 changes: 25 additions & 18 deletions tests/dashboard/test_staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def test_delete_staff_with_orders(admin_client, staff_user, order):
def test_staff_create_email_with_set_link_password(
admin_client, staff_group):
url = reverse('dashboard:staff-create')
data = {'email': '[email protected]', 'groups': staff_group.pk,
'is_staff': True}
data = {
'email': '[email protected]', 'groups': staff_group.pk,
'is_staff': True}
response = admin_client.post(url, data)
assert User.objects.count() == 2
assert len(mail.outbox) == 1
Expand All @@ -89,34 +90,40 @@ def test_staff_create_email_with_set_link_password(

def test_send_set_password_email(staff_user):
site = Site.objects.get_current()
ctx = {'protocol': 'http',
'domain': site.domain,
'site_name': site.name,
'uid': urlsafe_base64_encode(force_bytes(staff_user.pk)),
'token': default_token_generator.make_token(staff_user)}
send_templated_mail(template_name='dashboard/staff/set_password',
from_email=DEFAULT_FROM_EMAIL,
recipient_list=[staff_user.email],
context=ctx)
ctx = {
'protocol': 'http',
'domain': site.domain,
'site_name': site.name,
'uid': urlsafe_base64_encode(force_bytes(staff_user.pk)).decode(),
'token': default_token_generator.make_token(staff_user)}
send_templated_mail(
template_name='dashboard/staff/set_password',
from_email=DEFAULT_FROM_EMAIL,
recipient_list=[staff_user.email],
context=ctx)
assert len(mail.outbox) == 1
generated_link = ('http://%s/account/password/reset/%s/%s/' %
(ctx['domain'], ctx['uid'].decode('utf-8'), ctx['token']))
generated_link = (
'http://%s/account/password/reset/%s/%s/' % (
ctx['domain'], ctx['uid'], ctx['token']))
sended_message = mail.outbox[0].body
assert generated_link in sended_message


def test_create_staff_and_set_password(admin_client, staff_group):
url = reverse('dashboard:staff-create')
data = {'email': '[email protected]', 'groups': staff_group.pk,
'is_staff': True}
data = {
'email': '[email protected]', 'groups': staff_group.pk,
'is_staff': True}
response = admin_client.post(url, data)
assert response.status_code == 302
new_user = User.objects.get(email='[email protected]')
assert not new_user.has_usable_password()
uid = urlsafe_base64_encode(force_bytes(new_user.pk)),
uid = urlsafe_base64_encode(force_bytes(new_user.pk)).decode()
token = default_token_generator.make_token(new_user)
response = admin_client.get(reverse('account_reset_password_confirm',
kwargs={'uidb64': uid[0], 'token': token}))
response = admin_client.get(
reverse(
'account_reset_password_confirm',
kwargs={'uidb64': uid, 'token': token}))
assert response.status_code == 302
post_data = {'new_password1': 'password', 'new_password2': 'password'}
response = admin_client.post(response['Location'], post_data)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from django.core.urlresolvers import reverse
from django.urls import reverse

from .utils import get_redirect_location
from saleor.product.models import Collection
Expand Down
2 changes: 1 addition & 1 deletion tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal

from django.core.urlresolvers import reverse
from django.urls import reverse
from elasticsearch_dsl.connections import connections
import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_impersonation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch

from saleor.userprofile.models import User
Expand Down
2 changes: 1 addition & 1 deletion tests/test_postgresql_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from saleor.order.models import Order
from saleor.userprofile.models import Address, User

from django.core.urlresolvers import reverse
from django.urls import reverse
from decimal import Decimal
import pytest

Expand Down

0 comments on commit 8bcfe17

Please sign in to comment.