Skip to content

Commit

Permalink
Try again to connect the mock tahoe-idp user sync receivers for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlandia committed Jun 27, 2023
1 parent a231332 commit ee68b8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from social_django.models import UserSocialAuth

from django.db.models.signals import post_save
from django.urls import reverse
from django.contrib.auth import get_user_model
from rest_framework.test import APITestCase
Expand Down Expand Up @@ -64,7 +65,7 @@ def deactivate_user(self, color, username=None):
})
return response

@patch('tahoe_idp.receivers.user_sync_to_idp') # no-op
@patch('tahoe_idp.receivers.user_sync_to_idp')
@patch('tahoe_idp.api.get_tahoe_idp_id_by_user')
@patch('tahoe_idp.api.deactivate_user')
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_TAHOE_IDP': True})
Expand All @@ -77,6 +78,10 @@ def test_disallow_email_reuse_after_deactivate(
social_auth_uid = 'e1ede4d8-f6f6-11ec-9eb7-f778f1c67e22'
mock_get_tahoe_idp_id_by_user.return_value = social_auth_uid

# mock out receivers which rely on a real Tenant Id
post_save.connect(mock_user_sync_to_idp, sender=User, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')
post_save.connect(mock_user_sync_to_idp, sender=UserProfile, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')

with with_organization_context(site_color=self.RED):
register_res = self.register_user(self.RED)
assert register_res.status_code == status.HTTP_200_OK, register_res.content.decode('utf-8')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from django.core import mail
from django.db.models.signals import post_save
from django.test import RequestFactory, TestCase
from unittest.mock import Mock, patch
from openedx.core.djangoapps.user_authn.views.password_reset import password_reset
Expand Down Expand Up @@ -42,6 +43,11 @@ def test_reset_password_with_tahoe_idp(self, mock_request_password_reset, mock_u
req.site = Mock(domain='example.com')
req.user = user

# mock out receivers which rely on a real Tenant Id
post_save.connect(mock_user_sync_to_idp, sender=User, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')
post_save.connect(mock_user_sync_to_idp, sender=UserProfile, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')


with patch.dict(settings.FEATURES, {'ENABLE_TAHOE_IDP': enable_tahoe_idp}):
with patch('crum.get_current_request', return_value=req):
response = password_reset(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ddt
from mock import patch

from django.db.models.signals import post_save
from django.urls import reverse_lazy
from rest_framework import status
from rest_framework.test import APITestCase
Expand Down Expand Up @@ -61,6 +62,10 @@ def test_api_wit_tahoe_idp(self, mock_user_sync_to_idp, url):
"""
Both v1 and v2 API shouldn't work with Tahoe IdP.
"""

post_save.connect(mock_user_sync_to_idp, sender=User, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')
post_save.connect(mock_user_sync_to_idp, sender=UserProfile, dispatch_uid='tahoe_idp.receivers.user_sync_to_idp')

color1 = 'red1'
with with_organization_context(site_color=color1):
response = self.register_user(url, 'red_learner')
Expand Down

0 comments on commit ee68b8f

Please sign in to comment.