Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dateEnd
# D-TimeLeft

An API to store final dates and return various parameters related to these dates.

Expand Down
16 changes: 13 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
from src.api import api
from src.utils.error_handler import ErrorHandler

app = Flask(__name__)
api.init_app(app)
def create_app():
from dotenv import load_dotenv
import os
load_dotenv()

app.register_error_handler(Exception, lambda error: ErrorHandler(error)())
app = Flask(__name__)
app.config["MONGO_CONNECTION"] = os.getenv("MONGO_CONNECTION")

api.init_app(app)

app.register_error_handler(Exception, lambda error: ErrorHandler(error)())

return app

if __name__ == '__main__':
app = create_app()
app.run(debug=True)
8 changes: 3 additions & 5 deletions src/config/db_connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from pymongo import MongoClient
from dotenv import load_dotenv
import os
load_dotenv()
from flask import current_app

def create_conn():
"""Create database connection"""
client = MongoClient(os.getenv("MONGO_CONNECTION"))
db = client.dateEnd
client = MongoClient(current_app.config["MONGO_CONNECTION"])
db = client.da
collection = db.dates

return collection
2 changes: 1 addition & 1 deletion src/repositories/date_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class DateRepository:
"""Query methods from database"""

def __init__(self):
"""Initiate database connection"""
self.conn = create_conn()
Expand Down
Empty file added test/conftest.py
Empty file.
22 changes: 22 additions & 0 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from werkzeug.test import Client
from pymongo import MongoClient


@pytest.fixture
def client():
from app import app

test_mongodb_uri = 'mongodb://localhost/test'

app.config.update({
"MONGO_CONNECTION": test_mongodb_uri,
"TESTING": True,
})

test_client = Client(app)

yield test_client

mongo = MongoClient(test_mongodb_uri)
mongo.drop_database('test')