From 2a06e4b6ae4548db3df0b80083214e706db3e0b3 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 29 Apr 2021 23:22:05 +0200 Subject: [PATCH] New cli unit tests --- tests/cli_tests.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+), 0 deletions(-) create mode 100644 tests/cli_tests.py diff --git a/tests/cli_tests.py b/tests/cli_tests.py new file mode 100644 index 0000000..5ae10bf --- /dev/null +++ b/tests/cli_tests.py @@ -0,0 +1,49 @@ +import unittest + +from app import create_app, db, User +from app.commands.commands import feed_from_irap, show_roles, user_add, user_show_all +from pdc_config import TestConfig + +from app.commands import bp as cli_bp + + +class CliBaseTestCase(unittest.TestCase): + + def setUp(self): + # Get rid of a strange 'ValueError: I/O operation' when app.logger outputs + TestConfig.PDC_LOGS_LEVEL = 'ERROR' + # Force sqlite in memory db + TestConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' + # Create and register app + self.app = create_app(TestConfig) + self.app.register_blueprint(cli_bp) + self.app_context = self.app.app_context() + self.app_context.push() + db.create_all() + + def tearDown(self): + pass + + def test_hello3(self): + runner = self.app.test_cli_runner() + result = runner.invoke(user_show_all) + print("\n") + print(result.output) + + def test_hello2(self): + runner = self.app.test_cli_runner() + result = runner.invoke(show_roles) + print(result.output) + + def test_add_user(self): + runner = self.app.test_cli_runner() + + all_users = User.query.all() + self.assertEqual(0, len(all_users)) + # invoke the command directly + arguments = ['geo@ici.fr', 'Joseph Hitier', 'joh', 'passwd', 'PUBLIC'] + result = runner.invoke(user_add, arguments) + print(result.output) + all_users = User.query.all() + print(len(all_users)) + # self.assertEqual(1, len(all_users)) -- libgit2 0.21.2