test_azure_5.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. def test_get_remote_config(self, mocker: MockFixture, azure_layer: Mock) -> None:
  2. mocked_creds = mocker.Mock()
  3. mocked_default_creds = mocker.patch(
  4. "opta.core.azure.DefaultAzureCredential", return_value=mocked_creds
  5. )
  6. mocked_container_client_instance = mocker.Mock()
  7. mocked_container_client_instance.download_blob = mocker.Mock()
  8. download_stream_mock = mocker.Mock()
  9. download_stream_mock.readall = mocker.Mock(
  10. return_value='{"opta_version":"1", "date": "mock_date", "original_spec": "mock_spec", "defaults": {}}'
  11. )
  12. mocked_container_client_instance.download_blob.return_value = download_stream_mock
  13. mocked_container_client = mocker.patch(
  14. "opta.core.azure.ContainerClient",
  15. return_value=mocked_container_client_instance,
  16. )
  17. mocked_structured_config: StructuredConfig = {
  18. "opta_version": "1",
  19. "date": "mock_date",
  20. "original_spec": "mock_spec",
  21. "defaults": {},
  22. }
  23. assert Azure(azure_layer).get_remote_config() == mocked_structured_config
  24. azure_layer.gen_providers.assert_called_once_with(0)
  25. mocked_default_creds.assert_called_once_with()
  26. mocked_container_client.assert_called_once_with(
  27. account_url="https://dummy_storage_account.blob.core.windows.net",
  28. container_name="dummy_container_name",
  29. credential=mocked_creds,
  30. )
  31. mocked_container_client_instance.download_blob.assert_called_once_with(
  32. f"opta_config/{azure_layer.name}"
  33. )