|
29 | 29 | )
|
30 | 30 | from openedx.features.enterprise_support.utils import (
|
31 | 31 | ENTERPRISE_HEADER_LINKS,
|
| 32 | + _user_has_social_auth_record, |
32 | 33 | clear_data_consent_share_cache,
|
33 | 34 | enterprise_fields_only,
|
34 | 35 | fetch_enterprise_customer_by_id,
|
@@ -539,6 +540,54 @@ def test_get_provider_login_url_with_redirect_url(self, mock_tpa, mock_next_logi
|
539 | 540 | )
|
540 | 541 | assert not mock_next_login_url.called
|
541 | 542 |
|
| 543 | + @mock.patch('openedx.features.enterprise_support.utils.UserSocialAuth') |
| 544 | + @mock.patch('openedx.features.enterprise_support.utils.third_party_auth') |
| 545 | + def test_user_has_social_auth_record(self, mock_tpa, mock_user_social_auth): |
| 546 | + user = mock.Mock() |
| 547 | + enterprise_customer = { |
| 548 | + 'identity_providers': [ |
| 549 | + {'provider_id': 'mock-idp'}, |
| 550 | + ], |
| 551 | + } |
| 552 | + mock_idp = mock.MagicMock(backend_name='mock-backend') |
| 553 | + mock_tpa.provider.Registry.get.return_value = mock_idp |
| 554 | + mock_user_social_auth.objects.select_related.return_value.filter.return_value.exists.return_value = True |
| 555 | + |
| 556 | + result = _user_has_social_auth_record(user, enterprise_customer) |
| 557 | + assert result is True |
| 558 | + |
| 559 | + mock_tpa.provider.Registry.get.assert_called_once_with(provider_id='mock-idp') |
| 560 | + mock_user_social_auth.objects.select_related.assert_called_once_with('user') |
| 561 | + mock_user_social_auth.objects.select_related.return_value.filter.assert_called_once_with( |
| 562 | + provider__in=['mock-backend'], user=user |
| 563 | + ) |
| 564 | + |
| 565 | + @mock.patch('openedx.features.enterprise_support.utils.UserSocialAuth') |
| 566 | + @mock.patch('openedx.features.enterprise_support.utils.third_party_auth') |
| 567 | + def test_user_has_social_auth_record_no_providers(self, mock_tpa, mock_user_social_auth): |
| 568 | + user = mock.Mock() |
| 569 | + enterprise_customer = { |
| 570 | + 'identity_providers': [], |
| 571 | + } |
| 572 | + |
| 573 | + result = _user_has_social_auth_record(user, enterprise_customer) |
| 574 | + assert result is False |
| 575 | + |
| 576 | + assert not mock_tpa.provider.Registry.get.called |
| 577 | + assert not mock_user_social_auth.objects.select_related.called |
| 578 | + |
| 579 | + @mock.patch('openedx.features.enterprise_support.utils.UserSocialAuth') |
| 580 | + @mock.patch('openedx.features.enterprise_support.utils.third_party_auth') |
| 581 | + def test_user_has_social_auth_record_no_enterprise_customer(self, mock_tpa, mock_user_social_auth): |
| 582 | + user = mock.Mock() |
| 583 | + enterprise_customer = None |
| 584 | + |
| 585 | + result = _user_has_social_auth_record(user, enterprise_customer) |
| 586 | + assert result is False |
| 587 | + |
| 588 | + assert not mock_tpa.provider.Registry.get.called |
| 589 | + assert not mock_user_social_auth.objects.select_related.called |
| 590 | + |
542 | 591 |
|
543 | 592 | @override_settings(FEATURES=FEATURES_WITH_ENTERPRISE_ENABLED)
|
544 | 593 | @skip_unless_lms
|
|
0 commit comments