예제 #1
0
 def test_edly_sub_organization_post_save_receiver(self):
     """
     Test EdlySubOrganization model object creation.
     """
     edly_sub_organization = EdlySubOrganizationFactory(slug='test-edly-sub-organization', lms_site=self.lms_site)
     edly_sub_organization_data = EdlySubOrganization.objects.filter(lms_site=edly_sub_organization.lms_site)
     assert edly_sub_organization_data.count() == 1
예제 #2
0
    def setUp(self):
        """
        Create environment for settings override middleware tests.
        """
        self.user = EdlyUserFactory()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.request.site = SiteFactory()
        EdlySubOrganizationFactory(lms_site=self.request.site)

        self.client = Client(SERVER_NAME=self.request.site.domain)
        self.client.cookies.load({
            settings.EDLY_USER_INFO_COOKIE_NAME:
            cookies._get_edly_user_info_cookie_string(self.request)
        })
        self.client.login(username=self.user.username, password='******')
        self.default_settings = {
            key: getattr(settings, key, None)
            for key in [
                'SITE_NAME',
                'CMS_BASE',
                'LMS_BASE',
                'LMS_ROOT_URL',
                'SESSION_COOKIE_DOMAIN',
                'LOGIN_REDIRECT_WHITELIST',
                'DEFAULT_FEEDBACK_EMAIL',
                'CREDENTIALS_PUBLIC_SERVICE_URL',
                'FEATURES',
            ]
        }
예제 #3
0
    def test_filter_courses_based_on_org(self):
        """
        Test course are filtered properly on current site organization.
        """
        edx_org_1 = OrganizationFactory()
        edx_org_2 = OrganizationFactory()
        courses_of_org_1 = CourseFactory.create_batch(2,
                                                      org=edx_org_1.short_name)
        CourseFactory.create(org=edx_org_2.short_name)

        assert len(modulestore().get_courses()) == 3

        EdlySubOrganizationFactory(edx_organization=edx_org_1,
                                   lms_site=self.request.site,
                                   studio_site=self.request.site)
        create_user_link_with_edly_sub_organization(self.request,
                                                    self.request.user)
        response = cookies_api.set_logged_in_edly_cookies(
            self.request, HttpResponse(), self.user,
            cookie_settings(self.request))
        self._copy_cookies_to_request(response, self.request)

        filtered_courses = filter_courses_based_on_org(self.request,
                                                       courses_of_org_1)
        assert len(filtered_courses) == 2

        edx_orgs_of_filterd_courses = [
            course.org for course in filtered_courses
        ]
        for org in edx_orgs_of_filterd_courses:
            assert org == edx_org_1.short_name
예제 #4
0
    def test_user_cannot_login_on_requested_edly_organization(self):
        """
        Test user cannot login on the requested URL site if not linked with its parent edly-organization.
        """
        assert user_can_login_on_requested_edly_organization(
            self.request, self.user) is False

        edly_sub_organization_linked_to_site = self._create_edly_sub_organization(
        )

        edly_sub_organization_linked_to_user = EdlySubOrganizationFactory(
            lms_site=SiteFactory(),
            edly_organization=EdlyOrganizationFactory(),
        )
        self.edly_user_profile.edly_sub_organizations.add(
            edly_sub_organization_linked_to_user)

        assert user_can_login_on_requested_edly_organization(
            self.request, self.user) is False

        edly_sub_organization_linked_to_site.edly_organization.enable_all_edly_sub_org_login = True
        edly_sub_organization_linked_to_site.edly_organization.save()

        assert user_can_login_on_requested_edly_organization(
            self.request, self.user) is False
예제 #5
0
    def test_user_without_edly_sub_organization_access_for_current_site(self):
        """
        Test user has no access to current site as it's edly sub organization
        is not linked with user's "EdlyUserProfile".
        """

        EdlySubOrganizationFactory(lms_site=self.request.site)
        has_access = is_edly_user_allowed_to_login(self.request, self.user)

        assert not has_access
예제 #6
0
 def test_user_with_edly_organization_access(self):
     """
     Test logged in user access based on user's linked edly sub organization.
     """
     EdlySubOrganizationFactory(lms_site=self.request.site)
     self.client.cookies.load({
         settings.EDLY_USER_INFO_COOKIE_NAME:
         cookies._get_edly_user_info_cookie_string(self.request)
     })
     response = self.client.get('/', follow=True)
     assert response.status_code == 200
예제 #7
0
    def test_user_linked_with_edly_organization(self):
        """
        Test user is linked with a valid site.
        """
        edly_sub_organization = EdlySubOrganizationFactory(
            lms_site=self.request.site)
        self.edly_user_profile.edly_sub_organizations.add(
            edly_sub_organization)

        assert user_belongs_to_edly_organization(self.request,
                                                 self.user) is True
예제 #8
0
    def test_user_without_organization_access(self):
        """
        Test user has no access to a valid site URL but that site in not linked to the user.
        """
        edly_sub_organization = EdlySubOrganizationFactory(
            lms_site=SiteFactory())
        self.edly_user_profile.edly_sub_organizations.add(
            edly_sub_organization)

        user_has_access = user_has_edly_organization_access(self.request)
        assert user_has_access is False
예제 #9
0
    def test_multiple_sub_organizations(self):
        """
        Test "EdlyUserProfile" model multiple edly sub organizations.
        """

        edly_sub_organizations = [EdlySubOrganizationFactory() for __ in range(3)]
        edly_user_profile = EdlyUserProfileFactory(user=self.user)
        edly_user_profile.edly_sub_organizations.add(*edly_sub_organizations)

        edly_user_profile_data = EdlyUserProfile.objects.filter(user=edly_user_profile.user)

        assert edly_user_profile_data.count() == 1
        assert list(edly_user_profile_data[0].edly_sub_organizations.all()) == edly_sub_organizations
예제 #10
0
    def test_user_with_edly_sub_organization_access_of_current_site(self):
        """
        Test user has access to current site as it's edly sub organization
        is linked with user's "EdlyUserProfile".
        """

        edly_sub_organization = EdlySubOrganizationFactory(
            lms_site=self.request.site)
        self.edly_user_profile.edly_sub_organizations.add(
            edly_sub_organization)
        has_access = is_edly_user_allowed_to_login(self.request, self.user)

        assert has_access
예제 #11
0
    def test_edly_sub_organization_post_update_receiver(self):
        """
        Test EdlySubOrganization model object update.
        """
        edly_organization = EdlyOrganizationFactory(name='Test Edly Organization Name')
        edly_sub_organization = EdlySubOrganizationFactory(
            name='Test Edly Sub Organization Name',
            slug='test-edly-sub-organization-name',
            studio_site=self.studio_site,
            edly_organization=edly_organization
        )
        edly_sub_organization_data = EdlySubOrganization.objects.filter(studio_site=edly_sub_organization.studio_site)

        assert edly_sub_organization_data.count() == 1
        assert edly_sub_organization_data[0].edly_organization.name == edly_organization.name
예제 #12
0
    def test_organization_list(self):
        """
        Verify that the organization names list API only returns Edly's enabled organizations.
        """
        studio_site = SiteFactory()
        edly_organization = EdlyOrganizationFactory(name='Test Edly Organization Name')
        edly_sub_organization = EdlySubOrganizationFactory(
            studio_site=studio_site,
            edly_organization=edly_organization
        )

        response = self.client.get(self.org_names_listing_url, HTTP_ACCEPT='application/json', SERVER_NAME=studio_site.domain)

        assert response.status_code == 200
        assert len(response.json()) == 1
        assert response.json()[0] == edly_sub_organization.edx_organization.short_name
예제 #13
0
    def setUp(self):
        self.staff = EdlyUserFactory(
            **self.USER_CREDENTIALS['staff']
        )
        self.edly_sub_organizations = [EdlySubOrganizationFactory()]

        edly_user_profile = EdlyUserProfileFactory(user=self.staff)
        edly_user_profile.edly_sub_organizations.add(*self.edly_sub_organizations)

        self.student = EdlyUserFactory(
            **self.USER_CREDENTIALS['student']
        )
        edly_user_profile = EdlyUserProfileFactory(user=self.student)
        edly_user_profile.edly_sub_organizations.add(*self.edly_sub_organizations)

        self.site = self.staff.edly_profile.edly_sub_organizations.first().lms_site

        self.client = Client(site=self.site, SERVER_NAME=self.site.domain)
예제 #14
0
    def test_for_non_staff_user_return_error(self):
        password = '******'
        user = EdlyUserFactory(password=password)
        site = SiteFactory(name=self.site_name)
        site_config = SiteConfigurationFactory(
            values={'address': self.site_address}, site=site)
        EdlySubOrganizationFactory(lms_site=site)
        request = RequestFactory()
        request.user = user
        request.site = site

        self.client.login(username=user.username, password=password)
        self.client.cookies.load({
            settings.EDLY_USER_INFO_COOKIE_NAME:
            cookies._get_edly_user_info_cookie_string(request)
        })
        url = reverse('redhouse_panel:redhouse_panel_api.v0:site',
                      kwargs={'pk': site.id})
        response = self.client.get(url, SERVER_NAME=site.domain)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'],
                         'You do not have permission to perform this action.')
예제 #15
0
    def test_edly_profile_creation_with_user_registration(self):
        """
        Test "EdlyUserProfile" creation on Registration of User.

        Create an account with params, assert that the response indicates
        success, and check if "EdlyUserProfile" object exists for the newly created user
        """

        EdlySubOrganizationFactory(lms_site=self.site)
        username = '******'
        params = {
            'email': '*****@*****.**',
            'name': 'Test User',
            'username': username,
            'password': '******',
            'honor_code': 'true',
        }

        response = self.client.post(self.url, params, SERVER_NAME=self.site.domain)
        assert response.status_code == 200

        edly_user = User.objects.get(username=username)
        assert hasattr(edly_user, 'edly_profile') == True
        assert self.site.edly_sub_org_for_lms.slug in edly_user.edly_profile.get_linked_edly_sub_organizations
예제 #16
0
 def _create_edly_sub_organization(self):
     """
     Helper method to create 'EdlySubOrganization` for the request site.
     """
     return EdlySubOrganizationFactory(lms_site=self.request.site)