From c5890ea0cc10dd6c2fa45ebc0ccdada63b2a4aa7 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Thu, 6 Dec 2018 18:03:43 -0500 Subject: [PATCH] Add playbook filtering by status This allows to search playbook by status (running, failed, completed, etc.) Change-Id: I05bba5611bb1f18e48791d570575b6f57c5862d9 --- ara/api/tests/tests_playbook.py | 7 +++++++ ara/api/views.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ara/api/tests/tests_playbook.py b/ara/api/tests/tests_playbook.py index e800398..d777fc3 100644 --- a/ara/api/tests/tests_playbook.py +++ b/ara/api/tests/tests_playbook.py @@ -121,6 +121,13 @@ class PlaybookTestCase(APITestCase): self.assertEqual(1, len(request.data["results"])) self.assertEqual(playbook.name, request.data["results"][0]["name"]) + def test_get_playbook_by_status(self): + playbook = factories.PlaybookFactory(status="failed") + factories.PlaybookFactory(status="completed") + request = self.client.get("/api/v1/playbooks?status=failed") + self.assertEqual(1, len(request.data["results"])) + self.assertEqual(playbook.status, request.data["results"][0]["status"]) + def test_get_playbook_duration(self): started = timezone.now() ended = started + datetime.timedelta(hours=1) diff --git a/ara/api/views.py b/ara/api/views.py index 40d9b0e..64156cc 100644 --- a/ara/api/views.py +++ b/ara/api/views.py @@ -29,7 +29,7 @@ class LabelViewSet(viewsets.ModelViewSet): class PlaybookViewSet(viewsets.ModelViewSet): queryset = models.Playbook.objects.all() serializer_class = serializers.PlaybookSerializer - filter_fields = ("name",) + filter_fields = ("name", "status") class PlaybookFilesDetail(NestedViewSetMixin, viewsets.ModelViewSet):