-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathlocustfile.py
More file actions
48 lines (40 loc) · 1.88 KB
/
Copy pathlocustfile.py
File metadata and controls
48 lines (40 loc) · 1.88 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
import os
import logging
logging.basicConfig(level=logging.INFO)
MAILSLURP_API_KEY = os.getenv("API_KEY")
if not MAILSLURP_API_KEY:
raise ValueError("API_KEY environment variable is not set")
#<gen>locust_email_test
from locust import HttpUser, task, between
import mailslurp_client
# Load test user sign up and email confirmation
class EmailSignUpLoadTest(HttpUser):
wait_time = between(1, 5)
@task
def sign_up_and_receive_email(self):
# configure mailslurp client config
configuration = mailslurp_client.Configuration()
configuration.api_key["x-api-key"] = MAILSLURP_API_KEY
with mailslurp_client.ApiClient(configuration) as api_client:
# create unique email account for a user
logging.info("Creating unique email account")
inbox_controller = mailslurp_client.InboxControllerApi(api_client)
inbox = inbox_controller.create_inbox_with_defaults()
# submit the email to our test application sign-up url
logging.info("Posting magic link request for %s", inbox.email_address)
response = self.client.post(
"/test-application/magic-link",
data={"emailAddress": inbox.email_address},
name="/magic-link"
)
response.raise_for_status()
# wait for email to be sent and received by account
logging.info("Waiting for email to be received")
wait_controller = mailslurp_client.WaitForControllerApi(api_client)
email = wait_controller.wait_for_latest_email(
inbox_id=inbox.id, timeout=60_000, unread_only=True
)
# confirm email has correct information
logging.info("Received email with subject: %s", email.subject)
assert email.subject == "Please confirm your email address", "Magic‑link email has subject"
#</gen>