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

fixed issue expired events #743

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions app/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Groups(ChoiceEnum):
JUBKOM = "JubKom"
REDAKSJONEN = "Redaksjonen"
FONDET = "Forvaltningsgruppen"
PLASK = "Plask"


class AppModel(ChoiceEnum):
Expand Down
12 changes: 7 additions & 5 deletions app/content/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ def _list_queryset(self):
if activity and category:
return self._list_activity_queryset(category, expired, time)

if (
expired and
category and
not activity
):
return self.queryset.filter(end_date__lt=time).filter(~Q(category=category))

if expired:
return self.queryset.filter(end_date__lt=time).order_by("-start_date")

if category:
return self.queryset.filter(end_date__gte=time).filter(
~Q(category=category)
)

return self.queryset.filter(end_date__gte=time)

def _list_activity_queryset(self, category, expired, time):
Expand Down
6 changes: 6 additions & 0 deletions app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def jubkom_member(member):
return member


@pytest.fixture()
def plask_member(member):
add_user_to_group_with_name(member, Groups.PLASK)
return member


@pytest.fixture()
def member_client(member):
return get_api_client(user=member)
Expand Down
30 changes: 22 additions & 8 deletions app/tests/content/test_event_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ def test_list_as_anonymous_user(default_client, event):
"""An anonymous user should be able to list all events that are not activities."""

category = Category.objects.create(text="Aktivitet")
activity = EventFactory(category=category)

activity.category = category
activity.save()
EventFactory(category=category)

event.category = None
event.save()
Expand All @@ -192,10 +189,7 @@ def test_list_activities_as_anonymous_user(default_client, event):
"""An anonymous user should be able to list all activities."""

category = Category.objects.create(text="Aktivitet")
activity = EventFactory(category=category)

activity.category = category
activity.save()
EventFactory(category=category)

event.category = None
event.save()
Expand All @@ -206,6 +200,26 @@ def test_list_activities_as_anonymous_user(default_client, event):
assert response.json().get("count") == 1


@pytest.mark.django_db
def test_list_expired_events_as_anonymous_user(default_client, event):
"""
An anonymous user should be able to list all expired events.
Activites should not be included.
"""

two_days_ago = now() - timedelta(days=1)
event.end_date = two_days_ago
event.save()

category = Category.objects.create(text="Aktivitet")
EventFactory(end_date=two_days_ago, category=category)

response = default_client.get(f"{API_EVENTS_BASE_URL}?expired=true")

assert response.status_code == 200
assert response.json().get("count") == 1


@pytest.mark.django_db
def test_retrieve_as_anonymous_user(default_client, event):
"""An anonymous user should be able to retrieve an event."""
Expand Down
Loading