added integration tests and repository pattern for image, model and visual communication DTOs
Code Quality Pipeline / Check Code (pull_request) Failing after 3m21s
Code Quality Pipeline / Check Code (pull_request) Failing after 3m21s
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Definition of unittests for Docstore MongoDB implementation."""
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from pymongo import MongoClient
|
||||
from pymongo.collection import Collection
|
||||
from pymongo.database import Database
|
||||
|
||||
from shared.docstore.src.docstore_mongo import DocstoreMongo
|
||||
|
||||
|
||||
class TestDocstoreMongoImplementation(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# define relevant env vars
|
||||
self.env_var_map = {
|
||||
'MONGO_ENDPOINT': '192.168.1.2:27017',
|
||||
'MONGO_DB': 'visual_critical_discourse_analysis',
|
||||
'MONGO_COLLECTION': 'test-collection',
|
||||
}
|
||||
# set env vars
|
||||
for key, val in self.env_var_map.items():
|
||||
os.environ[key] = val
|
||||
# set other variables
|
||||
self.mongo_client_mock = MagicMock(MongoClient)
|
||||
self.mongo_database_mock = MagicMock(Database)
|
||||
self.mongo_collection_mock = MagicMock(Collection)
|
||||
|
||||
def tearDown(self):
|
||||
# clear env vars
|
||||
for key in self.env_var_map:
|
||||
_ = os.environ.pop(key, default=None)
|
||||
# reset reuseable mocks
|
||||
self.mongo_client_mock.reset_mock()
|
||||
self.mongo_database_mock.reset_mock()
|
||||
self.mongo_collection_mock.reset_mock()
|
||||
|
||||
def test_instantiation_should_fail_when_env_not_set(self):
|
||||
# ensure env not set
|
||||
self.tearDown()
|
||||
# run test
|
||||
with self.assertRaises(OSError):
|
||||
_ = DocstoreMongo()
|
||||
Reference in New Issue
Block a user