@@ -36,7 +36,7 @@ def test_email_verification_rate_limits_login(
3636 content_type = "application/json" ,
3737 )
3838 if attempt == 0 :
39- assert resp .status_code == 401
39+ assert resp .status_code == HTTPStatus . UNAUTHORIZED
4040 flow = [
4141 flow for flow in resp .json ()["data" ]["flows" ] if flow .get ("is_pending" )
4242 ][0 ]
@@ -80,7 +80,7 @@ def test_email_verification_rate_limits_submitting_codes(
8080 },
8181 content_type = "application/json" ,
8282 )
83- assert resp .status_code == 401
83+ assert resp .status_code == HTTPStatus . UNAUTHORIZED
8484 flow = [flow for flow in resp .json ()["data" ]["flows" ] if flow .get ("is_pending" )][0 ]
8585 assert flow ["id" ] == Flow .VERIFY_EMAIL
8686
@@ -134,7 +134,7 @@ def test_add_email(
134134 data = {"email" : new_email },
135135 content_type = "application/json" ,
136136 )
137- assert resp .status_code == 200
137+ assert resp .status_code == HTTPStatus . OK
138138
139139 # It's in the response, albeit unverified.
140140 assert len (resp .json ()["data" ]) == 2
@@ -162,7 +162,7 @@ def test_add_email(
162162 data = {"key" : code },
163163 content_type = "application/json" ,
164164 )
165- assert resp .status_code == 200
165+ assert resp .status_code == HTTPStatus . OK
166166 assert resp .json ()["data" ]["user" ]["email" ] == new_email
167167
168168 # ACCOUNT_CHANGE_EMAIL = True, so the other one is gone.
@@ -204,7 +204,7 @@ def test_signup_with_email_verification(
204204 },
205205 content_type = "application/json" ,
206206 )
207- assert resp .status_code == 401
207+ assert resp .status_code == HTTPStatus . UNAUTHORIZED
208208 assert User .objects .filter (email = email ).exists ()
209209 data = resp .json ()
210210 flow = next ((f for f in data ["data" ]["flows" ] if f .get ("is_pending" )))
@@ -215,14 +215,14 @@ def test_signup_with_email_verification(
215215 headless_reverse ("headless:account:verify_email" ),
216216 HTTP_X_EMAIL_VERIFICATION_KEY = code ,
217217 )
218- assert resp .status_code == 200
218+ assert resp .status_code == HTTPStatus . OK
219219 assert resp .json () == {
220220 "data" : {
221221 "email" : email ,
222222 "user" : ANY ,
223223 },
224224 "meta" : {"is_authenticating" : True },
225- "status" : 200 ,
225+ "status" : HTTPStatus . OK ,
226226 }
227227 resp = client .post (
228228 headless_reverse ("headless:account:verify_email" ),
@@ -232,7 +232,7 @@ def test_signup_with_email_verification(
232232 addr = EmailAddress .objects .get (email = email )
233233 assert addr .verified
234234
235- assert resp .status_code == 200
235+ assert resp .status_code == HTTPStatus . OK
236236 data = resp .json ()
237237 assert data ["meta" ]["is_authenticated" ]
238238
@@ -267,7 +267,7 @@ def test_resend_at_signup(
267267 },
268268 content_type = "application/json" ,
269269 )
270- assert resp .status_code == 401
270+ assert resp .status_code == HTTPStatus . UNAUTHORIZED
271271 assert User .objects .filter (email = email ).exists ()
272272 data = resp .json ()
273273 flow = next ((f for f in data ["data" ]["flows" ] if f .get ("is_pending" )))
@@ -278,7 +278,7 @@ def test_resend_at_signup(
278278 headless_reverse ("headless:account:verify_email" ),
279279 HTTP_X_EMAIL_VERIFICATION_KEY = code ,
280280 )
281- assert resp .status_code == 200
281+ assert resp .status_code == HTTPStatus . OK
282282 assert resp .json () == {
283283 "data" : {
284284 "email" : email ,
@@ -339,3 +339,41 @@ def test_add_resend_verify_email(
339339 content_type = "application/json" ,
340340 )
341341 assert EmailAddress .objects .filter (email = new_email , verified = True ).exists ()
342+
343+
344+ def test_remove_unverified_email (
345+ auth_client ,
346+ user ,
347+ email_factory ,
348+ headless_reverse ,
349+ settings ,
350+ get_last_email_verification_code ,
351+ mailoutbox ,
352+ ):
353+ settings .ACCOUNT_AUTHENTICATION_METHOD = "email"
354+ settings .ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True
355+ settings .ACCOUNT_CHANGE_EMAIL = True
356+ new_email = email_factory ()
357+
358+ # Let's add an email...
359+ resp = auth_client .post (
360+ headless_reverse ("headless:account:manage_email" ),
361+ data = {"email" : new_email },
362+ content_type = "application/json" ,
363+ )
364+ assert resp .status_code == HTTPStatus .OK
365+
366+ # It's in the response, albeit unverified.
367+ assert len (resp .json ()["data" ]) == 2
368+ email_map = {addr ["email" ]: addr for addr in resp .json ()["data" ]}
369+ assert not email_map [new_email ]["verified" ]
370+
371+ # Delete the pending email.
372+ resp = auth_client .delete (
373+ headless_reverse ("headless:account:manage_email" ),
374+ data = {"email" : new_email },
375+ content_type = "application/json" ,
376+ )
377+ assert resp .status_code == HTTPStatus .OK
378+ assert len (resp .json ()["data" ]) == 1
379+ assert new_email not in {addr ["email" ] for addr in resp .json ()["data" ]}
0 commit comments