Skip to content

Commit

Permalink
fix: sequence filter if client doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Muchogoc committed Feb 15, 2023
1 parent 5c85b20 commit 956a297
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mycarehub/content/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import django_filters
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, Q
from django.utils import timezone
from rest_framework.filters import BaseFilterBackend
Expand Down Expand Up @@ -92,7 +93,11 @@ def filter_queryset(self, request, queryset, view):
client_id = query_params.get("client_id", "")

if client_id and queryset.model is ContentItem:
client = Client.objects.get(id=client_id)
try:
client = Client.objects.get(id=client_id)
except ObjectDoesNotExist:
return queryset

program = client.program

if program.content_sequence == ContentSequence.GRADUAL:
Expand Down
19 changes: 19 additions & 0 deletions mycarehub/content/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

import pytest
from django.urls import reverse
from model_bakery import baker
Expand Down Expand Up @@ -202,6 +204,23 @@ def test_content_sequence_filter_instant(
assert response_data["meta"]["total_count"] == 1


def test_content_sequence_filter_invalid_client(
content_item_with_tag_and_category, request_with_user, client, program
):
program.content_sequence = ContentSequence.INSTANT
program.save()

client.force_login(request_with_user.user)
url = (
reverse("wagtailapi:pages:listing")
+ f"?type=content.ContentItem&fields=*&client_id={uuid.uuid4()}"
)
response = client.get(url)
assert response.status_code == status.HTTP_200_OK
response_data = response.json()
assert response_data["meta"]["total_count"] == 0


def test_content_facility_filter(
content_item_with_tag_and_category, request_with_user, client, facility
):
Expand Down

0 comments on commit 956a297

Please sign in to comment.