Skip to content

Commit

Permalink
Fixed migration conflict after merge,
Browse files Browse the repository at this point in the history
Improved view names,
Cleanup in test_create_view.py
Removed test_create_membershipresignation.py that contains only duplicates of test_create_view.py
  • Loading branch information
Theophile-Madet committed Nov 18, 2024
1 parent 33aeb80 commit 5bdafb4
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

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

Expand Down
2 changes: 1 addition & 1 deletion tapir/coop/templates/coop/membership_resignation_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h5>{% translate "List of resigned members" %} ({{ total_of_resigned_members }})
{% endfor %}
</div>
<a class="{% tapir_button_link_to_action %}"
href="{% url 'coop:resign_new_membership' %}">
href="{% url 'coop:membership_resignation_create' %}">
<span class="material-icons">add_circle_outline</span>
{% translate "Resign new member" %}
</a>
Expand Down
4 changes: 2 additions & 2 deletions tapir/coop/templates/coop/membershipresignation_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h5 class="modal-title">Attention!</h5>
<h5 class="card-header">
{% translate "Resigned member" %}: {% get_display_name_for_viewer object.share_owner request.user %}
</h5>
<div class="card-body" id="resignedmember_detail_card">
<div class="card-body">
<div class="row m-1">
<div class="col-3 fw-bold text-end">{% translate "Share owner" %}:</div>
<div class="col-9" id="membership_resignation_share_owner">
Expand Down Expand Up @@ -92,7 +92,7 @@ <h5 class="card-header">
<span class="material-icons">mood</span>Reactivate
</span>
<a class="{% tapir_button_link_to_action %}"
href="{% url 'coop:resign_member_edit' object.pk %}">
href="{% url 'coop:membership_resignation_edit' object.pk %}">
<span class="material-icons">edit</span>
{% translate "Edit" %}
</a>
Expand Down
100 changes: 51 additions & 49 deletions tapir/coop/tests/membership_resignation/test_create_view.py
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 All @@ -16,12 +15,12 @@
from tapir.coop.models import (
MembershipResignation,
MembershipResignationCreateLogEntry,
TapirUser,
ShareOwner,
)
from tapir.coop.services.MembershipResignationService import (
MembershipResignationService,
)
from tapir.coop.tests.factories import ShareOwnerFactory, MembershipResignationFactory
from tapir.coop.tests.factories import ShareOwnerFactory
from tapir.utils.tests_utils import (
FeatureFlagTestMixin,
TapirFactoryTestBase,
Expand All @@ -43,36 +42,42 @@ def setUp(self) -> None:

def test_membershipResignationCreateView_loggedInAsNormalUser_accessDenied(self):
self.login_as_normal_user()
response = self.client.get(reverse("coop:resign_new_membership"))
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

def test_membershipResignationCreateView_loggedInAsMemberOffice_accessGranted(self):
self.login_as_member_office_user()
response = self.client.get(reverse("coop:resign_new_membership"))
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.OK)

def test_membershipResignationCreateView_featureFlagDisabled_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, False)
self.login_as_member_office_user()
response = self.client.get(reverse("coop:resign_new_membership"))
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

def create_default_resignation(self):
share_owner = ShareOwnerFactory.create()
actor = self.login_as_member_office_user()
def call_resignation_create_view(
self,
resignation_type: MembershipResignation.ResignationType,
transferring_shares_to: ShareOwner | None = None,
):
resigning_member = ShareOwnerFactory.create()
data = {
"share_owner": resigning_member.id,
"cancellation_reason": "Test resignation",
"cancellation_date": self.TODAY,
"resignation_type": resignation_type,
}
if transferring_shares_to:
data["transferring_shares_to"] = transferring_shares_to.id

response = self.client.post(
reverse("coop:resign_new_membership"),
data={
"share_owner": share_owner.id,
"cancellation_reason": "Test resignation",
"cancellation_date": self.TODAY,
"resignation_type": MembershipResignation.ResignationType.GIFT_TO_COOP,
},
reverse("coop:membership_resignation_create"),
data=data,
follow=True,
)
self.assertStatusCode(response, HTTPStatus.OK)
resignation = MembershipResignation.objects.last()
return resignation, actor
return MembershipResignation.objects.get()

@patch.object(MembershipResignationService, "delete_shareowner_membershippauses")
@patch.object(
Expand All @@ -83,15 +88,21 @@ def test_membershipResignationCreateView_default_changesApplied(
mock_update_shifts_and_shares_and_pay_out_day: Mock,
mock_delete_shareowner_membershippauses: Mock,
):
resignation, _ = self.create_default_resignation()
self.login_as_member_office_user()
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)
self.assertEqual(1, MembershipResignation.objects.count())
mock_delete_shareowner_membershippauses.assert_called_once_with(resignation)
mock_update_shifts_and_shares_and_pay_out_day.assert_called_once_with(
resignation=resignation
)

def test_membershipResignationCreateView_default_logEntryCreated(self):
_, actor = self.create_default_resignation()
actor = self.login_as_member_office_user()
self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)

self.assertEqual(1, MembershipResignationCreateLogEntry.objects.count())
log_entry = MembershipResignationCreateLogEntry.objects.get()
Expand All @@ -100,7 +111,10 @@ def test_membershipResignationCreateView_default_logEntryCreated(self):
self.assertEqual(actor, log_entry.actor)

def test_membershipResignationCreateView_default_correctMailSent(self):
member_to_resign, _ = self.create_default_resignation()
self.login_as_member_office_user()
member_to_resign = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)

self.assertEqual(1, len(mail.outbox))
sent_mail = mail.outbox[0]
Expand All @@ -113,27 +127,20 @@ def test_membershipResignationCreateView_default_correctMailSent(self):
def test_membershipResignationCreateView_sharesTransferred_shareRecipientAlsoReceivesMails(
self,
):
member_to_resign = ShareOwnerFactory.create()
self.login_as_member_office_user()
member_that_receives_shares = ShareOwnerFactory.create()
self.login_as_member_office_user()
response = self.client.post(
reverse("coop:resign_new_membership"),
data={
"share_owner": member_to_resign.id,
"cancellation_reason": "Test resignation",
"cancellation_date": self.TODAY,
"resignation_type": MembershipResignation.ResignationType.TRANSFER,
"transferring_shares_to": member_that_receives_shares.id,
},
follow=True,
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.TRANSFER,
member_that_receives_shares,
)
self.assertStatusCode(response, HTTPStatus.OK)
member_that_gifts_shares = resignation.share_owner

self.assertEqual(2, len(mail.outbox))
mail_to_resigned_member = mail.outbox[0]
self.assertEmailOfClass_GotSentTo(
MembershipResignationConfirmation,
member_to_resign.email,
member_that_gifts_shares.email,
mail_to_resigned_member,
)
mail_to_receiving_member = mail.outbox[1]
Expand All @@ -143,29 +150,24 @@ def test_membershipResignationCreateView_sharesTransferred_shareRecipientAlsoRec
mail_to_receiving_member,
)

def test_membershipResignationCreateView_default_payOutDayIsSetCorrectly(self):
member_to_resign, _ = self.create_default_resignation()
def test_membershipResignationCreateView_resignationTypeGiftToCoop_payOutDayIsSetCorrectly(
self,
):
self.login_as_member_office_user()
member_to_resign = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)

self.assertEqual(self.TODAY, member_to_resign.pay_out_day)

def test_membershipResignationCreateView_resignationTypeBuyBack_payOutDayIsSetCorrectly(
self,
):
self.login_as_member_office_user()
share_owner = ShareOwnerFactory.create()
response = self.client.post(
reverse("coop:resign_new_membership"),
data={
"share_owner": share_owner.id,
"cancellation_reason": "Test resignation",
"cancellation_date": self.TODAY,
"resignation_type": MembershipResignation.ResignationType.BUY_BACK,
},
follow=True,
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.BUY_BACK
)
self.assertStatusCode(response, HTTPStatus.OK)
member_to_resign = MembershipResignation.objects.last()
self.assertEqual(
datetime.date(year=2027, month=12, day=31),
member_to_resign.pay_out_day,
resignation.pay_out_day,
)
6 changes: 3 additions & 3 deletions tapir/coop/tests/membership_resignation/test_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_membershipResignationDetailView_loggedInAsNormalUser_accessDenied(self)
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resignedmember_detail", args=[resignation.id])
reverse("coop:membership_resignation_detail", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
Expand All @@ -27,7 +27,7 @@ def test_membershipResignationDetailView_loggedInAsMemberOffice_accessGranted(se
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resignedmember_detail", args=[resignation.id])
reverse("coop:membership_resignation_detail", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.OK)
Expand All @@ -38,7 +38,7 @@ def test_membershipResignationDetailView_featureFlagDisabled_accessDenied(self):
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resignedmember_detail", args=[resignation.id])
reverse("coop:membership_resignation_detail", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
12 changes: 6 additions & 6 deletions tapir/coop/tests/membership_resignation/test_edit_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_membershipResignationEditView_loggedInAsNormalUser_accessDenied(self):
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resign_member_edit", args=[resignation.id])
reverse("coop:membership_resignation_edit", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
Expand All @@ -38,7 +38,7 @@ def test_membershipResignationEditView_loggedInAsMemberOffice_accessGranted(self
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resign_member_edit", args=[resignation.id])
reverse("coop:membership_resignation_edit", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.OK)
Expand All @@ -49,7 +49,7 @@ def test_membershipResignationEditView_featureFlagDisabled_accessDenied(self):
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:resign_member_edit", args=[resignation.id])
reverse("coop:membership_resignation_edit", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
Expand All @@ -59,7 +59,7 @@ def test_membershipResignationEditView_default_logEntryCreated(self):
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.post(
reverse("coop:resign_member_edit", args=[resignation.id]),
reverse("coop:membership_resignation_edit", args=[resignation.id]),
data={
"cancellation_reason": "Reason after edit",
"cancellation_date": self.TODAY,
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_membershipResignationEditView_default_cantChangeBaseFields(self):
new_recipient = ShareOwnerFactory.create()

response = self.client.post(
reverse("coop:resign_member_edit", args=[resignation.id]),
reverse("coop:membership_resignation_edit", args=[resignation.id]),
data={
"share_owner": new_resigned_member.id,
"transferring_shares_to": new_recipient.id,
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_membershipResignationEditView_cancellationDateUpdate_payOutDayUpdated(
datetime.date(year=2023, month=12, day=31), resignation.pay_out_day
)
response = self.client.post(
reverse("coop:resign_member_edit", args=[resignation.id]),
reverse("coop:membership_resignation_edit", args=[resignation.id]),
data={
"cancellation_reason": "Test for updated object via post-client.",
"cancellation_date": datetime.date(year=2022, month=7, day=30),
Expand Down
38 changes: 0 additions & 38 deletions tapir/coop/tests/test_create_membershipresignation.py

This file was deleted.

16 changes: 8 additions & 8 deletions tapir/coop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@
name="share_create_multiple",
),
path(
"resign_member/new",
"membership_resignation/new",
views.MembershipResignationCreateView.as_view(),
name="resign_new_membership",
name="membership_resignation_create",
),
path(
"resign_member/edit/<int:pk>",
"membership_resignation/<int:pk>/edit",
views.MembershipResignationEditView.as_view(),
name="resign_member_edit",
name="membership_resignation_edit",
),
path(
"resign_member/<int:pk>/detail",
"membership_resignation/<int:pk>/detail",
views.MembershipResignationDetailView.as_view(),
name="resignedmember_detail",
name="membership_resignation_detail",
),
path(
"resign_member/<int:pk>/delete",
"membership_resignation/<int:pk>/delete",
views.MembershipResignationRemoveFromListView.as_view(),
name="resign_member_remove",
),
path(
"resigned_members_list",
"membership_resignation_list",
views.MembershipResignationList.as_view(),
name="resigned_members_list",
),
Expand Down
2 changes: 1 addition & 1 deletion tapir/coop/views/membership_resignation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def render_paid_out(self, record: MembershipResignation):
def render_add_buttons(self, value, record: MembershipResignation):
return format_html(
"<a href='{}' class='{}'>{}</a>",
reverse_lazy("coop:resignedmember_detail", args=[record.pk]),
reverse_lazy("coop:membership_resignation_detail", args=[record.pk]),
tapir_button_link_to_action(),
format_html("<span class='material-icons'>edit</span>"),
)
Expand Down

0 comments on commit 5bdafb4

Please sign in to comment.