Commit 3262868b80d702bbc1ba0ddacdd9a58e5f86152f

Authored by hitier
1 parent 264e5cfb

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 38 sys.exit(-1)
39 39  
40 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 44 @bp.cli.command("feed_from_irap")
... ...
tests/cli_tests.py
1 1 import unittest
2 2  
3 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 5 from pdc_config import TestConfig
6 6  
7 7 from app.commands import bp as cli_bp
... ... @@ -10,7 +10,8 @@ from app.commands import bp as cli_bp
10 10 class CliBaseTestCase(unittest.TestCase):
11 11  
12 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 15 TestConfig.PDC_LOGS_LEVEL = 'ERROR'
15 16 # Force sqlite in memory db
16 17 TestConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
... ... @@ -24,6 +25,11 @@ class CliBaseTestCase(unittest.TestCase):
24 25 def tearDown(self):
25 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 33 def test_show_all(self):
28 34 runner = self.app.test_cli_runner()
29 35 result = runner.invoke(user_show_all)
... ...