test_fake_partition_service.py 1.1 KB
Newer Older
Luc Yriarte's avatar
Luc Yriarte committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pytest
from azure.keyvault.secrets import KeyVaultSecret

from mock import patch, Mock

from osdu_az.partition.partition_info import PartitionInfo
from osdu_az.partition.partition_service import PartitionService


@pytest.fixture
async def partition_service(monkeypatch) -> PartitionService:
    monkeypatch.setenv('USE_PARTITION_SERVICE', 'disabled')
    yield PartitionService()
    PartitionService.partition_client = None


@pytest.fixture
async def partition_info() -> PartitionInfo:
    with patch.object(PartitionInfo, '_get_secret', Mock()):
        yield PartitionInfo()


@pytest.mark.asyncio
async def test_get_partition_info_with_fakes(partition_info, partition_service):
    partition_info._get_secret.return_value = KeyVaultSecret('opendes-storage', 'single-partition-storage-account-name')
    assert await PartitionService.get_storage_account_name('opendes') == 'single-partition-storage-account-name'


@pytest.mark.asyncio
async def test_get_invalid_partition_info_with_fakes(partition_info, partition_service):
    assert await PartitionService.get_storage_account_name('invalid-partition-id') is None