Skip to content

Commit a34800d

Browse files
committed
Fun trick: If your regex fails to capture all the key generations cases, it will fail intermittently - not consistantly.
1 parent 42adb08 commit a34800d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

project/userauth/tests.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,25 @@ def test_verify_email_path_get(self):
118118
def test_verify_email_path_post(self):
119119

120120
# start by registering a user
121-
reg_url = '/api/v1/auth/registration/'
122-
reg_data = {
121+
new_user_reg_url = '/api/v1/auth/registration/'
122+
new_user_reg_data = {
123123
"username": self.user['username'],
124124
"email": self.user['email'],
125125
"password1": self.user['password1'],
126126
"password2": self.user['password2']
127127
}
128-
response = self.client.post(reg_url, reg_data, format='json')
128+
response = self.client.post(new_user_reg_url, new_user_reg_data, format='json')
129129

130130
# grab email from outbox so we can extract the verification link
131131
email_message = mail.outbox[0]
132132
verify_email_message = email_message.body
133133

134134
# extracting what we need for the verification post action
135-
uri_regex = re.compile(r"(\/api\/v1\/auth\/registration\/verify-email\/)(\?key=)([\w:]+)")
135+
uri_regex = re.compile(r"(\/api\/v1\/auth\/registration\/verify-email\/)(\?key=)([\w:-]+)")
136136
confirmation_uri = re.search(uri_regex, verify_email_message)
137137

138138
# now, let's post the key to trigger validation
139-
validate_email_url = f'/api/v1/auth/registration/verify-email/?key={confirmation_uri[3]}/'
139+
validate_email_url = f'{confirmation_uri[0]}'
140140
validate_key_data = {"key": confirmation_uri[3]}
141141
validation_response = self.client.post(validate_email_url, validate_key_data, format='json')
142142
print(validation_response)
@@ -172,6 +172,7 @@ def test_verify_email_marked_valid_after_post(self):
172172
key_data = {"key": confirmation_uri[3]}
173173
response = self.client.post(email_url, key_data, format='json')
174174

175+
175176
#did the post succeed in marking the email as valid in the DB?
176177
model = get_user_model()
177178
email_to_verify = EmailAddress.objects.get(email=reg_data['email'])

0 commit comments

Comments
 (0)