Skip to content

Commit

Permalink
api: Add tests for tcms.bugs.api.filter -- Closes kiwitcms#1597
Browse files Browse the repository at this point in the history
  • Loading branch information
mfonism committed Jul 13, 2020
1 parent 97fcf36 commit c68106c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tcms/bugs/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,31 @@ def verify_api_with_permission(self):
def verify_api_without_permission(self):
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):
self.rpc_client.Bug.remove({"pk__in": [self.bug.pk, self.another_bug.pk]})


class TestFilter(APITestCase):
"""Test Bug.filter"""

def _fixture_setup(self):
super()._fixture_setup()

self.bug = BugFactory(status=False)
self.another_bug = BugFactory(status=True)
self.yet_another_bug = BugFactory(status=True)

def test_filter(self):
result = self.rpc_client.Bug.filter({"status": True})
self.assertIsInstance(result, list)
self.assertEqual(len(result), 2)

pks = []
for item in result:
pks.append(item["pk"])

self.assertNotIn(self.bug.pk, pks)
self.assertIn(self.another_bug.pk, pks)
self.assertIn(self.yet_another_bug.pk, pks)

def test_filter_non_existing(self):
result = self.rpc_client.Bug.filter({"pk": -99})
self.assertEqual(len(result), 0)

0 comments on commit c68106c

Please sign in to comment.