From 70e084625818c7b68f4fbf9203feeec3f9b294a4 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 9 Oct 2024 11:53:18 +0700 Subject: [PATCH] Added Django 4 support, dropped Python 2 --- .travis-requirements.txt | 1 - django_sofortueberweisung/__init__.py | 2 +- django_sofortueberweisung/models.py | 6 +----- django_sofortueberweisung/views.py | 2 +- django_sofortueberweisung/wrappers.py | 13 ++++--------- setup.py | 5 ++--- tests/tests.py | 21 +++++---------------- 7 files changed, 14 insertions(+), 36 deletions(-) diff --git a/.travis-requirements.txt b/.travis-requirements.txt index 7344ef5..9b0e87c 100644 --- a/.travis-requirements.txt +++ b/.travis-requirements.txt @@ -1,4 +1,3 @@ testfixtures==4.13.3 xmltodict>=0.9.2 -six>=1.10.0 requests>=2.21.0 \ No newline at end of file diff --git a/django_sofortueberweisung/__init__.py b/django_sofortueberweisung/__init__.py index 9767f90..1f356cc 100644 --- a/django_sofortueberweisung/__init__.py +++ b/django_sofortueberweisung/__init__.py @@ -1 +1 @@ -__version__ = '0.2.1' +__version__ = '1.0.0' diff --git a/django_sofortueberweisung/models.py b/django_sofortueberweisung/models.py index 7d49372..1775792 100644 --- a/django_sofortueberweisung/models.py +++ b/django_sofortueberweisung/models.py @@ -1,15 +1,13 @@ import logging from django.template.loader import render_to_string -from six import python_2_unicode_compatible from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.utils import timezone from django_sofortueberweisung import settings as django_sofortueberweisung_settings -@python_2_unicode_compatible class SofortError(models.Model): error_code = models.CharField(_('error code'), max_length=30) error_message = models.CharField(_('error code'), max_length=255) @@ -22,7 +20,6 @@ def __str__(self): return "{0} - {1}".format(self.error_code, self.error_message) -@python_2_unicode_compatible class SofortTransaction(models.Model): transaction_id = models.CharField(_("transaction id"), max_length=255, unique=True) status = models.CharField(_("status"), max_length=255, blank=True) @@ -122,7 +119,6 @@ def create_refund(self, sofort_wrapper, sender_data, amount=None, reasons=None, return sofort_refund -@python_2_unicode_compatible class SofortRefund(models.Model): transaction = models.ForeignKey(SofortTransaction, verbose_name=_("Transaction"), related_name="refunds", on_delete=models.SET_NULL, null=True) diff --git a/django_sofortueberweisung/views.py b/django_sofortueberweisung/views.py index bbaa031..cb48ae3 100644 --- a/django_sofortueberweisung/views.py +++ b/django_sofortueberweisung/views.py @@ -2,7 +2,7 @@ import xmltodict from django.http import HttpResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.generic import View diff --git a/django_sofortueberweisung/wrappers.py b/django_sofortueberweisung/wrappers.py index 30aea37..334e520 100644 --- a/django_sofortueberweisung/wrappers.py +++ b/django_sofortueberweisung/wrappers.py @@ -8,21 +8,16 @@ from django.conf import settings from django.db import IntegrityError from django.template.loader import render_to_string -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django_sofortueberweisung import \ settings as django_sofortueberweisung_settings from django_sofortueberweisung.__init__ import __version__ from django_sofortueberweisung.models import SofortTransaction -try: - # For Python 3.0 and later - from urllib.error import HTTPError - from urllib.request import urlopen - from urllib.request import Request -except ImportError: - # Fall back to Python 2's urllib2 - from urllib2 import HTTPError, Request, urlopen +from urllib.error import HTTPError +from urllib.request import urlopen +from urllib.request import Request class DjangoSofortError(Exception): diff --git a/setup.py b/setup.py index 434eb41..26558a3 100755 --- a/setup.py +++ b/setup.py @@ -40,9 +40,8 @@ def get_package_data(package): return {package: filepaths} REQUIREMENTS = [ - 'Django>=1.8', - 'xmltodict>=0.9.2', - 'six>=1.10.0' + 'Django>=4.0', + 'xmltodict>=0.9.2' ] version = get_version('django_sofortueberweisung') diff --git a/tests/tests.py b/tests/tests.py index 1d3df62..5f281fd 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,11 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from __future__ import unicode_literals - import re -import sys - import xmltodict from django.conf.urls import include, url from django.test import Client, TestCase @@ -17,14 +13,10 @@ from django_sofortueberweisung.wrappers import SofortWrapper from .test_response_mockups import TEST_RESPONSES -try: - # For Python 3.0 and later - from urllib.error import HTTPError - from urllib.request import urlopen - from urllib.request import Request -except ImportError: - # Fall back to Python 2's urllib2 - from urllib2 import HTTPError, Request, urlopen +from urllib.error import HTTPError +from urllib.request import urlopen +from urllib.request import Request + app_name='sofort' urlpatterns = [ @@ -135,10 +127,7 @@ def test_known_transaction_refund(self): self.assertEqual(transaction.transaction_id, refund.transaction.transaction_id) self.assertEqual(transaction, refund.transaction) self.assertEqual(refund.status, 'accepted') - if sys.version_info[0] < 3: - self.assertRegexpMatches(refund.pain, re.compile('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')) - else: - self.assertRegex(refund.pain, re.compile('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')) + self.assertRegex(refund.pain, re.compile('^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$')) @replace('django_sofortueberweisung.wrappers.urlopen', mock_urlopen) def test_known_transaction_refund_error(self):