-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.py
185 lines (171 loc) · 7.44 KB
/
config.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import os
import uuid
import pytest
def generate_unique_email(email, uuid):
parts = email.split("@")
return f"{parts[0]}+{uuid}@{parts[1]}"
# global variable
config = {
# static
"notification_retry_times": 15,
"notification_retry_interval": 5,
"pdf_generation_retry_times": 10,
"pdf_generation_retry_interval": 2,
"verify_callback_retry_times": 5,
"verify_callback_retry_interval": 0.5,
"letter_retry_times": 108,
"provider_retry_times": 12,
"provider_retry_interval": 22,
"verify_code_retry_times": 8,
"verify_code_retry_interval": 9,
"functional_test_service_name": "Functional Test Service_",
"letter_contact_data": {
"address_line_1": "test",
"address_line_2": "London",
"postcode": "N1 7RA",
},
# notify templates
"notify_templates": {
"email_auth_template_id": "299726d2-dba6-42b8-8209-30e1d66ea164",
"invitation_template_id": "4f46df42-f795-4cc4-83bb-65ca312f49cc",
"org_invitation_template_id": "203566f0-d835-47c5-aa06-932439c86573",
"password_reset_template_id": "474e9242-823b-4f99-813d-ed392e7f1201",
"registration_template_id": "ece42649-22a8-4d06-b87f-d52d5d3f0a27",
"verify_code_template_id": "36fb0730-6259-4da1-8a80-c8de22ad4246",
"request_invite_to_service_template_id": "77677459-f862-44ee-96d9-b8cb2323d407",
},
}
def setup_shared_config():
"""
Used by all tests
"""
env = os.environ["ENVIRONMENT"].lower()
urls = {
"dev": {
"api": os.environ.get("FUNCTIONAL_TESTS_LOCAL_API_HOST", "http://localhost:6011"),
"admin": os.environ.get("FUNCTIONAL_TESTS_LOCAL_ADMIN_HOST", "http://localhost:6012"),
},
"preview": {
"api": "https://api.notify.works",
"admin": "https://www.notify.works",
},
"staging": {
"api": "https://api.staging-notify.works",
"admin": "https://www.staging-notify.works",
},
"live": {
"api": "https://api.notifications.service.gov.uk",
"admin": "https://www.notifications.service.gov.uk",
},
}
if env not in {"dev", "preview", "staging", "live"}:
if not os.environ.get("FUNCTIONAL_TESTS_API_HOST") or not os.environ.get("FUNCTIONAL_TESTS_ADMIN_HOST"):
pytest.fail(
f'env "{env}" not one of dev, preview, staging, live, '
"so you need to set the environment variables FUNCTIONAL_TESTS_API_HOST "
"and FUNCTIONAL_TESTS_ADMIN_HOST"
)
config.update(
{
"env": env,
"notify_api_url": os.environ.get("FUNCTIONAL_TESTS_API_HOST"),
"notify_admin_url": os.environ.get("FUNCTIONAL_TESTS_ADMIN_HOST"),
}
)
if env.startswith("dev-"):
# dev environments may be slow, so increase retries
config.update(
{
"pdf_generation_retry_times": 40,
"verify_callback_retry_times": 40,
"verify_callback_retry_interval": 1,
}
)
else:
config.update(
{
"env": env,
"notify_api_url": urls[env]["api"],
"notify_admin_url": urls[env]["admin"],
}
)
def setup_preview_dev_config():
uuid_for_test_run = str(uuid.uuid4())
config.update(
{
"name": "{} Functional Tests".format(config["env"]),
"service_name": f"Functional Test_{uuid_for_test_run}",
"user": {
"name": "{}_Functional Test_{}".format(config["env"], uuid_for_test_run),
"email": generate_unique_email(os.environ["FUNCTIONAL_TEST_EMAIL"], uuid_for_test_run),
"password": os.environ["FUNCTIONAL_TEST_PASSWORD"],
"mobile": os.environ["TEST_NUMBER"],
},
"api_auth": {
"client_id": "notify-functional-tests",
"secret": os.environ["FUNCTIONAL_TESTS_API_AUTH_SECRET"],
},
"notify_service_api_key": os.environ["NOTIFY_SERVICE_API_KEY"],
"service": {
"id": os.environ["FUNCTIONAL_TESTS_SERVICE_ID"],
"name": os.environ["FUNCTIONAL_TESTS_SERVICE_NAME"],
"seeded_user": {
"email": os.environ["FUNCTIONAL_TESTS_SERVICE_EMAIL"],
"password": os.environ["FUNCTIONAL_TESTS_SERVICE_EMAIL_PASSWORD"],
"mobile": os.environ["FUNCTIONAL_TESTS_SERVICE_NUMBER"],
},
"api_live_key": os.environ["FUNCTIONAL_TESTS_SERVICE_API_KEY"],
"api_test_key": os.environ["FUNCTIONAL_TESTS_SERVICE_API_TEST_KEY"],
# email address of seeded email auth user
"email_auth_account": os.environ["FUNCTIONAL_TESTS_SERVICE_EMAIL_AUTH_ACCOUNT"],
"organisation_id": os.environ["FUNCTIONAL_TESTS_ORGANISATION_ID"],
"email_reply_to": os.environ["FUNCTIONAL_TESTS_SERVICE_EMAIL_REPLY_TO"],
"email_reply_to_2": os.environ.get("FUNCTIONAL_TESTS_SERVICE_EMAIL_REPLY_TO_2"),
"email_reply_to_3": os.environ.get("FUNCTIONAL_TESTS_SERVICE_EMAIL_REPLY_TO_3"),
"sms_sender_text": "func tests",
"templates": {
"email": os.environ["FUNCTIONAL_TEST_EMAIL_TEMPLATE_ID"],
"sms": os.environ["FUNCTIONAL_TEST_SMS_TEMPLATE_ID"],
"letter": os.environ["FUNCTIONAL_TEST_LETTER_TEMPLATE_ID"],
},
"inbound_number": os.environ["FUNCTIONAL_TESTS_SERVICE_INBOUND_NUMBER"],
},
"mmg_inbound_sms": {
"username": os.environ["MMG_INBOUND_SMS_USERNAME"],
"password": os.environ["MMG_INBOUND_SMS_AUTH"],
},
"pipedream": {
"api_token": os.environ["REQUEST_BIN_API_TOKEN"],
"source_id": "dc_bPuNxED",
},
}
)
def setup_staging_prod_config():
# staging and prod run the same simple smoke tests
config.update(
{
# the smoke tests send a CSV which might get stuck behind other jobs we allow
# these notifications to take longer (2m30s rather than the normal wait of 1m15s)
"smoke_test_csv_notification_retry_time": 30,
"name": "{} Functional Tests".format(config["env"]),
"user": {
"email": os.environ["FUNCTIONAL_TEST_EMAIL"],
"password": os.environ["FUNCTIONAL_TEST_PASSWORD"],
"mobile": os.environ["TEST_NUMBER"],
},
"notify_service_api_key": os.environ["NOTIFY_SERVICE_API_KEY"],
"service": {
"id": os.environ["SERVICE_ID"],
"api_live_key": os.environ["API_KEY"],
"api_test_key": os.environ["API_TEST_KEY"],
"email_auth_account": os.environ["FUNCTIONAL_TEST_EMAIL_AUTH"],
"seeded_user": {"password": os.environ["FUNCTIONAL_TEST_PASSWORD"]},
"templates": {
"email": os.environ["FUNCTIONAL_TEST_EMAIL_TEMPLATE_ID"],
"sms": os.environ["FUNCTIONAL_TEST_SMS_TEMPLATE_ID"],
# letter template not set up on staging and prod
},
"inbound_number": os.environ["PROVIDER_TEST_INBOUND_NUMBER"],
},
}
)