1 | import os |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | import pytest |
||
4 | from click.testing import CliRunner |
||
5 | from testfixtures import LogCapture |
||
6 | |||
7 | from gols.cli import main |
||
8 | from gols.cli import upload |
||
9 | |||
10 | |||
11 | @pytest.fixture(scope='function') |
||
12 | def runner(): |
||
13 | yield CliRunner() |
||
14 | |||
15 | |||
16 | @pytest.fixture(scope='function') |
||
17 | def fs(): |
||
18 | if not os.path.exists(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'directory_fit')): |
||
0 ignored issues
–
show
|
|||
19 | os.makedirs(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'directory_fit')) |
||
0 ignored issues
–
show
|
|||
20 | yield os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'directory_fit') |
||
21 | |||
22 | |||
23 | @pytest.fixture(scope='function') |
||
24 | def cdf(): |
||
25 | if not os.path.exists(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'conf_dir_fit')): |
||
0 ignored issues
–
show
|
|||
26 | os.makedirs(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'conf_dir_fit')) |
||
0 ignored issues
–
show
|
|||
27 | yield os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests', 'conf_dir_fit') |
||
28 | |||
29 | |||
30 | def test_debug_turned_on(runner): |
||
31 | with LogCapture() as lc: |
||
32 | result = runner.invoke(main, ['--debug', 'upload']) |
||
33 | assert result.exit_code == 2 |
||
34 | assert 'Debug level set on' in str(lc) |
||
35 | |||
36 | |||
37 | def test_debug_turned_off(runner): |
||
38 | with LogCapture() as lc: |
||
39 | result = runner.invoke(main, ['upload']) |
||
40 | assert result.exit_code == 2 |
||
41 | assert 'Info level set on' in str(lc) |
||
42 | |||
43 | |||
44 | def test_upload_help(runner): |
||
45 | result = runner.invoke(upload, ['--help']) |
||
46 | assert result.exit_code == 0 |
||
47 | assert 'Usage' in result.output |
||
48 | |||
49 | |||
50 | def test_required_fit_directory(runner, fs): |
||
51 | result = runner.invoke(upload, ['upload', fs]) |
||
52 | assert result.exit_code == 2 |
||
53 | assert 'Error: Missing option' in result.output |
||
54 | |||
55 | |||
56 | def test_upload_fit(runner, fs, cdf): |
||
57 | username = '[email protected]' |
||
58 | password = 'G0lsG0ls' |
||
59 | with LogCapture() as lc: |
||
60 | # logger = logging.getLogger() |
||
61 | result = runner.invoke(main, ['--debug', 'upload', '-d', fs, '-c', cdf, '-u', username, '-p', password]) # noqa |
||
0 ignored issues
–
show
|
|||
62 | print(result.output) |
||
63 | print(lc) |
||
64 | assert result.exit_code == 0 |
||
65 | assert 'Done uploading' in str(lc) |
||
66 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.