Пример #1
0
    def test_activate_learner_enterprise(self):
        """
        Test enterprise is activated successfully for user
        """
        request_mock = mock.MagicMock(session={}, user=self.user)
        enterprise_customer_user = EnterpriseCustomerUserFactory(user_id=self.user.id)
        enterprise_customer_uuid = enterprise_customer_user.enterprise_customer.uuid

        activate_learner_enterprise(request_mock, self.user, enterprise_customer_uuid)
        assert request_mock.session['enterprise_customer']['uuid'] == str(enterprise_customer_uuid)
Пример #2
0
def enterprise_selection_page(request, user, next_url):
    """
    Updates redirect url to enterprise selection page if user is associated
    with multiple enterprises otherwise return the next url.

    param:
      next_url(string): The URL to redirect to after multiple enterprise selection or in case
      the selection page is bypassed e.g when dealing with direct enrolment urls.
    """
    redirect_url = next_url

    response = get_enterprise_learner_data_from_api(user)
    if response and len(response) > 1:
        redirect_url = reverse(
            'enterprise_select_active') + '/?success_url=' + next_url

        # Check to see if next url has an enterprise in it. In this case if user is associated with
        # that enterprise, activate that enterprise and bypass the selection page.
        if re.match(ENTERPRISE_ENROLLMENT_URL_REGEX,
                    urllib.parse.unquote(next_url)):
            enterprise_in_url = re.search(UUID4_REGEX, next_url).group(0)
            for enterprise in response:
                if enterprise_in_url == str(
                        enterprise['enterprise_customer']['uuid']):
                    is_activated_successfully = activate_learner_enterprise(
                        request, user, enterprise_in_url)
                    if is_activated_successfully:
                        redirect_url = next_url
                    break

    return redirect_url