1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 18:21:12 +03:00

Merge pull request #1672 from wwitzel3/devel

adjusting how we restrict __in based on PR feedback
This commit is contained in:
Wayne Witzel III 2016-04-25 09:31:18 -04:00
commit f457e54a23
2 changed files with 8 additions and 3 deletions

View File

@ -131,9 +131,9 @@ class FieldLookupBackend(BaseFilterBackend):
value = to_python_boolean(value)
elif new_lookup.endswith('__in'):
items = []
if not value:
raise ValueError('cannot provide empty value for __in')
for item in value.split(','):
if not item:
raise ValueError('cannot provide empty value for __in')
items.append(self.value_to_python_for_field(field, item))
value = items
elif new_lookup.endswith('__regex') or new_lookup.endswith('__iregex'):

View File

@ -3,10 +3,15 @@ import pytest
from awx.api.filters import FieldLookupBackend
from awx.main.models import JobTemplate
@pytest.mark.parametrize(u"empty_value", [u'', '', u'a,,b'])
@pytest.mark.parametrize(u"empty_value", [u'', ''])
def test_empty_in(empty_value):
field_lookup = FieldLookupBackend()
with pytest.raises(ValueError) as excinfo:
field_lookup.value_to_python(JobTemplate, 'project__in', empty_value)
assert 'empty value for __in' in str(excinfo.value)
@pytest.mark.parametrize(u"valid_value", [u'foo', u'foo,'])
def test_valid_in(valid_value):
field_lookup = FieldLookupBackend()
value, new_lookup = field_lookup.value_to_python(JobTemplate, 'project__in', valid_value)
assert 'foo' in value