Exemplo n.º 1
0
    def test_get_enterprise_learner_portal_no_customer_from_request(self):
        """
        Test that only one enabled enterprise portal is returned,
        even if enterprise_customer_uuid_from_request() returns None.
        """
        # Create another enterprise customer association for the same user.
        # There should be no data returned for this customer's portal,
        # because another customer is later created with a more recent active/modified time.
        other_enterprise_customer_user = EnterpriseCustomerUserFactory(active=True, user_id=self.user.id)
        other_enterprise_customer_user.enable_learner_portal = True
        other_enterprise_customer_user.save()

        enterprise_customer_user = EnterpriseCustomerUserFactory(active=True, user_id=self.user.id)
        EnterpriseCustomerBrandingConfigurationFactory(
            enterprise_customer=enterprise_customer_user.enterprise_customer,
        )
        enterprise_customer_user.enterprise_customer.enable_learner_portal = True
        enterprise_customer_user.enterprise_customer.save()

        request = mock.MagicMock(session={}, user=self.user)

        with mock.patch(
                'openedx.features.enterprise_support.api.enterprise_customer_uuid_for_request',
                return_value=None,
        ):
            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,
        })
Exemplo n.º 2
0
    def test_get_enterprise_learner_portal_uncached(self):
        """
        Test that only an enabled enterprise portal is returned,
        and that it matches the customer UUID provided in the request.
        """
        enterprise_customer_user = EnterpriseCustomerUserFactory(active=True, user_id=self.user.id)
        EnterpriseCustomerBrandingConfigurationFactory(
            enterprise_customer=enterprise_customer_user.enterprise_customer,
        )
        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}

        # Create another enterprise customer association for the same user.
        # There should be no data returned for this customer's portal,
        # because we filter for only the enterprise customer uuid found in the request.
        other_enterprise_customer_user = EnterpriseCustomerUserFactory(active=True, user_id=self.user.id)
        other_enterprise_customer_user.enable_learner_portal = True
        other_enterprise_customer_user.save()

        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,
        })