Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth committed Nov 21, 2023
1 parent 49cabf4 commit 0e90a69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
10 changes: 7 additions & 3 deletions myhpi/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def __str__(self):
def get_full_name(self):
return self.display_name

@staticmethod
def for_user(u):
return UserProfile.objects.get(user=u)


from django.db.models.signals import post_save
from django.dispatch import receiver
Expand All @@ -41,10 +45,10 @@ def get_full_name(self):
@receiver(post_save, sender=User)
def post_user_save(sender, instance, created, **kwargs):
display_name = instance.first_name + " " + instance.last_name
user_profile = UserProfile.objects.get(user=instance.pk)
user_profile = UserProfile.objects.filter(user=instance.pk)
if user_profile:
user_profile.display_name = display_name
user_profile.save()
user_profile[0].display_name = display_name
user_profile[0].save()
else:
UserProfile.objects.create(user=instance, display_name=display_name)

Expand Down
25 changes: 13 additions & 12 deletions myhpi/tests/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MinutesList,
RootPage,
SecondLevelMenuItem,
UserProfile,
)


Expand Down Expand Up @@ -171,9 +172,9 @@ def setup_minutes(group, students_group, parent, user):
date="2022-01-01",
is_public=False,
visible_for=[students_group, group],
moderator=user,
author=user,
participants=[user],
moderator=UserProfile.for_user(user),
author=UserProfile.for_user(user),
participants=[UserProfile.for_user(user)],
body="These are the first minutes.",
slug="first-minutes",
),
Expand All @@ -193,9 +194,9 @@ def setup_minutes(group, students_group, parent, user):
date="2022-03-03",
is_public=False,
visible_for=[group],
moderator=user,
author=user,
participants=[user],
moderator=UserProfile.for_user(user),
author=UserProfile.for_user(user),
participants=[UserProfile.for_user(user)],
body="These minutes are private.",
slug="private-minutes",
),
Expand All @@ -205,9 +206,9 @@ def setup_minutes(group, students_group, parent, user):
is_public=False,
live=False,
visible_for=[group],
moderator=user,
author=user,
participants=[user],
moderator=UserProfile.for_user(user),
author=UserProfile.for_user(user),
participants=[UserProfile.for_user(user)],
body="These minutes are unpublished.",
slug="unpublished-minutes",
),
Expand All @@ -216,9 +217,9 @@ def setup_minutes(group, students_group, parent, user):
date="2022-05-05",
is_public=False,
visible_for=[students_group, group],
moderator=user,
author=user,
participants=[user],
moderator=UserProfile.for_user(user),
author=UserProfile.for_user(user),
participants=[UserProfile.for_user(user)],
body="These minutes are the most recent.",
slug="recent-minutes",
),
Expand Down

0 comments on commit 0e90a69

Please sign in to comment.