|
17 | 17 | init_app_with_options, |
18 | 18 | json_authenticate, |
19 | 19 | logout, |
| 20 | + is_authenticated, |
20 | 21 | ) |
21 | 22 |
|
22 | 23 | from flask_security import Security, UserMixin, user_registered, user_not_registered |
@@ -578,13 +579,15 @@ def test_username(app, clients, get_message): |
578 | 579 | "/login", json=dict(username="dude", password="awesome sunset") |
579 | 580 | ) |
580 | 581 | assert response.status_code == 200 |
| 582 | + assert is_authenticated(client, get_message) |
581 | 583 | logout(client) |
582 | 584 |
|
583 | 585 | # login with email |
584 | 586 | response = client.post( |
585 | 587 | "/login", json=dict(email="dude@lp.com", password="awesome sunset") |
586 | 588 | ) |
587 | 589 | assert response.status_code == 200 |
| 590 | + assert is_authenticated(client, get_message) |
588 | 591 | logout(client) |
589 | 592 |
|
590 | 593 | response = client.post( |
@@ -621,6 +624,29 @@ def test_username(app, clients, get_message): |
621 | 624 | ) |
622 | 625 |
|
623 | 626 |
|
| 627 | +@pytest.mark.settings(username_enable=True) |
| 628 | +def test_username_not_set(app, client, get_message): |
| 629 | + # login with null username - shouldn't match |
| 630 | + # note that this is caught at LoginForm - it doesn't force a DB call |
| 631 | + response = client.post( |
| 632 | + "/register", |
| 633 | + json=dict( |
| 634 | + email="justemail@lp.com", |
| 635 | + username="", |
| 636 | + password="awesome sunset", |
| 637 | + password_confirm="awesome sunset", |
| 638 | + ), |
| 639 | + ) |
| 640 | + assert response.status_code == 200 |
| 641 | + client.post("/logout") |
| 642 | + response = client.post("/login", json=dict(username="", password="awesome sunset")) |
| 643 | + assert response.status_code == 400 |
| 644 | + assert ( |
| 645 | + get_message("USER_DOES_NOT_EXIST") |
| 646 | + == response.json["response"]["field_errors"][""][0].encode() |
| 647 | + ) |
| 648 | + |
| 649 | + |
624 | 650 | @pytest.mark.settings(username_enable=True) |
625 | 651 | def test_username_template(app, client): |
626 | 652 | # verify template displays username option |
|
0 commit comments