cli_tests.py
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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))