Commit 3262868b80d702bbc1ba0ddacdd9a58e5f86152f
1 parent
264e5cfb
Exists in
master
and in
4 other branches
New Cli tests
create_db now outputs to stdout, not through logger
Showing
2 changed files
with
9 additions
and
3 deletions
Show diff stats
app/commands/commands.py
@@ -38,7 +38,7 @@ def create_db(): | @@ -38,7 +38,7 @@ def create_db(): | ||
38 | sys.exit(-1) | 38 | sys.exit(-1) |
39 | 39 | ||
40 | if sqlite_uri: | 40 | if sqlite_uri: |
41 | - current_app.logger.info("Created sqlite db: " + sqlite_uri) | 41 | + print("Created sqlite db: " + sqlite_uri) |
42 | 42 | ||
43 | 43 | ||
44 | @bp.cli.command("feed_from_irap") | 44 | @bp.cli.command("feed_from_irap") |
tests/cli_tests.py
1 | import unittest | 1 | import unittest |
2 | 2 | ||
3 | from app import create_app, db, User | 3 | from app import create_app, db, User |
4 | -from app.commands.commands import feed_from_irap, show_roles, user_add, user_show_all | 4 | +from app.commands.commands import feed_from_irap, show_roles, user_add, user_show_all, create_db |
5 | from pdc_config import TestConfig | 5 | from pdc_config import TestConfig |
6 | 6 | ||
7 | from app.commands import bp as cli_bp | 7 | from app.commands import bp as cli_bp |
@@ -10,7 +10,8 @@ from app.commands import bp as cli_bp | @@ -10,7 +10,8 @@ from app.commands import bp as cli_bp | ||
10 | class CliBaseTestCase(unittest.TestCase): | 10 | class CliBaseTestCase(unittest.TestCase): |
11 | 11 | ||
12 | def setUp(self): | 12 | def setUp(self): |
13 | - # Get rid of a strange 'ValueError: I/O operation' when app.logger outputs | 13 | + # Get rid of a strange 'ValueError: I/O operation' when pytest catches app.logger outputs |
14 | + # Error can also be bypassed with 'pytest -s' option | ||
14 | TestConfig.PDC_LOGS_LEVEL = 'ERROR' | 15 | TestConfig.PDC_LOGS_LEVEL = 'ERROR' |
15 | # Force sqlite in memory db | 16 | # Force sqlite in memory db |
16 | TestConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' | 17 | TestConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' |
@@ -24,6 +25,11 @@ class CliBaseTestCase(unittest.TestCase): | @@ -24,6 +25,11 @@ class CliBaseTestCase(unittest.TestCase): | ||
24 | def tearDown(self): | 25 | def tearDown(self): |
25 | pass | 26 | pass |
26 | 27 | ||
28 | + def test_create_db(self): | ||
29 | + runner = self.app.test_cli_runner() | ||
30 | + result = runner.invoke(create_db) | ||
31 | + self.assertTrue('Created sqlite' in result.output) | ||
32 | + | ||
27 | def test_show_all(self): | 33 | def test_show_all(self): |
28 | runner = self.app.test_cli_runner() | 34 | runner = self.app.test_cli_runner() |
29 | result = runner.invoke(user_show_all) | 35 | result = runner.invoke(user_show_all) |