-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_config.py
More file actions
55 lines (42 loc) · 2.26 KB
/
test_config.py
File metadata and controls
55 lines (42 loc) · 2.26 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import pytest
from yarl import URL
from eligibility_signposting_api.config.config import LOG_LEVEL, AwsAccessKey, AwsRegion, AwsSecretAccessKey, config
from eligibility_signposting_api.config.constants import STATUS_TEXT_OVERRIDE_ACTION_TYPE
from eligibility_signposting_api.repos.campaign_repo import BucketName
from eligibility_signposting_api.repos.person_repo import TableName
@pytest.fixture(autouse=True)
def clear_config_cache(monkeypatch):
config.cache_clear()
monkeypatch.delenv("ENV", raising=False)
def test_config_with_env_variable(monkeypatch):
# Given:
monkeypatch.setenv("ENV", "PROD")
# When:
config_data_with_env = config()
# Then:
assert os.getenv("ENV") == "PROD"
assert config_data_with_env["aws_access_key_id"] is None
assert config_data_with_env["aws_secret_access_key"] is None
assert config_data_with_env["aws_default_region"] == AwsRegion("eu-west-1")
assert config_data_with_env["dynamodb_endpoint"] is None
assert config_data_with_env["person_table_name"] == TableName("test_eligibility_datastore")
assert config_data_with_env["s3_endpoint"] is None
assert config_data_with_env["rules_bucket_name"] == BucketName("test-rules-bucket")
assert config_data_with_env["log_level"] == LOG_LEVEL
def test_config_without_env_variable():
# Given: The environment variable "ENV" isn't set
# When:
config_data_without_env = config()
# Then:
assert os.getenv("ENV") is None
assert config_data_without_env["aws_access_key_id"] == AwsAccessKey("dummy_key")
assert config_data_without_env["aws_secret_access_key"] == AwsSecretAccessKey("dummy_secret")
assert config_data_without_env["aws_default_region"] == AwsRegion("eu-west-1")
assert config_data_without_env["dynamodb_endpoint"] == URL("http://localhost:4566")
assert config_data_without_env["person_table_name"] == TableName("test_eligibility_datastore")
assert config_data_without_env["s3_endpoint"] == URL("http://localhost:4566")
assert config_data_without_env["rules_bucket_name"] == BucketName("test-rules-bucket")
assert config_data_without_env["log_level"] == LOG_LEVEL
def test_status_text_override_action_type_constant_value():
assert STATUS_TEXT_OVERRIDE_ACTION_TYPE == "norender_StatusTextOverride"