Browse Source

Rename google provider to google-oauth2 (#1323)

* Fix #1321: rename google provider to google-oauth2

* Fix admin tests failing

* Format code with new black
Rafał Pitoń 5 years ago
parent
commit
e42a479fa9

+ 2 - 2
misago/admin/tests/test_admin_system_checks.py

@@ -168,7 +168,7 @@ def test_warning_about_unset_forum_address_is_displayed_on_checks_list(admin_cli
 
 @override_dynamic_settings(forum_address=incorrect_address)
 def test_warning_about_incorrect_forum_address_is_displayed_on_checks_list(
-    admin_client
+    admin_client,
 ):
     response = admin_client.get(admin_link)
     assert_contains(response, "address")
@@ -201,7 +201,7 @@ def test_https_check_fails_if_site_is_accessed_without_https(mocker):
 
 
 def test_warning_about_accessing_site_without_https_is_displayed_on_checks_list(
-    admin_client
+    admin_client,
 ):
     response = admin_client.get(admin_link)
     assert_contains(response, "site is not running over HTTPS")

+ 1 - 1
misago/admin/tests/test_authorization.py

@@ -97,7 +97,7 @@ def test_updating_authorization_validates_authorization(admin_request):
 
 
 def test_removing_authorization_removes_autorization_from_request_session(
-    admin_request
+    admin_request,
 ):
     admin_request.session[UPDATED_KEY] = 0
     remove_admin_authorization(admin_request)

+ 1 - 1
misago/core/tests/test_cursor_pagination.py

@@ -48,7 +48,7 @@ def test_requesting_next_page_filters_queryset_using_filter_name(mock_queryset):
 
 
 def test_requesting_next_page_for_reversed_order_filters_queryset_with_descending(
-    mock_queryset
+    mock_queryset,
 ):
     page = get_page(mock_queryset, "-post", 6, 7)
     mock_queryset.filter.assert_called_once_with(post__lte=7)

+ 1 - 1
misago/socialauth/admin/tests/conftest.py

@@ -18,5 +18,5 @@ def other_provider(db):
 @pytest.fixture
 def disabled_provider(db):
     return SocialAuthProvider.objects.create(
-        provider="google", is_active=False, order=0
+        provider="google-oauth2", is_active=False, order=0
     )

+ 10 - 6
misago/socialauth/admin/tests/test_google_form.py

@@ -4,12 +4,16 @@ from django.urls import reverse
 from ...models import SocialAuthProvider
 
 
-admin_link = reverse("misago:admin:settings:socialauth:edit", kwargs={"pk": "google"})
+admin_link = reverse(
+    "misago:admin:settings:socialauth:edit", kwargs={"pk": "google-oauth2"}
+)
 
 
 @pytest.fixture
 def provider(db):
-    return SocialAuthProvider.objects.create(provider="google", is_active=True, order=0)
+    return SocialAuthProvider.objects.create(
+        provider="google-oauth2", is_active=True, order=0
+    )
 
 
 def test_google_form_can_be_accessed(admin_client):
@@ -28,7 +32,7 @@ def test_google_login_can_be_setup(admin_client):
         },
     )
 
-    provider = SocialAuthProvider.objects.get(provider="google")
+    provider = SocialAuthProvider.objects.get(provider="google-oauth2")
     assert provider.is_active
     assert provider.settings == {
         "associate_by_email": 1,
@@ -40,7 +44,7 @@ def test_google_login_can_be_setup(admin_client):
 def test_google_login_can_be_disabled(admin_client, provider):
     admin_client.post(admin_link, {"is_active": "0"})
 
-    provider = SocialAuthProvider.objects.get(provider="google")
+    provider = SocialAuthProvider.objects.get(provider="google-oauth2")
     assert not provider.is_active
 
 
@@ -48,11 +52,11 @@ def test_google_login_form_requires_key_to_setup(admin_client):
     admin_client.post(admin_link, {"is_active": "1", "secret": "test-secret"})
 
     with pytest.raises(SocialAuthProvider.DoesNotExist):
-        SocialAuthProvider.objects.get(provider="google")
+        SocialAuthProvider.objects.get(provider="google-oauth2")
 
 
 def test_google_login_form_requires_secret_to_setup(admin_client):
     admin_client.post(admin_link, {"is_active": "1", "key": "test-key"})
 
     with pytest.raises(SocialAuthProvider.DoesNotExist):
-        SocialAuthProvider.objects.get(provider="google")
+        SocialAuthProvider.objects.get(provider="google-oauth2")

+ 1 - 1
misago/socialauth/apps.py

@@ -33,7 +33,7 @@ class MisagoSocialAuthConfig(AppConfig):
             admin_template="misago/admin/socialauth/form.html",
         )
         providers.add(
-            provider="google",
+            provider="google-oauth2",
             name="Google",
             auth_backend=GoogleOAuth2,
             admin_form=GoogleForm,

+ 17 - 0
misago/socialauth/migrations/0003_rename_google_to_google_oauth.py

@@ -0,0 +1,17 @@
+# Generated by Django 2.2.3 on 2019-11-10 14:32
+
+from django.db import migrations
+
+
+def rename_google_provider(apps, _):
+    SocialAuthProvider = apps.get_model("misago_socialauth", "SocialAuthProvider")
+    SocialAuthProvider.objects.filter(provider="google").update(
+        provider="google-oauth2"
+    )
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [("misago_socialauth", "0002_cache_version")]
+
+    operations = [migrations.RunPython(rename_google_provider)]

+ 6 - 0
misago/socialauth/providers.py

@@ -24,6 +24,12 @@ class Providers:
             "admin_template": admin_template,
         }
 
+        if provider != auth_backend.name:
+            raise ValueError(
+                f"Provider's key '{provider}' is not the same as backend's name "
+                f"attribute: '{auth_backend.name}'"
+            )
+
         self._dict[provider] = data
         self._list.append(data)
         self._list = sorted(self._list, key=lambda k: k["name"])

+ 1 - 1
misago/socialauth/tests/test_getting_enabled_providers.py

@@ -82,7 +82,7 @@ def test_enabled_providers_dict_includes_auth_backend(provider, mocker, cache_ve
 
 
 def test_provider_settings_keys_are_capitalized():
-    provider = Mock(pk="google", settings={"key": "text-key"})
+    provider = Mock(pk="google-oauth2", settings={"key": "text-key"})
     settings = get_provider_settings(provider)
     assert settings == {"KEY": "text-key"}
 

+ 25 - 4
misago/socialauth/tests/test_providers.py

@@ -1,13 +1,16 @@
-from unittest.mock import Mock
-
 import pytest
 
 from ..providers import Providers
 
 
+class Mock:
+    def __init__(self, name):
+        self.name = name
+
+
 @pytest.fixture
 def auth_backend():
-    return Mock()
+    return Mock(name="facebook")
 
 
 @pytest.fixture
@@ -57,8 +60,26 @@ def test_provider_can_be_added_to_providers(auth_backend):
     ]
 
 
+def test_adding_provider_fails_if_provider_key_is_different_from_backend_name(
+    auth_backend,
+):
+    providers = Providers()
+    with pytest.raises(ValueError):
+        providers.add(
+            provider="facebook-oauth",
+            name="Facebook",
+            auth_backend=auth_backend,
+            settings={"scope": ["email"]},
+            admin_form=True,
+            admin_template="form.html",
+        )
+
+    assert providers.dict() == {}
+    assert providers.list() == []
+
+
 def test_providers_list_is_resorted_when_new_provider_is_added(providers, auth_backend):
-    other_auth_backend = Mock()
+    other_auth_backend = Mock(name="auth")
     providers.add(
         provider="auth",
         name="Auth",

+ 2 - 2
misago/themes/tests/test_getting_active_theme.py

@@ -21,7 +21,7 @@ def test_if_active_theme_is_default_themes_child_include_defaults_flag_is_set(
 
 
 def test_if_active_theme_is_not_default_themes_child_include_defaults_flag_is_not_set(
-    active_theme
+    active_theme,
 ):
     assert not get_active_theme()["include_defaults"]
 
@@ -83,7 +83,7 @@ def test_active_theme_styles_list_contains_url_to_local_built_css(active_theme):
 
 
 def test_active_theme_styles_list_exclude_url_to_css_that_has_not_been_built(
-    active_theme
+    active_theme,
 ):
     active_theme.css.create(
         name="test",

+ 3 - 3
misago/threads/tests/test_attachments_middleware.py

@@ -49,7 +49,7 @@ def test_middleware_is_used_if_user_has_permission_to_upload_attachments(context
 
 
 def test_middleware_is_not_used_if_user_has_no_permission_to_upload_attachments(
-    context
+    context,
 ):
     context["user_acl"]["max_attachment_size"] = 0
     middleware = AttachmentsMiddleware(**context)
@@ -261,7 +261,7 @@ def test_middleware_deletes_attachment_removed_from_post(context):
 
 
 def test_middleware_blocks_user_from_removing_other_user_attachment_without_permission(
-    context
+    context,
 ):
     attachment = create_attachment(post=context["post"])
     middleware = AttachmentsMiddleware(
@@ -276,7 +276,7 @@ def test_middleware_blocks_user_from_removing_other_user_attachment_without_perm
 
 
 def test_middleware_allows_user_with_permission_to_remove_other_user_attachment(
-    context
+    context,
 ):
     context["user_acl"]["can_delete_other_users_attachments"] = True
     attachment = create_attachment(post=context["post"])

+ 1 - 1
misago/users/admin/tests/test_users.py

@@ -73,7 +73,7 @@ def test_new_user_can_be_created_with_whitespace_around_password(admin_client):
 
 
 def test_new_user_creation_fails_because_user_was_not_given_authenticated_role(
-    admin_client
+    admin_client,
 ):
     default_rank = Rank.objects.get_default()
     guest_role = Role.objects.get(special_role="anonymous")

+ 2 - 2
misago/users/tests/test_getting_user_status.py

@@ -18,7 +18,7 @@ class GetUserStatusTests(AuthenticatedUserTestCase):
         assert get_user_status(request, self.other_user)["is_online"]
 
     def test_get_hidden_user_status_without_seeing_hidden_permission_returns_offline(
-        self
+        self,
     ):
         """get_user_status has no showstopper for hidden user"""
         self.other_user.is_hiding_presence = True
@@ -32,7 +32,7 @@ class GetUserStatusTests(AuthenticatedUserTestCase):
         assert get_user_status(request, self.other_user)["is_hidden"]
 
     def test_get_hidden_user_status_with_seeing_hidden_permission_returns_online_hidden(
-        self
+        self,
     ):
         self.other_user.is_hiding_presence = True
         self.other_user.save()

+ 1 - 1
misago/users/tests/test_remove_old_ips_command.py

@@ -41,7 +41,7 @@ def test_old_user_joined_ip_is_removed_by_command(user_with_old_ip):
 
 @override_dynamic_settings(ip_storage_time=None)
 def test_old_user_joined_ip_is_not_removed_by_command_if_removal_is_disabled(
-    user_with_old_ip
+    user_with_old_ip,
 ):
     call_command(removeoldips.Command(), stdout=StringIO())
     user_with_old_ip.refresh_from_db()