mirror of https://github.com/stijndcl/didier
Set up mongo connection in pytest & fix authentication url
parent
52b452c85a
commit
6bebd109bb
|
@ -7,14 +7,14 @@ from sqlalchemy.orm import sessionmaker
|
|||
|
||||
import settings
|
||||
|
||||
encoded_password = quote_plus(settings.POSTGRES_PASS)
|
||||
encoded_postgres_password = quote_plus(settings.POSTGRES_PASS)
|
||||
|
||||
# PostgreSQL engine
|
||||
postgres_engine = create_async_engine(
|
||||
URL.create(
|
||||
drivername="postgresql+asyncpg",
|
||||
username=settings.POSTGRES_USER,
|
||||
password=encoded_password,
|
||||
password=encoded_postgres_password,
|
||||
host=settings.POSTGRES_HOST,
|
||||
port=settings.POSTGRES_PORT,
|
||||
database=settings.POSTGRES_DB,
|
||||
|
@ -28,4 +28,7 @@ DBSession = sessionmaker(
|
|||
)
|
||||
|
||||
# MongoDB client
|
||||
mongo_client = motor.motor_asyncio.AsyncIOMotorClient(settings.MONGO_HOST, settings.MONGO_PORT)
|
||||
encoded_mongo_username = quote_plus(settings.MONGO_USER)
|
||||
encoded_mongo_password = quote_plus(settings.MONGO_PASS)
|
||||
mongo_url = f"mongodb://{encoded_mongo_username}:{encoded_mongo_password}@{settings.MONGO_HOST}:{settings.MONGO_PORT}/"
|
||||
mongo_client = motor.motor_asyncio.AsyncIOMotorClient(mongo_url)
|
||||
|
|
|
@ -2,10 +2,12 @@ import asyncio
|
|||
from typing import AsyncGenerator, Generator
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import motor.motor_asyncio
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.engine import postgres_engine
|
||||
import settings
|
||||
from database.engine import mongo_client, postgres_engine
|
||||
from database.migrations import ensure_latest_migration, migrate
|
||||
from didier import Didier
|
||||
|
||||
|
@ -54,6 +56,14 @@ async def postgres(tables) -> AsyncGenerator[AsyncSession, None]:
|
|||
await connection.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mongodb() -> motor.motor_asyncio.AsyncIOMotorDatabase:
|
||||
"""Fixture to get a MongoDB connection"""
|
||||
database = mongo_client[settings.MONGO_DB]
|
||||
yield database
|
||||
mongo_client.drop_database(settings.MONGO_DB)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_client() -> Didier:
|
||||
"""Fixture to get a mock Didier instance
|
||||
|
|
Loading…
Reference in New Issue