Commit 2a06e4b6ae4548db3df0b80083214e706db3e0b3
1 parent
f1bb8c76
Exists in
master
and in
4 other branches
New cli unit tests
Showing
1 changed file
with
49 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,49 @@ |
1 | +import unittest | |
2 | + | |
3 | +from app import create_app, db, User | |
4 | +from app.commands.commands import feed_from_irap, show_roles, user_add, user_show_all | |
5 | +from pdc_config import TestConfig | |
6 | + | |
7 | +from app.commands import bp as cli_bp | |
8 | + | |
9 | + | |
10 | +class CliBaseTestCase(unittest.TestCase): | |
11 | + | |
12 | + def setUp(self): | |
13 | + # Get rid of a strange 'ValueError: I/O operation' when app.logger outputs | |
14 | + TestConfig.PDC_LOGS_LEVEL = 'ERROR' | |
15 | + # Force sqlite in memory db | |
16 | + TestConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' | |
17 | + # Create and register app | |
18 | + self.app = create_app(TestConfig) | |
19 | + self.app.register_blueprint(cli_bp) | |
20 | + self.app_context = self.app.app_context() | |
21 | + self.app_context.push() | |
22 | + db.create_all() | |
23 | + | |
24 | + def tearDown(self): | |
25 | + pass | |
26 | + | |
27 | + def test_hello3(self): | |
28 | + runner = self.app.test_cli_runner() | |
29 | + result = runner.invoke(user_show_all) | |
30 | + print("\n") | |
31 | + print(result.output) | |
32 | + | |
33 | + def test_hello2(self): | |
34 | + runner = self.app.test_cli_runner() | |
35 | + result = runner.invoke(show_roles) | |
36 | + print(result.output) | |
37 | + | |
38 | + def test_add_user(self): | |
39 | + runner = self.app.test_cli_runner() | |
40 | + | |
41 | + all_users = User.query.all() | |
42 | + self.assertEqual(0, len(all_users)) | |
43 | + # invoke the command directly | |
44 | + arguments = ['geo@ici.fr', 'Joseph Hitier', 'joh', 'passwd', 'PUBLIC'] | |
45 | + result = runner.invoke(user_add, arguments) | |
46 | + print(result.output) | |
47 | + all_users = User.query.all() | |
48 | + print(len(all_users)) | |
49 | + # self.assertEqual(1, len(all_users)) | ... | ... |