Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support null/is_null sub-ops inside has/any ops #325

Merged
merged 2 commits into from
Jul 15, 2014
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
2 changes: 1 addition & 1 deletion flask_restless/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _sub_operator(model, argument, fieldname):
if isinstance(argument, dict):
fieldname = argument['name']
operator = argument['op']
argument = argument['val']
argument = argument.get('val')
relation = None
if '__' in fieldname:
fieldname, relation = fieldname.split('__')
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Computer(self.Base):
owner_id = Column(Integer, ForeignKey('person.id'))
owner = relationship('Person')
programs = relationship('ComputerProgram',
cascade="all, delete-orphan")
cascade="all, delete-orphan", backref='computer')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trim to 79 characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def speed(self):
return 42
Expand Down
16 changes: 14 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ def test_has_and_any_suboperators(self):
computer1 = self.Computer(name=u'c1', vendor=u'foo')
computer2 = self.Computer(name=u'c2', vendor=u'bar')
computer3 = self.Computer(name=u'c3', vendor=u'bar')
computer4 = self.Computer(name=u'c4', vendor=u'bar')
computer5 = self.Computer(name=u'c5', vendor=u'foo')
computer4 = self.Computer(name=u'c4', vendor=None, programs=[
self.ComputerProgram(program=self.Program())
])
computer5 = self.Computer(name=u'c5', vendor=u'foo', programs=[
self.ComputerProgram(program=self.Program())
])
computer6 = self.Computer(name=u'c6', vendor=u'foo')
self.session.add_all((computer1, computer2, computer3, computer4,
computer5, computer6))
Expand All @@ -214,11 +218,19 @@ def test_has_and_any_suboperators(self):
d = dict(filters=[dict(name='computers', op='any', val=val)])
result = search(self.session, self.Person, d)
assert result.count() == 2
val = dict(name='vendor', op='is_null')
d = dict(filters=[dict(name='computers', op='any', val=val)])
result = search(self.session, self.Person, d)
assert result.count() == 1
# test 'has'
val = dict(name='name', op='like', val=u'%incol%')
d = dict(filters=[dict(name='owner', op='has', val=val)])
result = search(self.session, self.Computer, d)
assert result.count() == 3
val = dict(name='vendor', op='is_null')
d = dict(filters=[dict(name='computer', op='has', val=val)])
result = search(self.session, self.ComputerProgram, d)
assert result.count() == 1

def test_has_and_any_nested_suboperators(self):
"""Tests for the ``"has"`` and ``"any"`` operators with nested
Expand Down