You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
817 B
37 lines
817 B
import sys
|
|
from pathlib import Path
|
|
sys.path.append(str(Path(__file__).absolute().parent.parent))
|
|
|
|
# TestClient provided by FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
# PyMongo for the database
|
|
import pymongo
|
|
|
|
# Contains all constants
|
|
import app.config as config
|
|
# Import the app
|
|
from app.main import app
|
|
|
|
# Database setup
|
|
client = pymongo.MongoClient(config.MONGODB_URL, username=config.MONGODB_USERNAME, password=config.MONGODB_PASSWORD)
|
|
|
|
# Drop test database if exists
|
|
if config.MONGODB_DATABASE in client.list_database_names():
|
|
try:
|
|
client.drop_database(config.MONGODB_DATABASE)
|
|
except Exception as e:
|
|
print(f"Error with database : {e}")
|
|
|
|
# Create empty database
|
|
db = client[config.MONGODB_DATABASE]
|
|
|
|
# TestClient with the app imported from main
|
|
client = TestClient(app)
|
|
|
|
|
|
|
|
|
|
|
|
|