-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate uidb64 and token for a test user in a fixture
- Loading branch information
1 parent
ee4c843
commit c904b31
Showing
1 changed file
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ def mock_respx_post_to_sib_smtp_url_fixture(): | |
yield | ||
|
||
|
||
@pytest.fixture(name="user_token") | ||
def user_token_fixture(): | ||
user = UserFactory(first_name="Samuel", last_name="Jackson", email="[email protected]") | ||
uidb64 = urlsafe_base64_encode(force_bytes(user.pk)) | ||
token = default_token_generator.make_token(user) | ||
return user, uidb64, token | ||
|
||
|
||
class ForumProfileUpdateViewTest(TestCase): | ||
def test_success_url(self): | ||
forum_profiles = ForumProfileFactory() | ||
|
@@ -177,30 +185,25 @@ def test_user_not_found(self, client, db): | |
assert response.status_code == 302 | ||
assert response.url == reverse("members:login") | ||
|
||
def test_invalid_token(self, client, db): | ||
user = UserFactory() | ||
uidb64 = urlsafe_base64_encode(force_bytes(user.pk)) | ||
response = client.get(reverse("members:login_with_link", kwargs={"uidb64": uidb64, "token": "token"})) | ||
def test_invalid_token(self, client, db, user_token): | ||
user, uidb64, token = user_token | ||
response = client.get(reverse("members:login_with_link", kwargs={"uidb64": uidb64, "token": "invalid_token"})) | ||
assert response.status_code == 302 | ||
assert response.url == reverse("members:login") | ||
|
||
def test_expired_token(self, client, db): | ||
user = UserFactory() | ||
uidb64 = urlsafe_base64_encode(force_bytes(user.pk)) | ||
expired_token = default_token_generator.make_token(user) | ||
def test_expired_token(self, client, db, user_token): | ||
user, uidb64, token = user_token | ||
|
||
client.force_login(user) | ||
# force logout | ||
client.session.flush() | ||
|
||
response = client.get(reverse("members:login_with_link", kwargs={"uidb64": uidb64, "token": expired_token})) | ||
response = client.get(reverse("members:login_with_link", kwargs={"uidb64": uidb64, "token": token})) | ||
assert response.status_code == 302 | ||
assert response.url == reverse("members:login") | ||
|
||
def test_success(self, client, db): | ||
user = UserFactory() | ||
uidb64 = urlsafe_base64_encode(force_bytes(user.pk)) | ||
token = default_token_generator.make_token(user) | ||
def test_success(self, client, db, user_token): | ||
user, uidb64, token = user_token | ||
next_url = "/topics/" | ||
|
||
response = client.get( | ||
|
@@ -210,6 +213,16 @@ def test_success(self, client, db): | |
assert response.url == next_url | ||
assert client.session.get(IdentityProvider.MAGIC_LINK.name) == 1 | ||
|
||
def test_unallowed_next_url(self, client, db, user_token): | ||
user, uidb64, token = user_token | ||
next_url = "http://www.unallowed_host.com" | ||
|
||
response = client.get( | ||
reverse("members:login_with_link", kwargs={"uidb64": uidb64, "token": token}), data={"next": next_url} | ||
) | ||
assert response.status_code == 302 | ||
assert response.url == "/" | ||
|
||
|
||
class TestLogoutView: | ||
@pytest.mark.parametrize( | ||
|