diff --git a/tests/conftest.py b/tests/conftest.py index 75cad67e4..a875ada97 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -64,9 +64,19 @@ def mock_store_client(): return client +@pytest.fixture() +def mock_store_anonymous_client() -> mock.Mock: + return mock.Mock(spec_set=store.AnonymousClient) + + @pytest.fixture() def service_factory( - fs, fake_project_dir, fake_prime_dir, simple_charm, mock_store_client + fs, + fake_project_dir, + fake_prime_dir, + simple_charm, + mock_store_client, + mock_store_anonymous_client, ) -> services.CharmcraftServiceFactory: factory = services.CharmcraftServiceFactory(app=APP_METADATA) @@ -78,6 +88,7 @@ def service_factory( factory.project = simple_charm factory.store.client = mock_store_client + factory.store.anonymous_client = mock_store_anonymous_client return factory diff --git a/tests/unit/commands/test_store.py b/tests/unit/commands/test_store.py index fe69d988a..774b3b376 100644 --- a/tests/unit/commands/test_store.py +++ b/tests/unit/commands/test_store.py @@ -164,7 +164,7 @@ def test_fetch_libs_no_charm_libs( Could not find the following libraries on charmhub: - lib: mysql.mysql version: '1' - - lib: some_charm.lib + - lib: some-charm.lib version: '1.2' """ ), @@ -173,7 +173,7 @@ def test_fetch_libs_no_charm_libs( ) def test_fetch_libs_missing_from_store(service_factory, libs, expected): service_factory.project.charm_libs = libs - service_factory.store.client.fetch_libraries_metadata.return_value = [] + service_factory.store.anonymous_client.fetch_libraries_metadata.return_value = [] fetch_libs = FetchLibs({"app": APP_METADATA, "services": service_factory}) with pytest.raises(errors.CraftError) as exc_info: @@ -213,8 +213,8 @@ def test_fetch_libs_missing_from_store(service_factory, libs, expected): ) def test_fetch_libs_no_content(new_path, service_factory, libs, store_libs, dl_lib, expected): service_factory.project.charm_libs = libs - service_factory.store.client.fetch_libraries_metadata.return_value = store_libs - service_factory.store.client.get_library.return_value = dl_lib + service_factory.store.anonymous_client.fetch_libraries_metadata.return_value = store_libs + service_factory.store.anonymous_client.get_library.return_value = dl_lib fetch_libs = FetchLibs({"app": APP_METADATA, "services": service_factory}) with pytest.raises(errors.CraftError, match=expected) as exc_info: @@ -254,10 +254,10 @@ def test_fetch_libs_no_content(new_path, service_factory, libs, store_libs, dl_l ) def test_fetch_libs_success( new_path, emitter, service_factory, libs, store_libs, dl_lib, expected -): +) -> None: service_factory.project.charm_libs = libs - service_factory.store.client.fetch_libraries_metadata.return_value = store_libs - service_factory.store.client.get_library.return_value = dl_lib + service_factory.store.anonymous_client.fetch_libraries_metadata.return_value = store_libs + service_factory.store.anonymous_client.get_library.return_value = dl_lib fetch_libs = FetchLibs({"app": APP_METADATA, "services": service_factory}) fetch_libs.run(argparse.Namespace()) diff --git a/tests/unit/services/test_store.py b/tests/unit/services/test_store.py index ec4730d07..540b6629d 100644 --- a/tests/unit/services/test_store.py +++ b/tests/unit/services/test_store.py @@ -35,6 +35,7 @@ def store(service_factory) -> services.StoreService: store = services.StoreService(app=application.APP_METADATA, services=service_factory) store.client = mock.Mock(spec_set=client.Client) + store.anonymous_client = mock.Mock(spec_set=client.AnonymousClient) return store @@ -232,11 +233,11 @@ def test_get_credentials(monkeypatch, store): ([], []), ( [CharmLib(lib="my_charm.my_lib", version="1")], - [{"charm-name": "my_charm", "library-name": "my_lib", "api": 1}], + [{"charm-name": "my-charm", "library-name": "my_lib", "api": 1}], ), ( [CharmLib(lib="my_charm.my_lib", version="1.0")], - [{"charm-name": "my_charm", "library-name": "my_lib", "api": 1, "patch": 0}], + [{"charm-name": "my-charm", "library-name": "my_lib", "api": 1, "patch": 0}], ), ], ) @@ -244,4 +245,4 @@ def test_fetch_libraries_metadata(monkeypatch, store, libs, expected_call): store.get_libraries_metadata(libs) - store.client.fetch_libraries_metadata.assert_called_once_with(expected_call) + store.anonymous_client.fetch_libraries_metadata.assert_called_once_with(expected_call)