mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
fix: wrong logic in Club.delete()
This commit is contained in:
parent
ae1fcdb8c0
commit
75bb3f992c
@ -207,11 +207,11 @@ class Club(models.Model):
|
|||||||
cache.set(f"sith_club_{self.unix_name}", self)
|
cache.set(f"sith_club_{self.unix_name}", self)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
super().delete(*args, **kwargs)
|
|
||||||
# Invalidate the cache of this club and of its memberships
|
# Invalidate the cache of this club and of its memberships
|
||||||
for membership in self.members.ongoing().select_related("user"):
|
for membership in self.members.ongoing().select_related("user"):
|
||||||
cache.delete(f"membership_{self.id}_{membership.user.id}")
|
cache.delete(f"membership_{self.id}_{membership.user.id}")
|
||||||
cache.delete(f"sith_club_{self.unix_name}")
|
cache.delete(f"sith_club_{self.unix_name}")
|
||||||
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -46,6 +46,8 @@ class ClubTest(TestCase):
|
|||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
# subscribed users - initial members
|
# subscribed users - initial members
|
||||||
cls.skia = User.objects.get(username="skia")
|
cls.skia = User.objects.get(username="skia")
|
||||||
|
# by default, Skia is in the AE, which creates side effect
|
||||||
|
cls.skia.memberships.all().delete()
|
||||||
cls.richard = User.objects.get(username="rbatsbak")
|
cls.richard = User.objects.get(username="rbatsbak")
|
||||||
cls.comptable = User.objects.get(username="comptable")
|
cls.comptable = User.objects.get(username="comptable")
|
||||||
cls.sli = User.objects.get(username="sli")
|
cls.sli = User.objects.get(username="sli")
|
||||||
@ -62,38 +64,34 @@ class ClubTest(TestCase):
|
|||||||
cls.public = User.objects.get(username="public")
|
cls.public = User.objects.get(username="public")
|
||||||
|
|
||||||
cls.ae = Club.objects.filter(pk=SITH_MAIN_CLUB_ID)[0]
|
cls.ae = Club.objects.filter(pk=SITH_MAIN_CLUB_ID)[0]
|
||||||
|
cls.club = Club.objects.create(
|
||||||
def setUp(self):
|
|
||||||
# by default, Skia is in the AE, which creates side effect
|
|
||||||
self.skia.memberships.all().delete()
|
|
||||||
|
|
||||||
# create a fake club
|
|
||||||
self.club = Club.objects.create(
|
|
||||||
name="Fake Club",
|
name="Fake Club",
|
||||||
unix_name="fake-club",
|
unix_name="fake-club",
|
||||||
address="5 rue de la République, 90000 Belfort",
|
address="5 rue de la République, 90000 Belfort",
|
||||||
)
|
)
|
||||||
self.members_url = reverse(
|
cls.members_url = reverse(
|
||||||
"club:club_members", kwargs={"club_id": self.club.id}
|
"club:club_members", kwargs={"club_id": cls.club.id}
|
||||||
)
|
)
|
||||||
a_month_ago = now() - timedelta(days=30)
|
a_month_ago = now() - timedelta(days=30)
|
||||||
yesterday = now() - timedelta(days=1)
|
yesterday = now() - timedelta(days=1)
|
||||||
Membership.objects.create(
|
Membership.objects.create(
|
||||||
club=self.club, user=self.skia, start_date=a_month_ago, role=3
|
club=cls.club, user=cls.skia, start_date=a_month_ago, role=3
|
||||||
)
|
)
|
||||||
Membership.objects.create(club=self.club, user=self.richard, role=1)
|
Membership.objects.create(club=cls.club, user=cls.richard, role=1)
|
||||||
Membership.objects.create(
|
Membership.objects.create(
|
||||||
club=self.club, user=self.comptable, start_date=a_month_ago, role=10
|
club=cls.club, user=cls.comptable, start_date=a_month_ago, role=10
|
||||||
)
|
)
|
||||||
|
|
||||||
# sli was a member but isn't anymore
|
# sli was a member but isn't anymore
|
||||||
Membership.objects.create(
|
Membership.objects.create(
|
||||||
club=self.club,
|
club=cls.club,
|
||||||
user=self.sli,
|
user=cls.sli,
|
||||||
start_date=a_month_ago,
|
start_date=a_month_ago,
|
||||||
end_date=yesterday,
|
end_date=yesterday,
|
||||||
role=2,
|
role=2,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
cache.clear()
|
cache.clear()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user