Coverage for tests\test_cli.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-05 18:06 +0100

1import os 

2import tempfile 

3 

4from click.testing import CliRunner 

5 

6import airtable_to_sqlite.__main__ as armain 

7from airtable_to_sqlite.cli import airtable_to_sqlite 

8 

9_ = armain 

10 

11 

12def test_cli(_mock_api, _mock_get_api_bases, _mock_base_schema): 

13 runner = CliRunner() 

14 with tempfile.TemporaryDirectory() as tmpdirname: 

15 result = runner.invoke(airtable_to_sqlite, ["--output", os.path.join(tmpdirname, "{}.db"), "app123"]) 

16 assert result.exit_code == 0 

17 assert os.path.exists(os.path.join(tmpdirname, "Base 123.db")) 

18 

19 

20def test_cli_error(_mock_api, _mock_get_api_bases, _mock_base_schema): 

21 runner = CliRunner() 

22 with tempfile.TemporaryDirectory() as tmpdirname: 

23 result = runner.invoke( 

24 airtable_to_sqlite, ["--output", os.path.join(tmpdirname, "blah.db"), "app123", "app124"] 

25 ) 

26 assert result.exit_code == 2 

27 assert "Output filename must contain '{}'" in result.output