Skip to content

Commit

Permalink
@W-14603959 - code refactoring to fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbharath committed Dec 5, 2023
1 parent 9eb9ec9 commit b5c769d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions metecho/oauth2/salesforce/tests/provider.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
from ..provider import CustomSalesforceProvider
from allauth.socialaccount.models import SocialApp
import pytest

@pytest.fixture
def dummy_app():
app = SocialApp.objects.create(
provider=CustomSalesforceProvider.id,
name=CustomSalesforceProvider.id,
client_id="app123id",
key=CustomSalesforceProvider.id,
secret="dummy",
)
return app

def test_get_auth_params(rf):
@pytest.mark.django_db
def test_get_auth_params(rf, dummy_app):
request = rf.get("/")
result = CustomSalesforceProvider(request).get_auth_params(request, None)
result = CustomSalesforceProvider(request, dummy_app).get_auth_params(request, None)
assert "prompt" in result and result["prompt"] == "login"


def test_extract_uid(rf):
@pytest.mark.django_db
def test_extract_uid(rf, dummy_app):
request = rf.get("/")
provider = CustomSalesforceProvider(request)
provider = CustomSalesforceProvider(request, dummy_app)
result = provider.extract_uid({"organization_id": "ORG", "user_id": "USER"})
assert result == "ORG/USER"
2 changes: 1 addition & 1 deletion metecho/oauth2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ensure_socialapp_in_db(token):
unless we create them here.
"""
if token.app.pk is None:
provider = providers.registry.by_id(token.app.provider)
provider = providers.registry.get_class(token.app.provider)
app, created = SocialApp.objects.get_or_create(
provider=provider.id,
name=provider.name,
Expand Down

0 comments on commit b5c769d

Please sign in to comment.