Ejemplo n.º 1
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',
            ]
        }
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def test_edly_user_profile_on_user_creation(self):
        """
        Test "EdlyUserProfile" object creation on User object creation.
        """

        edly_user = EdlyUserFactory(password='******')
        edly_user_profile = EdlyUserProfile.objects.filter(user=edly_user)
        assert edly_user_profile.count() == 1
        assert edly_user_profile[0].user == edly_user
Ejemplo n.º 4
0
    def test_staff_has_all_sites_access(self):
        """
        Test logged in staff user has access to all sites.
        """
        edly_user = EdlyUserFactory(is_staff=True)
        client = Client()
        client.login(username=edly_user.username, password='******')

        response = client.get('/', follow=True)
        assert response.status_code == 200
Ejemplo n.º 5
0
    def setUp(self):
        self.user = EdlyUserFactory()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.request.site = SiteFactory()
        self.site_config = SiteConfigurationFactory(
            site=self.request.site,
            values={
                'MARKETING_SITE_ROOT': 'http://marketing.site',
                'DJANGO_SETTINGS_OVERRIDE': {
                    'SITE_NAME': 'testserver.localhost'
                }
            })

        self.client = Client(SERVER_NAME=self.request.site.domain)
        self.client.login(username=self.user.username, password='******')
Ejemplo n.º 6
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.')
Ejemplo n.º 7
0
 def setUpClass(cls):
     super(EdlyUserProfileTests, cls).setUpClass()
     cls.user = EdlyUserFactory(password='******')