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

Add tests for API method tcms.bugs.api.filter() #1692

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Changes from all commits
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
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)