Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[LIB-743] corrects after tests
  • Loading branch information
opalczynski committed May 25, 2016
commit 12a61a0d40b1fcd302233ee0e2c1e608c4a751cd
9 changes: 6 additions & 3 deletions syncano/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ class for :class:`~syncano.models.base.Object` model.
'gt', 'gte', 'lt', 'lte',
'eq', 'neq', 'exists', 'in',
'near', 'is', 'contains',
'startswith', 'endswith',
'contains', 'istartswith',
'iendswith', 'icontains',
'ieq', 'near',
]

def __init__(self):
Expand Down Expand Up @@ -990,13 +994,12 @@ def _get_lookup_attributes(self, field_name):
return model_name, field_name, lookup

def _validate_lookup(self, model, model_name, field_name, lookup, field):

if not model_name and field_name not in model._meta.field_names:
allowed = ', '.join(model._meta.field_names)
raise SyncanoValueError('Invalid field name "{0}" allowed are {1}.'.format(field_name, allowed))

allowed_lookups = set(self.ALLOWED_LOOKUPS + field.field_lookups)

if lookup not in allowed_lookups:
if lookup not in self.ALLOWED_LOOKUPS:
allowed = ', '.join(self.ALLOWED_LOOKUPS)
raise SyncanoValueError('Invalid lookup type "{0}" allowed are {1}.'.format(lookup, allowed))

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test_string_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _test_filter(self, filter):

def test_starstwith(self):
self._test_filter({'title__startswith': 'Some'})
self._test_filter({'title__istartswith': 'omes'})
self._test_filter({'title__istartswith': 'some'})

def test_endswith(self):
self._test_filter({'title__endswith': 'tle'})
Expand Down