-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
45 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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
|
||
def noop_filter_user_data(request, user, user_data): | ||
return user_data | ||
|
||
|
||
@pytest.fixture | ||
def disable_user_data_filters(): | ||
pass | ||
with patch("misago.oauth2.validation.filter_user_data", noop_filter_user_data): | ||
yield |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from unittest.mock import Mock, patch | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
|
@@ -92,29 +92,20 @@ def test_user_is_created_with_admin_activation_from_valid_data(db, dynamic_setti | |
assert user.requires_activation == User.ACTIVATION_ADMIN | ||
|
||
|
||
def user_noop_filter(*args): | ||
pass | ||
|
||
|
||
def test_user_name_conflict_during_creation_from_valid_data_is_handled( | ||
user, dynamic_settings | ||
user, dynamic_settings, disable_user_data_filters | ||
): | ||
with pytest.raises(OAuth2UserDataValidationError) as excinfo: | ||
# Custom filters disable build in filters | ||
with patch( | ||
"misago.oauth2.validation.oauth2_user_data_filters", | ||
[user_noop_filter], | ||
): | ||
get_user_from_data( | ||
Mock(settings=dynamic_settings, user_ip="83.0.0.1"), | ||
{ | ||
"id": "1234", | ||
"name": user.username, | ||
"email": "[email protected]", | ||
"avatar": None, | ||
}, | ||
{}, | ||
) | ||
get_user_from_data( | ||
Mock(settings=dynamic_settings, user_ip="83.0.0.1"), | ||
{ | ||
"id": "1234", | ||
"name": user.username, | ||
"email": "[email protected]", | ||
"avatar": None, | ||
}, | ||
{}, | ||
) | ||
|
||
assert excinfo.value.error_list == [ | ||
"Your username returned by the provider is not available for use on this site." | ||
|
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from unittest.mock import Mock, patch | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
|
@@ -72,31 +72,22 @@ def test_user_is_not_updated_with_unchanged_valid_data(user, dynamic_settings): | |
assert user_by_email.id == user.id | ||
|
||
|
||
def user_noop_filter(*args): | ||
pass | ||
|
||
|
||
def test_user_name_conflict_during_update_with_valid_data_is_handled( | ||
user, other_user, dynamic_settings | ||
user, other_user, dynamic_settings, disable_user_data_filters | ||
): | ||
Subject.objects.create(sub="1234", user=user) | ||
|
||
with pytest.raises(OAuth2UserDataValidationError) as excinfo: | ||
# Custom filters disable build in filters | ||
with patch( | ||
"misago.oauth2.validation.oauth2_user_data_filters", | ||
[user_noop_filter], | ||
): | ||
get_user_from_data( | ||
Mock(settings=dynamic_settings, user_ip="83.0.0.1"), | ||
{ | ||
"id": "1234", | ||
"name": other_user.username, | ||
"email": "[email protected]", | ||
"avatar": None, | ||
}, | ||
{}, | ||
) | ||
get_user_from_data( | ||
Mock(settings=dynamic_settings, user_ip="83.0.0.1"), | ||
{ | ||
"id": "1234", | ||
"name": other_user.username, | ||
"email": "[email protected]", | ||
"avatar": None, | ||
}, | ||
{}, | ||
) | ||
|
||
assert excinfo.value.error_list == [ | ||
"Your username returned by the provider is not available " | ||
|