Fakultas Ilmu Komputer UI

Commit 5d65973f authored by Dave Nathanael's avatar Dave Nathanael
Browse files

Merge branch 'dave/fix-case-recap-endpoint' into 'staging'

Add query param to include Positive cases on InvestigationCase list endpoint

See merge request !48
parents 4af8c772 a1311b23
Pipeline #46172 passed with stages
in 22 minutes and 16 seconds
......@@ -65,7 +65,7 @@ class AccountViewSet(viewsets.ModelViewSet):
if User.objects.filter(username=username).exists():
return Response(
{"username" : ["User with that username already exists."]},
{"username": ["User with that username already exists."]},
status=status.HTTP_409_CONFLICT
)
......
......@@ -111,6 +111,24 @@ class InvestigationCaseViewTest(APITestCase):
self.assertIn(str(self.reference_case.case_subject.id), response_string)
self.assertIn(str(self.reference_case.author.id), response_string)
def test_list_all_investigation_cases_success(self):
url = self.BASE_URL + "?include_positive=true"
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_string = response.rendered_content.decode("utf-8")
self.assertIn('"count":2', response_string)
self.assertIn('"next":null', response_string)
self.assertIn('"previous":null', response_string)
self.assertIn(str(self.case.id), response_string)
self.assertIn(str(self.case.case_subject.id), response_string)
self.assertIn(str(self.case.author.id), response_string)
self.assertIn(str(self.reference_case.id), response_string)
self.assertIn(str(self.reference_case.case_subject.id), response_string)
self.assertIn(str(self.reference_case.author.id), response_string)
def test_retrieve_investigation_case_fails_on_deleted_subject(self):
url = self.BASE_URL + str(self.other_deleted_case.id) + "/"
......
......@@ -68,6 +68,9 @@ class InvestigationCaseViewSet(viewsets.ModelViewSet):
def get_queryset(self):
if self.action == 'list':
query_include_positive = self.request.query_params.get('include_positive', None)
if query_include_positive is not None:
return self.queryset
return self.queryset.filter(Q(outcome__isnull=True) | Q(outcome__icontains="-"))
return self.queryset
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment