diff options
author | 2018-03-14 09:53:43 -0400 | |
---|---|---|
committer | 2018-03-14 09:54:09 -0400 | |
commit | 4cc7a3e4e33d607f344ac413a2cc9f763e8cf4bd (patch) | |
tree | 15ce705ba3ea275f2a43736f3e58c498ed831a06 | |
parent | f9242fb6fd592a14b09761dfb58fb7f7e7c56607 (diff) |
Use tmpdir when using mock catalog of tests
Change-Id: I8ef3e3d79729b8aff899f6cda58d75245b3ad3e4
Issue-ID: DCAEGEN2-372
Signed-off-by: Michael Hwang <mhwang@research.att.com>
5 files changed, 41 insertions, 23 deletions
diff --git a/dcae-cli/dcae_cli/catalog/mock/tests/test_mock_catalog.py b/dcae-cli/dcae_cli/catalog/mock/tests/test_mock_catalog.py index 75b883d..98b7c54 100644 --- a/dcae-cli/dcae_cli/catalog/mock/tests/test_mock_catalog.py +++ b/dcae-cli/dcae_cli/catalog/mock/tests/test_mock_catalog.py @@ -277,10 +277,11 @@ _cdap_spec={ } -def test_component_basic(mock_cli_config, catalog=None): +def test_component_basic(mock_cli_config, mock_db_url, catalog=None): '''Tests basic component usage of MockCatalog''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, enforce_image=False) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + enforce_image=False, db_url=mock_db_url) else: mc = catalog @@ -312,10 +313,11 @@ def test_component_basic(mock_cli_config, catalog=None): assert cver == '1.0.0' -def test_format_basic(mock_cli_config, catalog=None): +def test_format_basic(mock_cli_config, mock_db_url, catalog=None): '''Tests basic data format usage of MockCatalog''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + db_url=mock_db_url) else: mc = catalog @@ -351,10 +353,11 @@ def test_format_basic(mock_cli_config, catalog=None): assert spec['self']['description'] == new_descr -def test_discovery(mock_cli_config, catalog=None): +def test_discovery(mock_cli_config, mock_db_url, catalog=None): '''Tests creation of discovery objects''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, enforce_image=False) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + enforce_image=False, db_url=mock_db_url) else: mc = catalog @@ -393,10 +396,11 @@ def _format_tuple_set(*dds): return set(map(_format_tuple, dds)) -def test_comp_list(mock_cli_config, catalog=None): +def test_comp_list(mock_cli_config, mock_db_url, catalog=None): '''Tests the list functionality of the catalog''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, enforce_image=False) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + enforce_image=False, db_url=mock_db_url) else: mc = catalog @@ -479,10 +483,11 @@ def test_comp_list(mock_cli_config, catalog=None): assert len(components) == 4 -def test_format_list(mock_cli_config, catalog=None): +def test_format_list(mock_cli_config, mock_db_url, catalog=None): '''Tests the list functionality of the catalog''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, enforce_image=False) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + enforce_image=False, db_url=mock_db_url) else: mc = catalog @@ -523,10 +528,11 @@ def test_format_list(mock_cli_config, catalog=None): assert len(formats) == 2 -def test_component_add_cdap(mock_cli_config, catalog=None): +def test_component_add_cdap(mock_cli_config, mock_db_url, catalog=None): '''Adds a mock CDAP application''' if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + db_url=mock_db_url) else: mc = catalog @@ -548,9 +554,9 @@ def test_component_add_cdap(mock_cli_config, catalog=None): assert _cdap_spec == spec_out -def test_get_discovery_from_spec(mock_cli_config): +def test_get_discovery_from_spec(mock_cli_config, mock_db_url): mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, - enforce_image=False) + enforce_image=False, db_url=mock_db_url) user = "test_get_discovery_from_spec" @@ -635,9 +641,10 @@ def test_get_discovery_from_spec(mock_cli_config): assert actual_dmaap_config_keys == ([], []) -def test_get_unpublished_formats(mock_cli_config, catalog=None): +def test_get_unpublished_formats(mock_cli_config, mock_db_url, catalog=None): if catalog is None: - mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, enforce_image=False) + mc = MockCatalog(db_name='dcae_cli.test.db', purge_existing=True, + enforce_image=False, db_url=mock_db_url) else: mc = catalog diff --git a/dcae-cli/dcae_cli/commands/tests/test_component_cmd.py b/dcae-cli/dcae_cli/commands/tests/test_component_cmd.py index 96f99de..67769eb 100644 --- a/dcae-cli/dcae_cli/commands/tests/test_component_cmd.py +++ b/dcae-cli/dcae_cli/commands/tests/test_component_cmd.py @@ -39,9 +39,10 @@ def _get_spec(path): return json.load(file) -def test_comp_docker(mock_cli_config, obj=None): +def test_comp_docker(mock_cli_config, mock_db_url, obj=None): - obj = {'catalog': MockCatalog(purge_existing=True, db_name='dcae_cli.test.db', enforce_image=False), + obj = {'catalog': MockCatalog(purge_existing=True, db_name='dcae_cli.test.db', + enforce_image=False, db_url=mock_db_url), 'config': {'user': 'test-user'}} df_kpi = os.path.join(TEST_DIR, 'mocked_components', 'collector', 'vnf-kpi.format.json') diff --git a/dcae-cli/dcae_cli/commands/tests/test_data_format_cmd.py b/dcae-cli/dcae_cli/commands/tests/test_data_format_cmd.py index 9a71e41..a291a74 100644 --- a/dcae-cli/dcae_cli/commands/tests/test_data_format_cmd.py +++ b/dcae-cli/dcae_cli/commands/tests/test_data_format_cmd.py @@ -40,9 +40,9 @@ def _get_spec(path): return json.load(file) -def test_basic(mock_cli_config): - - obj = {'catalog': MockCatalog(purge_existing=True, db_name='dcae_cli.test.db', enforce_image=False), +def test_basic(mock_cli_config, mock_db_url, tmpdir): + obj = {'catalog': MockCatalog(purge_existing=True, db_name='dcae_cli.test.db', + enforce_image=False, db_url=mock_db_url), 'config': {'user': 'test-user'}} runner = CliRunner() diff --git a/dcae-cli/dcae_cli/commands/tests/test_profiles_cmd.py b/dcae-cli/dcae_cli/commands/tests/test_profiles_cmd.py index 4380b13..be89722 100644 --- a/dcae-cli/dcae_cli/commands/tests/test_profiles_cmd.py +++ b/dcae-cli/dcae_cli/commands/tests/test_profiles_cmd.py @@ -34,12 +34,12 @@ from dcae_cli.util import profiles from dcae_cli.util import config -def test_basic(monkeypatch, tmpdir): +def test_basic(monkeypatch, tmpdir, mock_db_url): runner = CliRunner() # Setup config - test_db_url = "sqlite:///{0}/dcae_cli.db".format(util.get_app_dir()) + test_db_url = mock_db_url config_dict = { "user": "ninny", "active_profile": "fake-solutioning", "db_url": test_db_url, "cli_version": "2.0.0" } config_file = tmpdir.join("config.json") diff --git a/dcae-cli/dcae_cli/conftest.py b/dcae-cli/dcae_cli/conftest.py index 5df4cc7..7a00732 100644 --- a/dcae-cli/dcae_cli/conftest.py +++ b/dcae-cli/dcae_cli/conftest.py @@ -56,3 +56,13 @@ def mock_cli_config(monkeypatch): monkeypatch.setattr(dcae_cli.util.config, "get_config", fake_get_config) monkeypatch.setattr(dcae_cli.util.profiles, "get_profiles", fake_get_profiles) + +@pytest.fixture +def mock_db_url(tmpdir): + """Fixture to provide mock db url + + This url is intended to be the location of where to place the local sqlite + databases for each unit test""" + dbname="dcae_cli.test.db" + config_dir = tmpdir.mkdir("config") + return "/".join(["sqlite://", str(config_dir), dbname]) |