generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0661f7
commit 94c6a15
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest import TestCase | ||
from unittest.mock import patch, MagicMock | ||
from pymongo.collection import Collection | ||
from todo.models.label import LabelModel | ||
from todo.repositories.label_repository import LabelRepository | ||
from todo.tests.fixtures.label import label_db_data | ||
|
||
|
||
class LabelRepositoryTests(TestCase): | ||
def setUp(self): | ||
self.label_ids = [label_data["_id"] for label_data in label_db_data] | ||
self.label_data = label_db_data | ||
|
||
self.patcher_get_collection = patch("todo.repositories.label_repository.LabelRepository.get_collection") | ||
self.mock_get_collection = self.patcher_get_collection.start() | ||
self.mock_collection = MagicMock(spec=Collection) | ||
self.mock_get_collection.return_value = self.mock_collection | ||
|
||
def tearDown(self): | ||
self.patcher_get_collection.stop() | ||
|
||
def test_list_by_ids_returns_label_models(self): | ||
self.mock_collection.find.return_value = self.label_data | ||
|
||
result = LabelRepository.list_by_ids(self.label_ids) | ||
|
||
self.assertEqual(len(result), len(self.label_data)) | ||
self.assertTrue(all(isinstance(label, LabelModel) for label in result)) | ||
|
||
def test_list_by_ids_returns_empty_list_if_not_found(self): | ||
self.mock_collection.find.return_value = [] | ||
|
||
result = LabelRepository.list_by_ids([self.label_ids[0]]) | ||
|
||
self.assertEqual(result, []) | ||
|
||
def test_list_by_ids_skips_db_call_for_empty_input(self): | ||
result = LabelRepository.list_by_ids([]) | ||
|
||
self.assertEqual(result, []) | ||
self.mock_get_collection.assert_not_called() | ||
self.mock_collection.assert_not_called() |