-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filter for expired and upcoming events (#714)
* Added filter for expired and upcoming events * Removed registration filter on event has ended * Added manual filtering for expired events in user viewset * Removed unused import * Started testing expired event method * Finished testing filter methode * format * removed incorrect True comparison * Updated changlog * Added tests where query params give false * Used CaseInsensitiveBooleanQueryParam for handling all types of query params + removed comments * Fixed typo * Formatting --------- Co-authored-by: Harry Linrui XU <[email protected]> Co-authored-by: haruixu <[email protected]>
- Loading branch information
1 parent
c2d8f44
commit 9d09af3
Showing
3 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
from django.utils.text import slugify | ||
from rest_framework import status | ||
|
||
import pytest | ||
|
||
from app.common.enums import AdminGroup, GroupType | ||
from app.content.factories.event_factory import EventFactory | ||
from app.content.factories.registration_factory import RegistrationFactory | ||
from app.content.factories.strike_factory import StrikeFactory | ||
from app.content.factories.user_factory import UserFactory | ||
|
@@ -32,6 +36,10 @@ def _get_user_detail_url(user): | |
return f"{API_USER_BASE_URL}{user.user_id}/" | ||
|
||
|
||
def _get_user_events_url(): | ||
return f"{API_USER_BASE_URL}me/events/" | ||
|
||
|
||
def _get_user_post_data(): | ||
return { | ||
"email": "[email protected]", | ||
|
@@ -469,3 +477,93 @@ def test_destroy_other_user_as_index_user(member, user, api_client): | |
response = client.delete(url) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_expired_user_events(member, api_client): | ||
""" "All the events listed as expired should be expired""" | ||
client = api_client(user=member) | ||
|
||
two_days_ago = timezone.now() - timedelta(days=2) | ||
event = EventFactory(end_date=two_days_ago) | ||
|
||
registration = RegistrationFactory(user=member, event=event) | ||
|
||
url = _get_user_events_url() | ||
|
||
query_params = {"expired": "true"} | ||
|
||
response = client.get(url, data=query_params) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
|
||
registrations = response.json().get("results") | ||
for registration in registrations: | ||
assert registration.get("expired") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_unexpired_user_events(member, api_client): | ||
"""All the events listed as unexpired should be unexpired""" | ||
client = api_client(user=member) | ||
|
||
two_days_ago = timezone.now() - timedelta(days=2) | ||
event = EventFactory(end_date=two_days_ago) | ||
|
||
registration = RegistrationFactory(user=member, event=event) | ||
|
||
url = _get_user_events_url() | ||
|
||
query_params = {"expired": "false"} | ||
|
||
response = client.get(url, data=query_params) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
|
||
registrations = response.json().get("results") | ||
for registration in registrations: | ||
assert not registration.get("expired") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_expired_user_events_with_a_blank_query_params(member, api_client): | ||
"""All the events listed should be unexpired when returning a blank query params""" | ||
client = api_client(user=member) | ||
|
||
two_days_ago = timezone.now() - timedelta(days=2) | ||
event = EventFactory(end_date=two_days_ago) | ||
|
||
registration = RegistrationFactory(user=member, event=event) | ||
|
||
url = _get_user_events_url() | ||
|
||
query_params = {"expired": ""} | ||
|
||
response = client.get(url, data=query_params) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
|
||
registrations = response.json().get("results") | ||
for registration in registrations: | ||
assert not registration.get("expired") | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_list_expired_user_events_with_no_query_params(member, api_client): | ||
"""All the events listed should be unexpired with no query params""" | ||
client = api_client(user=member) | ||
|
||
two_days_ago = timezone.now() - timedelta(days=2) | ||
event = EventFactory(end_date=two_days_ago) | ||
|
||
registration = RegistrationFactory(user=member, event=event) | ||
|
||
url = _get_user_events_url() | ||
|
||
response = client.get(url) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
|
||
registrations = response.json().get("results") | ||
for registration in registrations: | ||
assert not registration.get("expired") |