Skip to content

Commit afe4038

Browse files
committed
Fix tests
1 parent 49cabf4 commit afe4038

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

myhpi/core/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def __str__(self):
3333
def get_full_name(self):
3434
return self.display_name
3535

36+
@staticmethod
37+
def for_user(u):
38+
return UserProfile.objects.get(user=u)
39+
3640

3741
from django.db.models.signals import post_save
3842
from django.dispatch import receiver
@@ -41,10 +45,10 @@ def get_full_name(self):
4145
@receiver(post_save, sender=User)
4246
def post_user_save(sender, instance, created, **kwargs):
4347
display_name = instance.first_name + " " + instance.last_name
44-
user_profile = UserProfile.objects.get(user=instance.pk)
48+
user_profile = UserProfile.objects.filter(user=instance.pk)
4549
if user_profile:
46-
user_profile.display_name = display_name
47-
user_profile.save()
50+
user_profile[0].display_name = display_name
51+
user_profile[0].save()
4852
else:
4953
UserProfile.objects.create(user=instance, display_name=display_name)
5054

myhpi/tests/core/setup.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
MinutesList,
1111
RootPage,
1212
SecondLevelMenuItem,
13+
UserProfile,
1314
)
1415

1516

@@ -171,9 +172,9 @@ def setup_minutes(group, students_group, parent, user):
171172
date="2022-01-01",
172173
is_public=False,
173174
visible_for=[students_group, group],
174-
moderator=user,
175-
author=user,
176-
participants=[user],
175+
moderator=UserProfile.for_user(user),
176+
author=UserProfile.for_user(user),
177+
participants=[UserProfile.for_user(user)],
177178
body="These are the first minutes.",
178179
slug="first-minutes",
179180
),
@@ -182,9 +183,9 @@ def setup_minutes(group, students_group, parent, user):
182183
date="2022-02-02",
183184
is_public=False,
184185
visible_for=[students_group, group],
185-
moderator=user,
186-
author=user,
187-
participants=[user],
186+
moderator=UserProfile.for_user(user),
187+
author=UserProfile.for_user(user),
188+
participants=[UserProfile.for_user(user)],
188189
body="These are the second minutes.",
189190
slug="second-minutes",
190191
),
@@ -193,9 +194,9 @@ def setup_minutes(group, students_group, parent, user):
193194
date="2022-03-03",
194195
is_public=False,
195196
visible_for=[group],
196-
moderator=user,
197-
author=user,
198-
participants=[user],
197+
moderator=UserProfile.for_user(user),
198+
author=UserProfile.for_user(user),
199+
participants=[UserProfile.for_user(user)],
199200
body="These minutes are private.",
200201
slug="private-minutes",
201202
),
@@ -205,9 +206,9 @@ def setup_minutes(group, students_group, parent, user):
205206
is_public=False,
206207
live=False,
207208
visible_for=[group],
208-
moderator=user,
209-
author=user,
210-
participants=[user],
209+
moderator=UserProfile.for_user(user),
210+
author=UserProfile.for_user(user),
211+
participants=[UserProfile.for_user(user)],
211212
body="These minutes are unpublished.",
212213
slug="unpublished-minutes",
213214
),
@@ -216,9 +217,9 @@ def setup_minutes(group, students_group, parent, user):
216217
date="2022-05-05",
217218
is_public=False,
218219
visible_for=[students_group, group],
219-
moderator=user,
220-
author=user,
221-
participants=[user],
220+
moderator=UserProfile.for_user(user),
221+
author=UserProfile.for_user(user),
222+
participants=[UserProfile.for_user(user)],
222223
body="These minutes are the most recent.",
223224
slug="recent-minutes",
224225
),

0 commit comments

Comments
 (0)