Пример #1
0
 def test_saml_provider_not_found(self):
     """
     Test that Prov exception is thrown if no SAML provider exists for this
     program's organization.
     """
     OrganizationFactory.create(short_name=self.organization_key)
     with self.assertRaises(ProviderDoesNotExistException):
         get_users_by_external_keys(self.program_uuid, [])
Пример #2
0
 def test_fetch_organization(self):
     """ Unit Test: test_fetch_organization"""
     organization1 = OrganizationFactory.create()
     organization2 = OrganizationFactory.create()
     with self.assertNumQueries(2):
         self.assertEqual(
             data.fetch_organization(organization1.id)["id"],
             organization1.id)
         self.assertEqual(
             data.fetch_organization(organization2.id)["id"],
             organization2.id)
Пример #3
0
    def test_same_user_key_in_multiple_organizations(self):
        uox_program_enrollment = self._create_waiting_program_enrollment()

        second_organization = OrganizationFactory.create()
        SAMLProviderConfigFactory.create(organization=second_organization,
                                         slug='aiu')
        catalog_org = CatalogOrganizationFactory.create(
            key=second_organization.short_name)
        program_uuid = self._create_catalog_program(catalog_org)['uuid']

        # aiu enrollment with the same student key as our uox user
        aiu_program_enrollment = ProgramEnrollmentFactory.create(
            user=None,
            external_user_key=self.external_id,
            program_uuid=program_uuid)

        UserSocialAuth.objects.create(
            user=UserFactory.create(),
            uid='{0}:{1}'.format('not_used', self.external_id),
        )

        UserSocialAuth.objects.create(
            user=self.user,
            uid='{0}:{1}'.format(self.provider_slug, self.external_id),
        )
        self._assert_program_enrollment_user(uox_program_enrollment, self.user)

        aiu_user = UserFactory.create()
        UserSocialAuth.objects.create(
            user=aiu_user,
            uid='{0}:{1}'.format('aiu', self.external_id),
        )
        self._assert_program_enrollment_user(aiu_program_enrollment, aiu_user)
Пример #4
0
 def test_empty_request(self):
     """
     Test that requesting no external keys does not cause an exception.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     actual = get_users_by_external_keys(self.program_uuid, set())
     assert actual == {}
Пример #5
0
 def test_lms_organization_not_found(self):
     """
     Test an OrganizationDoesNotExistException is thrown if the LMS has no organization
     matching the catalog program's authoring_organization
     """
     organization = OrganizationFactory.create(short_name='some_other_org')
     SAMLProviderConfigFactory.create(organization=organization)
     with self.assertRaises(OrganizationDoesNotExistException):
         get_users_by_external_keys(self.program_uuid, [])
Пример #6
0
    def setUp(self):
        super(TestOrganizationsView, self).setUp()

        self.user_password = "******"
        self.user = UserFactory(password=self.user_password)
        self.organization = OrganizationFactory.create()
        self.organization_list_url = reverse("v0:organization-list")
        self.client.login(username=self.user.username,
                          password=self.user_password)
Пример #7
0
 def test_extra_saml_provider_disabled(self):
     """
     If multiple samlprovider records exist with the same organization,
     but the extra record is disabled, no exception is raised.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     # create a second active config for the same organization, NOT enabled
     SAMLProviderConfigFactory.create(
         organization=organization, slug='foox', enabled=False
     )
     get_users_by_external_keys(self.program_uuid, [])
Пример #8
0
 def setUp(self):
     super(ProgramEnrollmentsInspectorViewTests, self).setUp()
     self.url = reverse("support:program_enrollments_inspector")
     SupportStaffRole().add_users(self.user)
     self.program_uuid = str(uuid4())
     self.external_user_key = 'abcaaa'
     # Setup three orgs and their SAML providers
     self.org_key_list = ['test_org', 'donut_org', 'tri_org']
     for org_key in self.org_key_list:
         lms_org = OrganizationFactory(
             short_name=org_key
         )
         SAMLProviderConfigFactory(
             organization=lms_org,
             slug=org_key,
             enabled=True,
         )
     self.no_saml_org_key = 'no_saml_org'
     self.no_saml_lms_org = OrganizationFactory(
         short_name=self.no_saml_org_key
     )
Пример #9
0
 def test_extra_saml_provider_enabled(self):
     """
     If multiple enabled samlprovider records exist with the same organization
     an exception is raised.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     # create a second active config for the same organizationm, IS enabled
     SAMLProviderConfigFactory.create(
         organization=organization, slug='foox', enabled=True
     )
     with self.assertRaises(ProviderConfigurationException):
         get_users_by_external_keys(self.program_uuid, [])
Пример #10
0
 def setUp(self):
     """Make the user support staff"""
     super(SsoRecordsTests, self).setUp()
     SupportStaffRole().add_users(self.user)
     self.student = UserFactory.create(username='******', email='*****@*****.**', password='******')
     self.url = reverse("support:sso_records", kwargs={'username_or_email': self.student.username})
     self.org_key_list = ['test_org']
     for org_key in self.org_key_list:
         lms_org = OrganizationFactory(
             short_name=org_key
         )
         SAMLProviderConfigFactory(
             organization=lms_org,
             slug=org_key,
             enabled=True,
         )
Пример #11
0
    def setUpClass(cls):
        super(SocialAuthEnrollmentCompletionSignalTest, cls).setUpClass()

        cls.external_id = '0000'
        cls.provider_slug = 'uox'
        cls.course_keys = [
            CourseKey.from_string('course-v1:edX+DemoX+Test_Course'),
            CourseKey.from_string('course-v1:edX+DemoX+Another_Test_Course'),
        ]
        cls.organization = OrganizationFactory.create(short_name='UoX')
        cls.user = UserFactory.create()

        for course_key in cls.course_keys:
            CourseOverviewFactory(id=course_key)
        cls.provider_config = SAMLProviderConfigFactory.create(
            organization=cls.organization, slug=cls.provider_slug)
Пример #12
0
    def test_success(self):
        """ The task should clone the OrganizationCourse and RestrictedCourse data. """
        old_course_key = self.course.id
        new_course_key = CourseLocator(org=old_course_key.org,
                                       course=old_course_key.course,
                                       run='rerun')

        old_course_id = str(old_course_key)
        new_course_id = str(new_course_key)

        organization = OrganizationFactory()
        OrganizationCourse.objects.create(course_id=old_course_id,
                                          organization=organization)

        restricted_course = RestrictedCourse.objects.create(
            course_key=self.course.id)
        restricted_country = Country.objects.create(country='US')

        CountryAccessRule.objects.create(
            rule_type=CountryAccessRule.BLACKLIST_RULE,
            restricted_course=restricted_course,
            country=restricted_country)

        # Run the task!
        self._rerun_course(old_course_key, new_course_key)

        # Verify the new course run exists
        course = modulestore().get_course(new_course_key)
        self.assertIsNotNone(course)

        # Verify the OrganizationCourse is cloned
        self.assertEqual(OrganizationCourse.objects.count(), 2)
        # This will raise an error if the OrganizationCourse object was not cloned
        OrganizationCourse.objects.get(course_id=new_course_id,
                                       organization=organization)

        # Verify the RestrictedCourse and related objects are cloned
        self.assertEqual(RestrictedCourse.objects.count(), 2)
        restricted_course = RestrictedCourse.objects.get(
            course_key=new_course_key)

        self.assertEqual(CountryAccessRule.objects.count(), 2)
        CountryAccessRule.objects.get(
            rule_type=CountryAccessRule.BLACKLIST_RULE,
            restricted_course=restricted_course,
            country=restricted_country)
Пример #13
0
 def test_happy_path(self):
     """
     Test that get_users_by_external_keys returns the expected
     mapping of external keys to users.
     """
     organization = OrganizationFactory.create(short_name=self.organization_key)
     provider = SAMLProviderConfigFactory.create(organization=organization)
     self.create_social_auth_entry(self.user_0, provider, 'ext-user-0')
     self.create_social_auth_entry(self.user_1, provider, 'ext-user-1')
     self.create_social_auth_entry(self.user_2, provider, 'ext-user-2')
     requested_keys = {'ext-user-1', 'ext-user-2', 'ext-user-3'}
     actual = get_users_by_external_keys(self.program_uuid, requested_keys)
     # ext-user-0 not requested, ext-user-3 doesn't exist
     expected = {
         'ext-user-1': self.user_1,
         'ext-user-2': self.user_2,
         'ext-user-3': None,
     }
     assert actual == expected
Пример #14
0
    def setUpClass(cls):
        """
        Set up test data
        """
        super(EnrollmentTestMixin, cls).setUpClass()
        catalog_org = CatalogOrganizationFactory.create(
            key=cls.organization_key)
        cls.program = ProgramFactory.create(
            uuid=cls.program_uuid, authoring_organizations=[catalog_org])
        organization = OrganizationFactory.create(
            short_name=cls.organization_key)
        SAMLProviderConfigFactory.create(organization=organization)

        catalog_course_id_str = 'course-v1:edX+ToyX'
        course_run_id_str = '{}+Toy_Course'.format(catalog_course_id_str)
        cls.course_id = CourseKey.from_string(course_run_id_str)
        CourseOverviewFactory(id=cls.course_id)
        course_run = CourseRunFactory(key=course_run_id_str)
        cls.course = CourseFactory(key=catalog_course_id_str,
                                   course_runs=[course_run])
        cls.student_1 = UserFactory(username='******')
        cls.student_2 = UserFactory(username='******')
Пример #15
0
 def setUp(self):
     super(TestOrganizationSerializer, self).setUp()
     self.organization = OrganizationFactory.create()
Пример #16
0
 def setUp(self):
     super(TestOrganizationModel, self).setUp()
     self.organization = OrganizationFactory.create()
Пример #17
0
 def test_inactive_organization(self):
     """ Verify inactive organization are filtered out."""
     organization = OrganizationFactory(active=False)
     url = self._get_organization_url(organization)
     response = self.client.get(url)
     self.assertEqual(response.status_code, 404)
Пример #18
0
 def test_authenticated_user(self):
     """ Verify that the authenticated user gets data."""
     OrganizationFactory.create()
     response = self.client.get(self.organization_list_url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data["results"]), 2)  # pylint: disable=no-member