Skip to content

Commit

Permalink
PDC-947,Make bootable filter on images case-insensitive and change th…
Browse files Browse the repository at this point in the history
…e name of the filter method.
  • Loading branch information
bliuredhat committed Sep 8, 2015
1 parent 639eca7 commit b38496d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pdc/apps/common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def filter(self, qs, value):
return super(NullableCharFilter, self).filter(qs, value)


class CustomizeBooleanFilter(django_filters.CharFilter):
class CaseInsensitiveBooleanFilter(django_filters.CharFilter):
"""
Customize boolean filter that allows filtering items with below values:
True: ('true', 't', '1'), regardless of letter case sensitive
Expand Down
4 changes: 2 additions & 2 deletions pdc/apps/component/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pdc.apps.common.filters import (ComposeFilterSet,
value_is_not_empty,
MultiValueFilter,
CustomizeBooleanFilter)
CaseInsensitiveBooleanFilter)


class RoleContactFilter(FilterSet):
Expand Down Expand Up @@ -147,7 +147,7 @@ class ReleaseComponentFilter(ComposeFilterSet):
widget=SelectMultiple)
bugzilla_component = MultiValueFilter(name='bugzilla_component__name')
brew_package = MultiValueFilter()
active = CustomizeBooleanFilter()
active = CaseInsensitiveBooleanFilter()
type = CharFilter(name='type__name')

@value_is_not_empty
Expand Down
2 changes: 2 additions & 0 deletions pdc/apps/package/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import django_filters

from pdc.apps.common.filters import MultiValueFilter, MultiIntFilter, NullableCharFilter
from pdc.apps.common.filters import CaseInsensitiveBooleanFilter
from . import models


Expand Down Expand Up @@ -47,6 +48,7 @@ class ImageFilter(django_filters.FilterSet):
sha256 = MultiValueFilter()
compose = MultiValueFilter(name='composeimage__variant_arch__variant__compose__compose_id',
distinct=True)
bootable = CaseInsensitiveBooleanFilter()

class Meta:
model = models.Image
Expand Down
10 changes: 10 additions & 0 deletions pdc/apps/package/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,16 @@ def test_query_bootable(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get('count'), 1)

def test_negative_bootable(self):
response = self.client.get(reverse('image-list'), {'bootable': 'false'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get('count'), 2)

def test_active_bootable(self):
response = self.client.get(reverse('image-list'), {'bootable': 'true'})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get('count'), 1)

def test_query_implant_md5(self):
response = self.client.get(reverse('image-list'), {'implant_md5': 'a' * 32})
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down

0 comments on commit b38496d

Please sign in to comment.