Skip to content

Commit b4d11ac

Browse files
author
EliuX
committed
Apply requested changes
1 parent 442a348 commit b4d11ac

File tree

7 files changed

+14
-25
lines changed

7 files changed

+14
-25
lines changed

tests/smoke_test.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import pyodbc
2+
13
import pytest
2-
import sqlalchemy
34
from flask.testing import FlaskClient
45
from flask_restplus._http import HTTPStatus
56
from pytest_mock import MockFixture
@@ -9,20 +10,16 @@ def test_app_exists(app):
910
assert app is not None
1011

1112

12-
unexpected_errors_to_be_handled = [sqlalchemy.exc.IntegrityError]
13+
unexpected_errors_to_be_handled = [pyodbc.OperationalError]
1314

1415

1516
@pytest.mark.parametrize("error_type", unexpected_errors_to_be_handled)
1617
def test_exceptions_are_handled(error_type, client: FlaskClient, mocker: MockFixture):
1718
from time_tracker_api.time_entries.time_entries_namespace import time_entries_dao
18-
repository_get_all_all_mock = mocker.patch.object(time_entries_dao,
19-
"get_all",
20-
side_effect=error_type)
19+
mocker.patch.object(time_entries_dao,
20+
"get_all",
21+
side_effect=error_type)
2122

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

24-
assert repository_get_all_all_mock.assert_not_called()
2525
assert HTTPStatus.INTERNAL_SERVER_ERROR != response.status_code
26-
27-
28-

time_tracker_api/activities/activities_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class ActivitiesDao(CRUDDao):
77

88
def create_dao() -> ActivitiesDao:
99
from time_tracker_api.sql_repository import db
10-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
10+
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
1111

12-
class ActivitySQLModel(db.Model, SQLModel, AuditedSQLModel):
12+
class ActivitySQLModel(db.Model, AuditedSQLModel):
1313
__tablename__ = 'activity'
1414
id = db.Column(db.Integer, primary_key=True)
1515

time_tracker_api/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def handle_invalid_data_error(e):
7878
@api.errorhandler(pyodbc.OperationalError)
7979
def handle_connection_error(e):
8080
"""Return a 500 due to a issue in the connection to a 3rd party service"""
81-
return {'message': 'Connection issues. Please try again in a few minutes.'}, HTTPStatus.INTERNAL_SERVER_ERROR
81+
return {'message': 'Connection issues. Please try again in a few minutes.'}, HTTPStatus.SERVICE_UNAVAILABLE
8282

8383

8484
@api.errorhandler

time_tracker_api/database.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ def __call__(self, *args, **kwargs):
4848
self.run() # pragma: no cover
4949

5050

51-
class DatabaseModel:
52-
pass
53-
54-
5551
seeder: Seeder = None
5652

5753

time_tracker_api/projects/projects_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class ProjectDao(CRUDDao):
1919
def create_dao() -> ProjectDao:
2020
from time_tracker_api.sql_repository import db
2121
from time_tracker_api.database import COMMENTS_MAX_LENGTH
22-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
22+
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
2323

24-
class ProjectSQLModel(db.Model, SQLModel, AuditedSQLModel):
24+
class ProjectSQLModel(db.Model, AuditedSQLModel):
2525
__tablename__ = 'project'
2626
id = db.Column(db.Integer, primary_key=True)
2727
name = db.Column(db.String(50), unique=True, nullable=False)

time_tracker_api/sql_repository.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from flask import Flask
44
from flask_sqlalchemy import SQLAlchemy
55

6-
from time_tracker_api.database import CRUDDao, Seeder, DatabaseModel, ID_MAX_LENGTH
6+
from time_tracker_api.database import CRUDDao, Seeder, ID_MAX_LENGTH
77
from time_tracker_api.security import current_user_id
88

99
db: SQLAlchemy = None
10-
SQLModel = None
1110
AuditedSQLModel = None
1211

1312

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

29-
global SQLModel
30-
SQLModel = DatabaseModel
31-
3228
global AuditedSQLModel
3329

3430
class AuditedSQLModelClass():

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class TimeEntriesDao(CRUDDao):
1010
def create_dao() -> TimeEntriesDao:
1111
from time_tracker_api.sql_repository import db
1212
from time_tracker_api.database import COMMENTS_MAX_LENGTH
13-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
13+
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
1414

15-
class TimeEntrySQLModel(db.Model, SQLModel, AuditedSQLModel):
15+
class TimeEntrySQLModel(db.Model, AuditedSQLModel):
1616
__tablename__ = 'time_entry'
1717
id = db.Column(db.Integer, primary_key=True)
1818
description = db.Column(db.String(COMMENTS_MAX_LENGTH))

0 commit comments

Comments
 (0)