Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Apply requested changes
  • Loading branch information
EliuX committed Mar 25, 2020
commit b4d11ac614cc70094e20fefa459ff292f7e2891f
15 changes: 6 additions & 9 deletions tests/smoke_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pyodbc

import pytest
import sqlalchemy
from flask.testing import FlaskClient
from flask_restplus._http import HTTPStatus
from pytest_mock import MockFixture
Expand All @@ -9,20 +10,16 @@ def test_app_exists(app):
assert app is not None


unexpected_errors_to_be_handled = [sqlalchemy.exc.IntegrityError]
unexpected_errors_to_be_handled = [pyodbc.OperationalError]


@pytest.mark.parametrize("error_type", unexpected_errors_to_be_handled)
def test_exceptions_are_handled(error_type, client: FlaskClient, mocker: MockFixture):
from time_tracker_api.time_entries.time_entries_namespace import time_entries_dao
repository_get_all_all_mock = mocker.patch.object(time_entries_dao,
"get_all",
side_effect=error_type)
mocker.patch.object(time_entries_dao,
"get_all",
side_effect=error_type)

response = client.get('/time-entries', follow_redirects=True)

assert repository_get_all_all_mock.assert_not_called()
assert HTTPStatus.INTERNAL_SERVER_ERROR != response.status_code



4 changes: 2 additions & 2 deletions time_tracker_api/activities/activities_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class ActivitiesDao(CRUDDao):

def create_dao() -> ActivitiesDao:
from time_tracker_api.sql_repository import db
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel

class ActivitySQLModel(db.Model, SQLModel, AuditedSQLModel):
class ActivitySQLModel(db.Model, AuditedSQLModel):
__tablename__ = 'activity'
id = db.Column(db.Integer, primary_key=True)

Expand Down
2 changes: 1 addition & 1 deletion time_tracker_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def handle_invalid_data_error(e):
@api.errorhandler(pyodbc.OperationalError)
def handle_connection_error(e):
"""Return a 500 due to a issue in the connection to a 3rd party service"""
return {'message': 'Connection issues. Please try again in a few minutes.'}, HTTPStatus.INTERNAL_SERVER_ERROR
return {'message': 'Connection issues. Please try again in a few minutes.'}, HTTPStatus.SERVICE_UNAVAILABLE


@api.errorhandler
Expand Down
4 changes: 0 additions & 4 deletions time_tracker_api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def __call__(self, *args, **kwargs):
self.run() # pragma: no cover


class DatabaseModel:
pass


seeder: Seeder = None


Expand Down
4 changes: 2 additions & 2 deletions time_tracker_api/projects/projects_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ProjectDao(CRUDDao):
def create_dao() -> ProjectDao:
from time_tracker_api.sql_repository import db
from time_tracker_api.database import COMMENTS_MAX_LENGTH
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel

class ProjectSQLModel(db.Model, SQLModel, AuditedSQLModel):
class ProjectSQLModel(db.Model, AuditedSQLModel):
__tablename__ = 'project'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), unique=True, nullable=False)
Expand Down
6 changes: 1 addition & 5 deletions time_tracker_api/sql_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

from time_tracker_api.database import CRUDDao, Seeder, DatabaseModel, ID_MAX_LENGTH
from time_tracker_api.database import CRUDDao, Seeder, ID_MAX_LENGTH
from time_tracker_api.security import current_user_id

db: SQLAlchemy = None
SQLModel = None
AuditedSQLModel = None


Expand All @@ -26,9 +25,6 @@ def init_app(app: Flask) -> None:
global db
db = SQLAlchemy(app)

global SQLModel
SQLModel = DatabaseModel

global AuditedSQLModel

class AuditedSQLModelClass():
Expand Down
4 changes: 2 additions & 2 deletions time_tracker_api/time_entries/time_entries_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class TimeEntriesDao(CRUDDao):
def create_dao() -> TimeEntriesDao:
from time_tracker_api.sql_repository import db
from time_tracker_api.database import COMMENTS_MAX_LENGTH
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel

class TimeEntrySQLModel(db.Model, SQLModel, AuditedSQLModel):
class TimeEntrySQLModel(db.Model, AuditedSQLModel):
__tablename__ = 'time_entry'
id = db.Column(db.Integer, primary_key=True)
description = db.Column(db.String(COMMENTS_MAX_LENGTH))
Expand Down