Commit 9073551e authored by Leo Sandoval's avatar Leo Sandoval Committed by Damien Lespiau
Browse files

series: Include filtering by test states

Allows querying series by test states. Sample query:

    GET /api/1.0/projects/oe-core/series/?test_state=success

Other test states are explained on the documentation page [1]

[1] http://patchwork-freedesktop.readthedocs.org/en/latest/rest.html

v2: A few tweaks here and there (Damien)
    https://github.com/dlespiau/patchwork/pull/154

Signed-off-by: default avatarLeo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent f2ddfce9
......@@ -314,6 +314,11 @@ A series has then ``n`` revisions, ``n`` going from ``1`` to ``version``.
specified time. Format is the same as
``last_updated`` in response, an ISO 8601 date.
:query test_state: Filter series by test state. Possible values are
``pending``, ``success``, ``warning``, ``failure`` or
``null`` series that don't have any test result.
.. http:get:: /api/1.0/series/
List of all Series known to patchwork.
......
......@@ -504,6 +504,11 @@ class TestState:
(STATE_FAILURE, 'failure'),
)
@classmethod
def from_string(cls, s):
s2i = {s: i for i, s in cls.STATE_CHOICES}
return s2i[s]
# This Model represents the "top level" Series, an object that doesn't change
# with the various versions of patches sent to the mailing list.
......
......@@ -160,6 +160,16 @@ class SeriesFilter(django_filters.FilterSet):
queryset = queryset.filter(reviewer__isnull=True)
return queryset
def test_state_filter(queryset, test_state):
try:
state = TestState.from_string(test_state)
queryset = queryset.filter(last_revision__test_state=state)
except KeyError:
if test_state == 'null':
queryset = queryset.filter(
last_revision__test_state__isnull=True)
return queryset
submitted_since = django_filters.CharFilter(action=submitted_since_filter)
updated_since = django_filters.CharFilter(action=updated_since_filter)
submitted_before = django_filters.CharFilter(
......@@ -167,6 +177,7 @@ class SeriesFilter(django_filters.FilterSet):
updated_before = django_filters.CharFilter(action=updated_before_filter)
submitter = django_filters.MethodFilter(action='submitter_filter')
reviewer = django_filters.MethodFilter(action=reviewer_filter)
test_state = django_filters.MethodFilter(action=test_state_filter)
class Meta:
model = Series
......
Markdown is supported
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