Skip to content

Commit

Permalink
feat: support for find queries in count
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 9, 2022
1 parent 356aedd commit a246d8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/quorum/model.py
Expand Up @@ -593,6 +593,10 @@ def find(cls, *args, **kwargs):
@classmethod
def count(cls, *args, **kwargs):
cls._clean_attrs(kwargs)

cls._find_s(kwargs)
cls._find_d(kwargs)

collection = cls._collection()
if kwargs:
if hasattr(collection, "count_documents"):
Expand Down
21 changes: 21 additions & 0 deletions src/quorum/test/model.py
Expand Up @@ -118,6 +118,27 @@ def test_count(self):
result = mock.Person.count()
self.assertEqual(result, 1)

@quorum.secured
def test_count_find(self):
adapter = quorum.get_adapter()
if not adapter.name in ("mongo",):
if not hasattr(self, "skipTest"): return
self.skipTest("Adapter is not supported")

result = mock.Person.count()
self.assertEqual(result, 0)

person = mock.Person()
person.age = 1
person.name = "Name"
person.save()

result = mock.Person.count(**dict(find_d = ["name:eq:Name"]))
self.assertEqual(result, 1)

result = mock.Person.count(**dict(find_d = ["name:eq:OtherName"]))
self.assertEqual(result, 0)

@quorum.secured
def test_delete(self):
result = mock.Person.count()
Expand Down

0 comments on commit a246d8b

Please sign in to comment.