Skip to content

Commit c34623f

Browse files
committed
add odm unit tests
1 parent bb9c914 commit c34623f

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

nest/core/database/base_odm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def __init__(self, db_type="mongodb", config_params: dict = None, document_model
4343

4444
async def create_all(self):
4545
self.check_document_models()
46-
self.client = AsyncIOMotorClient(self.config_url)
46+
client = AsyncIOMotorClient(self.config_url)
4747
await init_beanie(
48-
database=self.client[self.config.db_name],
48+
database=client[self.config.db_name],
4949
document_models=self.document_models
5050
)
5151

nest/core/database/config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class BaseProvider(BaseOdmConfig):
5959
Args:
6060
host (str): The database host.
6161
db_name (str): The name of the database.
62-
user (str): The username for database authentication.
63-
password (str): The password for database authentication.
6462
port (int): The database port number.
6563
6664
"""
@@ -72,8 +70,6 @@ def __init__(self, host: str, db_name: str, port: int):
7270
Args:
7371
host (str): The database host.
7472
db_name (str): The name of the database.
75-
user (str): The username for database authentication.
76-
password (str): The password for database authentication.
7773
port (int): The database port number.
7874
7975
"""
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
3+
import pytest
4+
from nest.core.database.odm_config import (
5+
ConfigFactory,
6+
MongoDBConfig,
7+
)
8+
9+
from nest.core.database.base_odm import OdmService
10+
11+
12+
@pytest.fixture(scope="module")
13+
def odm_service():
14+
return OdmService(
15+
db_type="mongodb",
16+
config_params={
17+
"db_name": "test",
18+
"host": "test",
19+
"port": "test",
20+
},
21+
document_models=[],
22+
)
23+
24+
25+
@pytest.fixture(scope="module")
26+
def mongodb_config():
27+
return MongoDBConfig("test", "test", "test")
28+
29+
30+
def test_odm_service_definition(odm_service):
31+
assert odm_service.config
32+
assert odm_service.config_url
33+
assert odm_service.document_models == []
34+
35+
36+
def test_odm_service_config_url(odm_service):
37+
config_url = odm_service.config_url
38+
assert config_url == "mongodb://test:test"

0 commit comments

Comments
 (0)