import pytest
import datetime
from azure.identity import DefaultAzureCredential
from savcfg.keyvault import KeyVaultVars


@pytest.fixture
def vars():
    return KeyVaultVars("savia-development", DefaultAzureCredential(), uppercase=True)


class A_KeyVaultVars:
    def should_list_variables(self, vars):
        assert "TEST.CONFIG" in vars.list_vars()

    def should_not_read_not_found(self, vars):
        assert vars.read("no_exist") == ""

    def should_read(self, vars):
        assert vars.read("TEST.PRIMITIVE") == "1"

    def should_edit_variables(self, vars):
        value = int(datetime.datetime.now().timestamp() * 1000)
        vars.write("TEST.SET_VALUE", str(value))
        assert vars.read("TEST.SET_VALUE") == str(value)
