Commit 9c64d3df authored by Luko van der Maas's avatar Luko van der Maas

more progress on tests

parent 534259c3
......@@ -129,7 +129,6 @@ class PaymentAdmin(admin.ModelAdmin):
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "batch":
print(Batch.objects.filter(processed=False))
kwargs["queryset"] = Batch.objects.filter(processed=False)
return super().formfield_for_foreignkey(db_field, request, **kwargs)
......
# Generated by Django 2.2.9 on 2020-01-15 19:39
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('payments', '0006_auto_20191109_1836'),
]
operations = [
migrations.AlterModelOptions(
name='batch',
options={'permissions': (('process_batches', 'Process batch'),), 'verbose_name': 'batch', 'verbose_name_plural': 'batches'},
),
]
......@@ -83,7 +83,7 @@ class Payment(models.Model):
def clean(self):
if self.type != self.TPAY and self.batch is not None:
return ValidationError(
raise ValidationError(
{"batch": "Non Thalia Pay payments cannot " "be added to a batch."}
)
......
......@@ -68,6 +68,10 @@ class PaymentAdminTest(TestCase):
content_type__model="payment", codename="process_payments"
)
self.user.user_permissions.remove(process_perm)
process_perm_batch = Permission.objects.get(
content_type__model="batch", codename="process_batches"
)
self.user.user_permissions.remove(process_perm_batch)
self.client.logout()
self.client.force_login(self.user)
......@@ -159,6 +163,15 @@ class PaymentAdminTest(TestCase):
payment2 = Payment.objects.create(amount=7.5)
self.assertEqual(self.admin.processed_by_link(payment2), "-")
def test_batch_link(self) -> None:
batch = Batch.objects.create(id=1)
payment1 = Payment.objects.create(amount=7.5, processed_by=self.user,
type=Payment.TPAY, batch=batch)
payment2 = Payment.objects.create(amount=7.5, processed_by=self.user,
type=Payment.TPAY)
self.assertEqual("<a href='/admin/payments/batch/1/change/'>your Thalia payments for 2019-12 (not processed)</a>", str(self.admin.batch_link(payment1)))
self.assertEqual("-", self.admin.batch_link(payment2))
@mock.patch("django.contrib.admin.ModelAdmin.message_user")
@mock.patch("payments.services.process_payment")
def test_process_cash(self, process_payment, message_user) -> None:
......@@ -360,7 +373,7 @@ class PaymentAdminTest(TestCase):
"process_card_selected",
"process_wire_selected",
"process_tpay_selected",
"add_to_batch",
"add_to_new_batch",
"export_csv",
],
)
......@@ -398,6 +411,13 @@ class PaymentAdminTest(TestCase):
response.content.decode("utf-8"),
)
def test_batch_foreignkey_filter(self) -> None:
b1 = Batch.objects.create(id=1)
b2 = Batch.objects.create(id=2, processed=True)
p1 = Payment.objects.create(amount=5, processed_by=self.user, type=Payment.TPAY)
pass
@freeze_time("2019-01-01")
@override_settings(SUSPEND_SIGNALS=True)
......
......@@ -21,6 +21,7 @@ class PaymentTest(TestCase):
cls.payment = Payment.objects.create(
amount=10, paid_by=cls.member, processed_by=cls.member,
)
cls.batch = Batch.objects.create()
def test_change_processed_sets_processing_date(self):
"""
......@@ -47,6 +48,25 @@ class PaymentTest(TestCase):
"/admin/payments/payment/{}/change/".format(self.payment.pk),
)
def test_clean(self):
"""
Tests that non thalia pay payments cannot be added to a batch
"""
for payment_type in [Payment.NONE, Payment.CASH, Payment.CARD, Payment.WIRE]:
self.payment.type = payment_type
self.payment.batch = self.batch
with self.assertRaises(ValidationError):
self.payment.clean()
for payment_type in [Payment.NONE, Payment.CASH, Payment.CARD, Payment.WIRE]:
self.payment.type = payment_type
self.payment.batch = None
self.payment.clean()
self.payment.type = Payment.TPAY
self.payment.batch = self.batch
self.payment.clean()
def test_str(self) -> None:
"""
Tests that the output is a description with the amount
......@@ -150,6 +170,16 @@ class BatchModelTest(TestCase):
)
self.assertEqual(batch.total_amount, 36+37)
def test_absolute_url(self) -> None:
b1 = Batch.objects.create(id=1)
self.assertEqual("/admin/payments/batch/1/change/", b1.get_absolute_url())
def test_str(self) -> None:
b1 = Batch.objects.create(id=1)
self.assertEqual("your Thalia payments for 2018-12 (not processed)", str(b1))
b2 = Batch.objects.create(id=2, processed=True)
self.assertEqual("your Thalia payments for 2018-12 (processed)", str(b2))
@freeze_time("2019-01-01")
@override_settings(SUSPEND_SIGNALS=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment