Skip to content

Commit 2ed13c9

Browse files
author
EliuX
committed
Apply changes requested in meeting
1 parent 336eb75 commit 2ed13c9

File tree

5 files changed

+20
-76
lines changed

5 files changed

+20
-76
lines changed

tests/sql_repository_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def test_find_all(sql_repository):
5454
assert all(e in existing_elements_registry for e in existing_elements)
5555

5656

57-
def test_find_all_that_contains_property_with_string(sql_repository):
58-
"""Find all elements that have a property that partially contains a string (case-insensitive)"""
57+
def test_find_all_that_contains_property_with_string_case_insensitive(sql_repository):
5958
fake_name = fake.name()
6059
new_element = dict(name="%s Snow" % fake_name,
6160
email=fake.safe_email(),

time_tracker_api/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ def handle_connection_error(e):
9494

9595
@api.errorhandler
9696
def generic_exception_handler(e):
97-
if not app.config.get("FLASK_DEBUG", False):
98-
app.logger.error(e)
97+
app.logger.error(e)
9998
return {'message': 'An unhandled exception occurred.'}, 500

time_tracker_api/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22

3-
from time_tracker_api.database import DATABASE_TYPE
43
from time_tracker_api.security import generate_dev_secret_key
54

65

@@ -26,7 +25,6 @@ class SQLConfig(Config):
2625
SQLALCHEMY_DATABASE_URI = Config.DATABASE_URI
2726
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
2827
SQLALCHEMY_TRACK_MODIFICATIONS = False
29-
DATABASE = DATABASE_TYPE.SQL
3028

3129

3230
class AzureConfig(SQLConfig):

time_tracker_api/database.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
from flask import Flask
1313

1414

15-
class DATABASE_TYPE(enum.Enum):
16-
IN_MEMORY = 'in-memory'
17-
SQL = 'sql'
18-
19-
2015
class CRUDDao(abc.ABC):
2116
@abc.abstractmethod
2217
def get_all(self):
@@ -76,13 +71,8 @@ def to_dto(*args, **kw):
7671

7772

7873
def init_app(app: Flask) -> None:
79-
database_strategy = app.config['DATABASE']
80-
with app.app_context():
81-
globals()["use_%s" % database_strategy.name.lower()](app)
82-
83-
84-
def use_sql(app: Flask) -> None:
8574
from time_tracker_api.sql_repository import init_app, SQLSeeder
8675
init_app(app)
8776
global seeder
8877
seeder = SQLSeeder()
78+

time_tracker_api/projects/projects_model.py

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from flask import Flask
44

5-
from time_tracker_api.database import DATABASE_TYPE, CRUDDao
5+
from time_tracker_api.database import CRUDDao
66
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel, SQLModel
77

88

@@ -20,66 +20,24 @@ class ProjectDao(CRUDDao):
2020

2121

2222
def create_dao(app: Flask) -> ProjectDao:
23-
if app.config['DATABASE'] == DATABASE_TYPE.SQL:
24-
from time_tracker_api.sql_repository import db
23+
from time_tracker_api.sql_repository import db
2524

26-
class ProjectSQLModel(db.Model, SQLModel, AuditedSQLModel):
27-
__tablename__ = 'projects'
28-
id = db.Column(db.Integer, primary_key=True)
29-
name = db.Column(db.String(50), unique=True, nullable=False)
30-
description = db.Column(db.String(250), unique=False, nullable=False)
31-
type = db.Column(db.String(10), nullable=False)
32-
active = db.Column(db.Boolean, default=True)
25+
class ProjectSQLModel(db.Model, SQLModel, AuditedSQLModel):
26+
__tablename__ = 'projects'
27+
id = db.Column(db.Integer, primary_key=True)
28+
name = db.Column(db.String(50), unique=True, nullable=False)
29+
description = db.Column(db.String(250), unique=False, nullable=False)
30+
type = db.Column(db.String(10), nullable=False)
31+
active = db.Column(db.Boolean, default=True)
3332

34-
def __repr__(self):
35-
return '<Project %r>' % self.name
33+
def __repr__(self):
34+
return '<Project %r>' % self.name
3635

37-
def __str___(self):
38-
return "the project \"%s\"" % self.name
36+
def __str___(self):
37+
return "the project \"%s\"" % self.name
3938

40-
class ProjectSQLDao(SQLCRUDDao):
41-
def __init__(self):
42-
SQLCRUDDao.__init__(self, ProjectSQLModel)
39+
class ProjectSQLDao(SQLCRUDDao):
40+
def __init__(self):
41+
SQLCRUDDao.__init__(self, ProjectSQLModel)
4342

44-
return ProjectSQLDao()
45-
else:
46-
"""
47-
This is legacy, just to make clear how multiple database strategies can be supported
48-
with the current design/architecture.
49-
"""
50-
from time_tracker_api.errors import MissingResource
51-
52-
class ProjectInMemoryDAO(object):
53-
def __init__(self):
54-
self.counter = 0
55-
self.projects = []
56-
57-
def get_all(self):
58-
return self.projects
59-
60-
def get(self, id):
61-
for project in self.projects:
62-
if project.get('id') == id:
63-
return project
64-
raise MissingResource("Project '%s' not found" % id)
65-
66-
def create(self, project):
67-
self.counter += 1
68-
project['id'] = str(self.counter)
69-
self.projects.append(project)
70-
return project
71-
72-
def update(self, id, data):
73-
project = self.get(id)
74-
if project:
75-
project.update(data)
76-
return project
77-
else:
78-
raise MissingResource("Project '%s' not found" % id)
79-
80-
def delete(self, id):
81-
if id:
82-
project = self.get(id)
83-
self.projects.remove(project)
84-
85-
return ProjectInMemoryDAO()
43+
return ProjectSQLDao()

0 commit comments

Comments
 (0)