Skip to content

Commit

Permalink
Merge pull request #9 from Shin--/django-4-support
Browse files Browse the repository at this point in the history
Added Django 4 support, dropped Python 2
  • Loading branch information
vincenz-e authored Oct 17, 2024
2 parents c48628b + 9097ad3 commit 5901719
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 36 deletions.
1 change: 0 additions & 1 deletion .travis-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
testfixtures==4.13.3
xmltodict>=0.9.2
six>=1.10.0
requests>=2.21.0
2 changes: 1 addition & 1 deletion django_sofortueberweisung/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.2'
__version__ = '1.0.0'
6 changes: 1 addition & 5 deletions django_sofortueberweisung/models.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion django_sofortueberweisung/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 4 additions & 9 deletions django_sofortueberweisung/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
21 changes: 5 additions & 16 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = [
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5901719

Please sign in to comment.