Skip to content

Commit

Permalink
Add tests for core.secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Dec 19, 2024
1 parent 8d76f36 commit 69f9695
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:
run: ruff check .
- name: Run tests
run: |
coverage run --include='src/**/*' -m unittest
coverage run --include='src/**/*' -m pytest
coverage report
env:
__SKIP_SECRETS__: true
AWS_REGION: us-east-1
3 changes: 1 addition & 2 deletions chat/src/core/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import json
import os

def load_secrets():
SecretsPath = os.getenv('SECRETS_PATH')
def load_secrets(SecretsPath=os.getenv('SECRETS_PATH')):
EnvironmentMap = [
['API_TOKEN_SECRET', 'dcapi', 'api_token_secret'],
['OPENSEARCH_ENDPOINT', 'index', 'endpoint'],
Expand Down
29 changes: 29 additions & 0 deletions chat/test/core/test_secrets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import boto3
import os
import pytest
from moto import mock_aws
from unittest import TestCase

from core.secrets import load_secrets

@mock_aws
@mock_aws
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
class TestSecrets(TestCase):
def setUp(self):
client = boto3.client("secretsmanager", region_name="us-east-1")
client.create_secret(
Name="mock/infrastructure/index",
SecretString='{"endpoint": "https://opensearch-endpoint", "embedding_model": "opensearch-model"}')
client.create_secret(
Name="mock/config/dcapi",
SecretString='{"api_token_secret": "dcapi-token"}')

def test_load_secrets(self):
self.assertNotEqual('dcapi-token', os.getenv('API_TOKEN_SECRET'))
self.assertNotEqual('https://opensearch-endpoint', os.getenv('OPENSEARCH_ENDPOINT'))
self.assertNotEqual('opensearch-model', os.getenv('OPENSEARCH_MODEL_ID'))
load_secrets('mock')
self.assertEqual('dcapi-token', os.getenv('API_TOKEN_SECRET'))
self.assertEqual('https://opensearch-endpoint', os.getenv('OPENSEARCH_ENDPOINT'))
self.assertEqual('opensearch-model', os.getenv('OPENSEARCH_MODEL_ID'))

0 comments on commit 69f9695

Please sign in to comment.