api: allow searching for ignore_errors in task results
This is relevant when searching failed results to filter out those
ignored due to ignore_errors.
For example, to get failed results without ignore_errors:
/api/v1/results?status=failed&ignore_errors=false
Change-Id: I6b6784d8999b78bcd01bae6c8958d25ce66f304b
This commit is contained in:
@@ -146,6 +146,7 @@ class ResultFilter(DateFilter):
|
||||
status = django_filters.MultipleChoiceFilter(
|
||||
field_name="status", choices=ara_models.Result.STATUS, lookup_expr="iexact"
|
||||
)
|
||||
ignore_errors = django_filters.BooleanFilter(field_name="ignore_errors", lookup_expr="exact")
|
||||
|
||||
# fmt: off
|
||||
order = django_filters.OrderingFilter(
|
||||
|
||||
@@ -184,6 +184,24 @@ class ResultTestCase(APITestCase):
|
||||
result = self.client.get("/api/v1/results/%s" % unreachable.id)
|
||||
self.assertEqual(result.data["status"], "unreachable")
|
||||
|
||||
def test_get_result_with_ignore_errors(self):
|
||||
failed = factories.ResultFactory(status="failed", ignore_errors=False)
|
||||
ignored = factories.ResultFactory(status="failed", ignore_errors=True)
|
||||
|
||||
# Searching for failed should return both
|
||||
results = self.client.get("/api/v1/results?status=failed").data["results"]
|
||||
self.assertEqual(2, len(results))
|
||||
|
||||
# Searching for failed with ignore_errors=True should only return the ignored result
|
||||
results = self.client.get("/api/v1/results?status=failed&ignore_errors=true").data["results"]
|
||||
self.assertEqual(1, len(results))
|
||||
self.assertEqual(ignored.id, results[0]["id"])
|
||||
|
||||
# Searching for failed with ignore_errors=False should only return the failed result
|
||||
results = self.client.get("/api/v1/results?status=failed&ignore_errors=false").data["results"]
|
||||
self.assertEqual(1, len(results))
|
||||
self.assertEqual(failed.id, results[0]["id"])
|
||||
|
||||
def test_get_result_duration(self):
|
||||
started = timezone.now()
|
||||
ended = started + datetime.timedelta(hours=1)
|
||||
|
||||
Reference in New Issue
Block a user