Пример #1
0
    def test_is_enterprise_learner(self):
        with mock.patch('django.core.cache.cache.set') as mock_cache_set:
            EnterpriseCustomerUserFactory.create(active=True,
                                                 user_id=self.user.id)
            self.assertTrue(is_enterprise_learner(self.user))

        self.assertTrue(mock_cache_set.called)
Пример #2
0
    def test_get_enterprise_learner_portal_no_branding_config(self):
        """
        Test that only an enabled enterprise portal is returned,
        and that it matches the customer UUID provided in the request,
        even if no branding config is associated with the customer.
        """
        enterprise_customer_user = EnterpriseCustomerUserFactory.create(
            active=True, user_id=self.user.id)
        enterprise_customer_user.enterprise_customer.enable_learner_portal = True
        enterprise_customer_user.enterprise_customer.save()

        request = mock.MagicMock(session={}, user=self.user)
        # Indicate the "preferred" customer in the request
        request.GET = {
            'enterprise_customer':
            enterprise_customer_user.enterprise_customer.uuid
        }

        portal = get_enterprise_learner_portal(request)
        self.assertDictEqual(
            portal, {
                'name':
                enterprise_customer_user.enterprise_customer.name,
                'slug':
                enterprise_customer_user.enterprise_customer.slug,
                'logo':
                enterprise_customer_user.enterprise_customer.
                safe_branding_configuration.safe_logo_url,
            })
Пример #3
0
    def test_is_enterprise_customer_user(self):
        """
        Verify that if user is an enterprise learner.
        """
        # Create users from factory

        user = UserFactory(username='******', email='*****@*****.**')
        other_user = UserFactory(username='******', email='*****@*****.**')
        customer_idp = EnterpriseCustomerIdentityProviderFactory.create(
            provider_id='the-provider',
        )
        customer = customer_idp.enterprise_customer
        EnterpriseCustomerUserFactory.create(
            enterprise_customer=customer,
            user_id=user.id,
        )

        assert is_enterprise_customer_user('the-provider', user)
        assert not is_enterprise_customer_user('the-provider', other_user)
Пример #4
0
    def test_unlink_enterprise_user_from_idp(self, mock_customer_from_request, mock_registry):
        customer_idp = EnterpriseCustomerIdentityProviderFactory.create(
            provider_id='the-provider',
        )
        customer = customer_idp.enterprise_customer
        customer_user = EnterpriseCustomerUserFactory.create(  # lint-amnesty, pylint: disable=unused-variable
            enterprise_customer=customer,
            user_id=self.user.id,
        )
        mock_customer_from_request.return_value = {
            'uuid': customer.uuid,
        }
        mock_registry.get_enabled_by_backend_name.return_value = [
            mock.Mock(provider_id='the-provider')
        ]
        request = mock.Mock()

        unlink_enterprise_user_from_idp(request, self.user, idp_backend_name='the-backend-name')

        assert 0 == EnterpriseCustomerUser.objects.filter(user_id=self.user.id).count()
Пример #5
0
 def test_user_enterprise(self, mock_get_programs_by_type):
     mock_get_programs_by_type.return_value = [self.program]
     EnterpriseCustomerUserFactory.create(user_id=self.user.id)
     assert not show_user_demographics(user=self.user)