...
 
Commits (5)
......@@ -47,7 +47,7 @@ codestyle:
- poetry run python manage.py makemigrations --no-input --check --dry-run
- poetry run python -Wall -mcoverage run manage.py test
- coverage report --fail-under=100 --omit registrations/urls.py registrations/**.py
- coverage report --fail-under=97.32 --omit payments/urls.py payments/**.py
- coverage report --fail-under=100 --omit payments/urls.py payments/**.py
- coverage report
python37-django22:
......
This diff is collapsed.
......@@ -7,44 +7,43 @@ license = "AGPL-3.0-or-later"
[tool.poetry.dependencies]
python = "^3.7"
django-localflavor = "~2.1"
freezegun = "~0.3.11"
bleach = "~3.1"
django-tinymce4-lite = "~1.7"
rcssmin = "~1.0"
djangorestframework = "~3.11"
django-ical = "~1.5"
django-libsass = "~0.7.0"
python-magic = "~0.4.15"
Django = "~2.2"
Pillow = "~7.0"
django-compressor = "^2.4"
psycopg2-binary = "~2.8"
bcrypt = "~3.1"
argon2_cffi = "~19.2"
uWSGI = "~2.0"
django-bootstrap4 = "~1.1.0"
firebase-admin = "~3.2"
sentry-sdk = "~0.14.0"
django-sendfile2 = "~0.4.2"
django-localflavor = { git = "https://github.com/django/django-localflavor.git", rev="d2ce849484640999a2fde7106407f7217a3c95c1" }
freezegun = "0.3.12"
bleach = "3.1"
django-tinymce4-lite = "1.7.5"
djangorestframework = "3.11"
django-ical = "1.5"
django-libsass = "0.7.0"
python-magic = "0.4.15"
Django = "2.2.9"
Pillow = "7.0"
django-compressor = "2.4"
psycopg2-binary = "2.8.4"
bcrypt = "3.1.7"
argon2_cffi = "19.2"
uWSGI = "2.0.18"
django-bootstrap4 = "1.1.1"
firebase-admin = "3.2.1"
sentry-sdk = "0.14.0"
django-sendfile2 = "0.4.3"
# docs requirements
recommonmark = { version = "~0.6.0", optional = true }
sphinx = { version = "~2.3", optional = true }
google-api-python-client = "^1.7.11"
recommonmark = { version = "0.6.0", optional = true }
sphinx = { version = "2.3.1", optional = true }
google-api-python-client = "1.7.11"
[tool.poetry.extras]
docs = ["recommonmark", "sphinx"]
[tool.poetry.dev-dependencies]
django-template-check = "~0.3.1"
factory_boy = "~2.12"
pydenticon = "~0.3.1"
pylint = "~2.4"
pylint-django = "~2.0"
Faker = "~3.0"
coverage = "~4.5"
black = "~19.10b0"
django-template-check = "0.3.1"
factory_boy = "2.12"
pydenticon = "0.3.1"
pylint = "2.4.4"
pylint-django = "2.0.13"
Faker = "3.0"
coverage = "5.0.3"
black = "19.10b0"
[tool.black]
exclude = '(/(\.eggs|\.git|\.tox)/|migrations)'
......
......@@ -15,4 +15,4 @@ source = .
precision = 2
skip_covered = True
show_missing = True
fail_under = 60
fail_under = 65
......@@ -20,7 +20,6 @@ from django.utils.crypto import get_random_string
from django.utils.translation import pgettext_lazy, gettext_lazy as _
from payments.models import BankAccount
from thaliawebsite.settings import THALIA_PAY_ENABLED_PAYMENT_METHOD
from activemembers.models import MemberGroup, MemberGroupMembership
from utils import countries
......@@ -203,11 +202,11 @@ class Member(User):
def tpay_enabled(self):
"""Does this user have a bank account with Direct Debit enabled"""
bank_accounts = BankAccount.objects.filter(owner=self)
if THALIA_PAY_ENABLED_PAYMENT_METHOD and bank_accounts.exists():
if bank_accounts.last().valid:
return True
else:
return False
return (
settings.THALIA_PAY_ENABLED_PAYMENT_METHOD
and bank_accounts.exists()
and bank_accounts.last().valid
)
def _profile_image_path(_instance, _filename):
......
......@@ -30,7 +30,9 @@ def process_payment(
# the processing date
for payment in queryset:
if pay_type != Payment.TPAY or (
pay_type == Payment.TPAY and payment.paid_by.tpay_enabled
pay_type == Payment.TPAY
and payment.paid_by
and payment.paid_by.tpay_enabled
):
payment.type = pay_type
payment.processed_by = processed_by
......
......@@ -4,11 +4,11 @@ from freezegun import freeze_time
from members.models import Member
from payments import services
from payments.models import BankAccount
from payments.models import BankAccount, Payment
@freeze_time("2019-01-01")
@override_settings(SUSPEND_SIGNALS=True)
@override_settings(SUSPEND_SIGNALS=True, THALIA_PAY_ENABLED_PAYMENT_METHOD=True)
class ServicesTest(TestCase):
"""
Test for the services
......@@ -20,6 +20,40 @@ class ServicesTest(TestCase):
def setUpTestData(cls):
cls.member = Member.objects.filter(last_name="Wiggers").first()
def test_process_payment(self):
BankAccount.objects.create(
owner=self.member,
initials="J",
last_name="Test",
iban="NL91ABNA0417164300",
mandate_no="11-2",
valid_from=timezone.now().date() - timezone.timedelta(days=5),
last_used=timezone.now().date() - timezone.timedelta(days=5),
signature="base64,png",
)
p1 = Payment.objects.create(type=Payment.NONE, notes="Test payment", amount=1)
r1 = services.process_payment(
Payment.objects.filter(pk=p1.pk), self.member, Payment.CARD
)
self.assertEqual(r1, [p1])
p2 = Payment.objects.create(type=Payment.NONE, notes="Test payment", amount=2)
r2 = services.process_payment(
Payment.objects.filter(pk=p2.pk), self.member, Payment.TPAY
)
self.assertEqual(r2, [])
p3 = Payment.objects.create(
type=Payment.NONE, notes="Test payment", amount=3, paid_by=self.member
)
self.assertTrue(self.member.tpay_enabled)
r3 = services.process_payment(
Payment.objects.filter(pk=p3.pk), self.member, Payment.TPAY
)
self.assertEqual(r3, [p3])
def test_update_last_used(self):
BankAccount.objects.create(
owner=self.member,
......
from django.contrib.auth import get_user_model
from django.test import Client, TestCase, override_settings
from freezegun import freeze_time
from django.urls import reverse
from freezegun import freeze_time
from members.models import Member
from payments.models import BankAccount
from payments.views import BankAccountCreateView, BankAccountListView
from payments.models import BankAccount, Payment
@freeze_time("2019-01-01")
......@@ -34,7 +33,6 @@ class BankAccountCreateViewTest(TestCase):
)
def setUp(self):
self.view = BankAccountCreateView()
self.client = Client()
self.client.force_login(self.login_user)
......@@ -193,51 +191,6 @@ class BankAccountRevokeViewTest(TestCase):
fixtures = ["members.json"]
@classmethod
def setUpTestData(cls):
cls.login_user = Member.objects.filter(last_name="Wiggers").first()
cls.account = BankAccount.objects.create(
owner=cls.login_user,
initials="J",
last_name="Test",
iban="NL91ABNA0417164300",
)
BankAccount.objects.create(
owner=None,
initials="Someone",
last_name="Else",
iban="BE68539007547034",
bic="NBBEBEBB",
)
def setUp(self):
self.view = BankAccountCreateView()
self.client = Client()
self.client.force_login(self.login_user)
def test_not_logged_in(self):
"""
If there is no logged-in user they should redirect
to the authentication page
"""
self.client.logout()
response = self.client.get(reverse("payments:bankaccount-add"), follow=True)
self.assertEqual(200, response.status_code)
self.assertEqual(
[("/user/login/?next=" + reverse("payments:bankaccount-add"), 302)],
response.redirect_chain,
)
@override_settings(SUSPEND_SIGNALS=True)
class BankAccountListViewTest(TestCase):
"""
Test for the BankAccountListView
"""
fixtures = ["members.json"]
@classmethod
def setUpTestData(cls):
cls.login_user = Member.objects.filter(last_name="Wiggers").first()
......@@ -261,7 +214,6 @@ class BankAccountListViewTest(TestCase):
def setUp(self):
self.account1.refresh_from_db()
self.account2.refresh_from_db()
self.view = BankAccountListView()
self.client = Client()
self.client.force_login(self.login_user)
......@@ -348,3 +300,122 @@ class BankAccountListViewTest(TestCase):
.first()
.valid
)
@override_settings(SUSPEND_SIGNALS=True)
class BankAccountListViewTest(TestCase):
"""
Test for the BankAccountListView
"""
fixtures = ["members.json"]
@classmethod
def setUpTestData(cls):
cls.login_user = Member.objects.filter(last_name="Wiggers").first()
cls.account1 = BankAccount.objects.create(
owner=cls.login_user,
initials="J1",
last_name="Test",
iban="NL91ABNA0417164300",
)
cls.account2 = BankAccount.objects.create(
owner=Member.objects.exclude(last_name="Wiggers").first(),
initials="J2",
last_name="Test",
iban="BE68539007547034",
bic="NBBEBEBB",
valid_from="2019-03-01",
signature="sig",
mandate_no="11-2",
)
def setUp(self):
self.account1.refresh_from_db()
self.account2.refresh_from_db()
self.client = Client()
self.client.force_login(self.login_user)
def test_not_logged_in(self):
"""
If there is no logged-in user they should redirect
to the authentication page
"""
self.client.logout()
response = self.client.post(reverse("payments:bankaccount-list"), follow=True,)
self.assertEqual(200, response.status_code)
self.assertEqual(
[("/user/login/?next=" + reverse("payments:bankaccount-list"), 302,)],
response.redirect_chain,
)
def test_accounts(self):
"""
The page should show only accounts of the logged-in user
"""
response = self.client.get(reverse("payments:bankaccount-list"), follow=True,)
self.assertEqual(200, response.status_code)
self.assertContains(response, "NL91ABNA0417164300")
self.assertNotContains(response, "BE68539007547034")
@freeze_time("2019-04-01")
@override_settings(SUSPEND_SIGNALS=True)
class PaymentListViewTest(TestCase):
"""
Test for the PaymentListView
"""
fixtures = ["members.json"]
@classmethod
def setUpTestData(cls):
cls.login_user = Member.objects.filter(last_name="Wiggers").first()
cls.account1 = BankAccount.objects.create(
owner=cls.login_user,
initials="J1",
last_name="Test",
iban="NL91ABNA0417164300",
valid_from="2019-03-01",
signature="sig",
mandate_no="11-2",
)
cls.payment1 = Payment.objects.create(
paid_by=cls.login_user,
notes="Testing Payment 1",
amount=10,
type=Payment.CARD,
processing_date="2019-03-06",
)
def setUp(self):
self.account1.refresh_from_db()
self.payment1.refresh_from_db()
self.client = Client()
self.client.force_login(self.login_user)
def test_not_logged_in(self):
"""
If there is no logged-in user they should redirect
to the authentication page
"""
self.client.logout()
response = self.client.post(reverse("payments:payment-list"), follow=True,)
self.assertEqual(200, response.status_code)
self.assertEqual(
[("/user/login/?next=" + reverse("payments:payment-list"), 302,)],
response.redirect_chain,
)
def test_contents(self):
"""
Test if the view shows payments
"""
response = self.client.get(
reverse("payments:payment-list", kwargs={"year": 2019, "month": 3}),
follow=True,
)
self.assertEqual(200, response.status_code)
self.assertContains(response, "Testing Payment 1")