mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 13:43:12 +00:00
33 lines
930 B
Python
33 lines
930 B
Python
|
|
"""Tests for shared.secrets — Secrets Manager fetch + client caching."""
|
||
|
|
|
||
|
|
import boto3
|
||
|
|
import pytest
|
||
|
|
from moto import mock_aws
|
||
|
|
|
||
|
|
import shared.secrets as secrets
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(autouse=True)
|
||
|
|
def _reset_client():
|
||
|
|
# The module caches a module-level client; reset around each test so a
|
||
|
|
# client created under one moto context doesn't leak into another.
|
||
|
|
secrets._client = None
|
||
|
|
yield
|
||
|
|
secrets._client = None
|
||
|
|
|
||
|
|
|
||
|
|
def test_get_secret_returns_secret_string():
|
||
|
|
with mock_aws():
|
||
|
|
sm = boto3.client("secretsmanager", region_name="us-east-1")
|
||
|
|
sm.create_secret(
|
||
|
|
Name="afterhours-shift-manager/3cx-domain", SecretString="x.3cx.us"
|
||
|
|
)
|
||
|
|
assert secrets.get_secret("afterhours-shift-manager/3cx-domain") == "x.3cx.us"
|
||
|
|
|
||
|
|
|
||
|
|
def test_get_client_is_cached():
|
||
|
|
with mock_aws():
|
||
|
|
first = secrets._get_client()
|
||
|
|
second = secrets._get_client()
|
||
|
|
assert first is second
|