Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resignation tests kerstens fork #569

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c61e5e1
First suggestion for ShiftAttendance entry in contributing
kerstenkenan Sep 29, 2024
e585045
First attempt ;) for getting the shift calendar more readable.
kerstenkenan Sep 29, 2024
3e0dbaf
Collasping also for the log view
kerstenkenan Sep 29, 2024
500a694
Fixed hopefully all changes requests.
kerstenkenan Sep 30, 2024
929ef80
Fixed text for ShiftAttendance.
kerstenkenan Sep 30, 2024
9a5c7d7
Fixed collapsing list.
kerstenkenan Sep 30, 2024
ca6596d
Deleted all "filter-button" classes.
kerstenkenan Oct 1, 2024
19935cf
Set seletc2-width to 100%.
kerstenkenan Oct 1, 2024
1dce65f
Last fixes with flexbox ;)
kerstenkenan Oct 2, 2024
fd43b26
Align title to center with flexbox.
kerstenkenan Oct 2, 2024
6462633
Translations corrections (hint from Vicky).
kerstenkenan Oct 2, 2024
e57e7c6
Fixes in opening hours.
kerstenkenan Oct 4, 2024
0b4b4d5
Merge pull request #562 from kerstenkenan/calendar-readability
kerstenkenan Oct 4, 2024
059f4e9
Merge pull request #564 from kerstenkenan/collapsing-for-logs
kerstenkenan Oct 4, 2024
1e0df74
Merge pull request #563 from kerstenkenan/contributing
kerstenkenan Oct 4, 2024
96156fe
Missing po-file
kerstenkenan Oct 4, 2024
12a0eb1
Restored 24h time
kerstenkenan Oct 4, 2024
d2e057f
Sorry for fuzzied po-file. Removed.
kerstenkenan Oct 5, 2024
e0a2082
Merge pull request #565 from kerstenkenan/translation-fixes
kerstenkenan Oct 6, 2024
5f1f24b
Translations fixes
kerstenkenan Oct 7, 2024
22343ef
Merge branch 'master' into po-file
kerstenkenan Oct 7, 2024
d0ae1c1
Merge pull request #568 from kerstenkenan/po-file
kerstenkenan Oct 7, 2024
f45682e
Merge remote-tracking branch 'origin/resignation_tests' into resignat…
kerstenkenan Oct 7, 2024
1062477
Update translations.
kerstenkenan Oct 7, 2024
5b4c8be
Search for Nonetype im form test.
kerstenkenan Oct 9, 2024
f241f23
test_membershipResignationForm_is_valid & test_validate_shareOwner_fu…
kerstenkenan Oct 11, 2024
5277655
Form tests done.
kerstenkenan Oct 14, 2024
a19c55d
Form tests work, but view tests still fails.
kerstenkenan Nov 1, 2024
830d6c1
Updateview-tests ready
kerstenkenan Nov 5, 2024
f2bf799
Changed service-function update_shifts_and_shares_and_pay_out_day in …
kerstenkenan Nov 5, 2024
f8ea2e6
Several fixes for all resignation-tests.
kerstenkenan Nov 9, 2024
f28ac19
More fixes for resignation-tests.
kerstenkenan Nov 15, 2024
ef86f52
Even more fixes for resignation-tests 1.0
kerstenkenan Nov 17, 2024
e2c541b
Even more fixes for resignation-tests 1.1
kerstenkenan Nov 17, 2024
bf95461
Even more fixes for resignation-tests 1.2
kerstenkenan Nov 17, 2024
dafaad3
Even more fixes for resignation-tests 1.3
kerstenkenan Nov 17, 2024
5cffd51
Even more fixes for resignation-tests 1.4
kerstenkenan Nov 17, 2024
0e87487
Even more fixes for resignation-tests 1.5
kerstenkenan Nov 18, 2024
1cc8a1d
Even more fixes for resignation-tests 1.6
kerstenkenan Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 5.1.1 on 2024-11-09 16:53

import django.contrib.postgres.fields.hstore
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("coop", "0046_deleteincomingpaymentlogentry"),
("log", "0007_auto_20240702_1748"),
]

operations = [
migrations.CreateModel(
name="MembershipResignationDeleteLogEntry",
fields=[
(
"logentry_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="log.logentry",
),
),
("values", django.contrib.postgres.fields.hstore.HStoreField()),
],
options={
"abstract": False,
},
bases=("log.logentry",),
),
migrations.AlterField(
model_name="membershipresignation",
name="transferring_shares_to",
field=models.ForeignKey(
help_text="Leave this empty if the resignation type is not a transfer to another member",
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="owner_to_transfer",
to="coop.shareowner",
verbose_name="OwnerToTransfer",
),
),
]
14 changes: 13 additions & 1 deletion tapir/coop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class ResignationType(models.TextChoices):
pay_out_day = models.DateField(null=True)
cancellation_reason = models.CharField(max_length=1000)
resignation_type = models.CharField(choices=ResignationType.choices, max_length=50)
transferring_shares_to = models.OneToOneField(
transferring_shares_to = models.ForeignKey(
ShareOwner,
on_delete=models.deletion.PROTECT,
verbose_name="OwnerToTransfer",
Expand Down Expand Up @@ -860,3 +860,15 @@ def populate(
old_frozen=old_frozen,
new_frozen=new_frozen,
)

class MembershipResignationDeleteLogEntry(ModelLogEntry):
template_name = "coop/log/delete_resignmember_log_entry.html"

def populate(
self,
actor: User,
model: MembershipResignation,
):
return super().populate_base(
actor=actor, share_owner=model.share_owner, model=model
)
19 changes: 8 additions & 11 deletions tapir/coop/services/MembershipResignationService.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,12 @@ def delete_shareowner_membershippauses(resignation: MembershipResignation):
share_owner=resignation.share_owner
):
if pause.end_date is not None:
if resignation.pay_out_day is not None:
if resignation.pay_out_day <= pause.end_date:
pause.update(end_date=resignation.pay_out_day)
elif pause.start_date > resignation.pay_out_day:
pause.delete()
else:
if resignation.cancellation_date <= pause.end_date:
pause.update(end_date=resignation.cancellation_date)
elif pause.start_date > resignation.cancellation_date:
pause.delete()
if resignation.pay_out_day <= pause.end_date:
pause.end_date=resignation.pay_out_day
pause.save()
else:
pause.update(end_date=resignation.cancellation_date)
if pause.start_date > resignation.pay_out_day:
pause.delete()
else:
pause.end_date=resignation.cancellation_date
pause.save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% blocktranslate %}
Reactivated resigned member
{% endblocktranslate %}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h5 class="modal-title">Attention!</h5>
class="close"
data-bs-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×;</span>
<span aria-hidden="true">×</span>
</button>
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
</div>
<p class="m-2">
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
from http import HTTPStatus
from unittest.mock import patch, Mock
from icecream import ic

from django.core import mail
from django.urls import reverse
Expand Down
120 changes: 51 additions & 69 deletions tapir/coop/tests/membership_resignation/test_delete_view.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import datetime
from http import HTTPStatus
from icecream import ic
import json

from django.urls import reverse

from tapir.coop.config import feature_flag_membership_resignation
from tapir.coop.models import (
MembershipResignation,
MembershipResignationUpdateLogEntry,
MembershipResignationDeleteLogEntry,
ShareOwnership,
)
from tapir.coop.tests.factories import (
MembershipResignationFactory,
ShareOwnershipFactory,
ShareOwnerFactory,
)
from tapir.utils.tests_utils import FeatureFlagTestMixin, TapirFactoryTestBase

Expand All @@ -23,91 +20,76 @@ class TestMembershipResignationDeleteView(FeatureFlagTestMixin, TapirFactoryTest
def setUp(self) -> None:
super().setUp()

# def test_membershipResignationDeleteView_loggedInAsNormalUser_accessDenied(self):
# self.given_feature_flag_value(feature_flag_membership_resignation, True)
# self.login_as_normal_user()
# resignation: MembershipResignation = MembershipResignationFactory.create()

# response = self.client.post(
# reverse("coop:resign_member_remove", args=[resignation.id]),
# data=resignation.data,
# follow=True,
# )

# self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

# def test_membershipResignationDeleteView_loggedInAsMemberOffice_accessGranted(self):
# self.given_feature_flag_value(feature_flag_membership_resignation, True)
# self.login_as_member_office_user()
# resignation: MembershipResignation = MembershipResignationFactory.create()
def test_membershipResignationDeleteView_loggedInAsNormalUser_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
self.login_as_normal_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

# response = self.client.post(
# reverse("coop:resign_member_remove", args=[resignation.id]),
# data=resignation.data,
# follow=True,
# )
response = self.client.post(
reverse("coop:resign_member_remove", args=[resignation.id]),
follow=True,
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
)
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

# self.assertStatusCode(response, HTTPStatus.FOUND)
def test_membershipResignationDeleteView_loggedInAsMemberOffice_accessGranted(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
self.login_as_member_office_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

# def test_membershipResignationDeleteView_featureFlagDisabled_accessDenied(self):
# self.given_feature_flag_value(feature_flag_membership_resignation, False)
# self.login_as_member_office_user()
# resignation: MembershipResignation = MembershipResignationFactory.create()
response = self.client.post(
reverse("coop:resign_member_remove", args=[resignation.id]),
follow=True,
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
)
self.assertStatusCode(response, HTTPStatus.OK)

# response = self.client.post(
# reverse("coop:resign_member_remove", args=[resignation.id]),
# follow=True,
# )
def test_membershipResignationDeleteView_featureFlagDisabled_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, False)
self.login_as_member_office_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

# self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
response = self.client.post(
reverse("coop:resign_member_remove", args=[resignation.id]),
follow=True,
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
)

# def test_membershipResignationDeleteView_default_sharesEndDateSetToNone(self):
# self.given_feature_flag_value(feature_flag_membership_resignation, True)
# self.login_as_member_office_user()
# resignation: MembershipResignation = MembershipResignationFactory.create()
# resignation.share_owner.share_ownerships.update(end_date=datetime.date.today())
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

# response = self.client.post(
# reverse("coop:resign_member_remove", args=[resignation.id]),
# data=resignation.data,
# follow=True,
# )
def test_membershipResignationDeleteView_default_sharesEndDateSetToNone(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
self.login_as_member_office_user()
resignation: MembershipResignation = MembershipResignationFactory.create()
resignation.share_owner.share_ownerships.update(end_date=datetime.date.today())

# self.assertStatusCode(response, HTTPStatus.OK)
# self.assertTrue(
# all(
# [
# share_ownership.end_date is None
# for share_ownership in resignation.share_owner.share_ownerships.all()
# ]
# )
# )
response = self.client.post(
reverse("coop:resign_member_remove", args=[resignation.id]),
follow=True,
)
self.assertStatusCode(response, HTTPStatus.OK)
self.assertTrue(
all(
[
share_ownership.end_date is None
for share_ownership in resignation.share_owner.share_ownerships.all()
]
)
)

def test_membershipResignationDeleteView_default_logEntryCreated(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
actor = self.login_as_member_office_user()
resignation: MembershipResignation = MembershipResignationFactory.create()
ShareOwnershipFactory.create(share_owner=resignation.share_owner)

response = self.client.post(
reverse("coop:resign_member_remove", args=[resignation.id]),
follow=True,
)
self.assertStatusCode(response, HTTPStatus.OK)
self.assertEqual(MembershipResignation.objects.all().count(), 0)
for shareownership in ShareOwnership.objects.filter(
share_owner=resignation.share_owner
):
self.assertEqual(shareownership.end_date, None)
ic(response)
self.assertRedirects(response, reverse("coop:resigned_members_list"))
self.assertEqual(1, MembershipResignationUpdateLogEntry.objects.count())
log_entry = MembershipResignationUpdateLogEntry.objects.get()
created_resignation = MembershipResignation.objects.get()
self.assertEqual(created_resignation.id, int(log_entry.values["id"]))
self.assertEqual(actor, log_entry.actor)

self.fail(
"No corresponding log entry class, see "
"TestMembershipResignationEditView.test_membershipResignationEditView_default_logEntryCreated "
"for an example on how to test log entries"
)
self.assertEqual(MembershipResignationDeleteLogEntry.objects.count(), 1)
log_entry = MembershipResignationDeleteLogEntry.objects.get()
# self.assertEqual(resignation.id, log_entry.actor.id)
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(actor, log_entry.actor)
8 changes: 2 additions & 6 deletions tapir/coop/tests/membership_resignation/test_edit_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from http import HTTPStatus
from icecream import ic

from django.urls import reverse

Expand Down Expand Up @@ -70,10 +69,8 @@ def test_membershipResignationEditView_default_logEntryCreated(self):

self.assertEqual(1, MembershipResignationUpdateLogEntry.objects.count())
log_entry = MembershipResignationUpdateLogEntry.objects.get()
created_resignation = MembershipResignation.objects.get()
ic(log_entry.__dict__)
ic(created_resignation.__dict__)
self.assertEqual(created_resignation.id, log_entry.actor_id)
# created_resignation = MembershipResignation.objects.get()
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
# self.assertEqual(created_resignation.id, log_entry.actor.id)
self.assertEqual(actor, log_entry.actor)

def test_membershipResignationEditView_default_cantChangeBaseFields(self):
Expand Down Expand Up @@ -111,7 +108,6 @@ def test_membershipResignationEditView_cancellationDateUpdate_payOutDayUpdated(
resignation_type=MembershipResignation.ResignationType.BUY_BACK,
cancellation_date=datetime.date(year=2020, month=6, day=20),
)
ic(resignation.__dict__)
self.assertEqual(
datetime.date(year=2023, month=12, day=31), resignation.pay_out_day
)
Expand Down
14 changes: 8 additions & 6 deletions tapir/coop/tests/membership_resignation/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def setUp(self) -> None:
self.given_feature_flag_value(feature_flag_membership_resignation, True)
mock_timezone_now(self, self.NOW)

def test_membershipResignationForm_is_valid(self):
def test_isValid_sendingValidData_returnsTrue(self):
share_owner = ShareOwnerFactory.create()
resignation = MembershipResignationFactory.create()
data = {
"share_owner": share_owner,
"cancellation_reason": resignation.cancellation_reason,
"cancellation_reason": "A test reason.",
"cancellation_date": resignation.cancellation_date,
"resignation_type": resignation.resignation_type,
"transferring_shares_to": resignation.transferring_shares_to,
Expand All @@ -40,7 +40,7 @@ def test_membershipResignationForm_is_valid(self):
form = MembershipResignationForm(data=data)
self.assertTrue(form.is_valid())

def test_validate_share_owner(self):
def test_validate_share_owner_duplicateErrors_isThrown(self):
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
share_owner = ShareOwnerFactory.create()
resignation = MembershipResignationFactory.create(share_owner=share_owner)
form = MembershipResignationForm(data={"share_owner": resignation.share_owner})
Expand All @@ -51,7 +51,7 @@ def test_validate_share_owner(self):
form.errors["share_owner"],
)

def test_validate_transfer_choice(self):
def test_validate_transfer_choice_notChosenError_isThrown(self):
share_owner = ShareOwnerFactory.create()
resignation = MembershipResignationFactory.create(
kerstenkenan marked this conversation as resolved.
Show resolved Hide resolved
share_owner=share_owner,
Expand Down Expand Up @@ -83,7 +83,9 @@ def test_validate_transfer_choice(self):
form.errors["transferring_shares_to"],
)

def test_validate_duplicates(self):
def test_validate_duplicates_errorShareownerAndTransferringSharesToDuplicate_isThrown(
self,
):
share_owner = ShareOwnerFactory.create()
resignation = MembershipResignationFactory.create(
share_owner=share_owner, transferring_shares_to=share_owner
Expand All @@ -104,7 +106,7 @@ def test_validate_duplicates(self):
form.errors["transferring_shares_to"],
)

def test_validate_if_gifted(self):
def test_validate_if_gifted_paidOutError_isThrown(self):
share_owner = ShareOwnerFactory.create()
resignation = MembershipResignationFactory.create(
share_owner=share_owner,
Expand Down
Loading
Loading