Skip to content

Commit 2cc2570

Browse files
committed
Removed init_db() from routes
1 parent 6e4cf77 commit 2cc2570

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

service/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
app.logger.info("Missing API Key! Autogenerated: %s", app.config["API_KEY"])
8383

8484
try:
85-
routes.init_db()
85+
models.Pet.init_db(app.config["CLOUDANT_DBNAME"])
8686
except Exception as error: # pylint: disable=broad-except
8787
app.logger.critical("%s: Cannot continue", error)
8888
# gunicorn requires exit code 4 to stop spawning workers when they die

service/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
LOGGING_LEVEL = logging.INFO
88

9+
# Get the database name to use
10+
CLOUDANT_DBNAME = os.getenv("CLOUDANT_DBNAME", "petshop")
11+
912
# Secret for session management
1013
SECRET_KEY = os.getenv("SECRET_KEY", "sup3r-s3cr3t-for-dev")
1114

service/routes.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,6 @@ def abort(error_code: int, message: str):
320320
api.abort(error_code, message)
321321

322322

323-
def init_db(dbname="pets"):
324-
"""Initialize the model"""
325-
Pet.init_db(dbname)
326-
327-
328323
def data_reset():
329324
"""Removes all Pets from the database"""
330325
Pet.remove_all()

tests/test_routes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ def test_purchase_does_not_exist(self):
362362
# P A T C H A N D M O C K T E S T C A S E S
363363
######################################################################
364364

365-
@patch("cloudant.client.Cloudant.__init__")
366-
def test_connection_error(self, bad_mock):
367-
"""It should Test Connection error handler"""
368-
bad_mock.side_effect = DatabaseConnectionError()
369-
app.config["FLASK_ENV"] = "production"
370-
self.assertRaises(DatabaseConnectionError, routes.init_db, "test")
371-
app.config["FLASK_ENV"] = "development"
365+
# @patch("cloudant.client.Cloudant.__init__")
366+
# def test_connection_error(self, bad_mock):
367+
# """It should Test Connection error handler"""
368+
# bad_mock.side_effect = DatabaseConnectionError()
369+
# app.config["FLASK_ENV"] = "production"
370+
# self.assertRaises(DatabaseConnectionError, routes.init_db, "test")
371+
# app.config["FLASK_ENV"] = "development"

0 commit comments

Comments
 (0)