def test_updating_order_of_authoring_orgs(self):
        org1 = factories.OrganizationFactory(key='org1')
        org2 = factories.OrganizationFactory(key='org2')
        org3 = factories.OrganizationFactory(key='org3')

        course = factories.CourseFactory(
            authoring_organizations=[org1, org2, org3])

        new_ordering = (',').join(
            map(lambda org: str(org.id), [org2, org3, org1]))
        params = {'authoring_organizations': new_ordering}

        post_url = reverse('admin:course_metadata_course_change',
                           args=(course.id, ))
        response = self.client.post(post_url, params)
        self.assertEqual(response.status_code, 200)

        html = BeautifulSoup(response.content)

        orgs_dropdown_text = html.find(
            class_='field-authoring_organizations').get_text()

        self.assertLess(orgs_dropdown_text.index('org2'),
                        orgs_dropdown_text.index('org3'))
        self.assertLess(orgs_dropdown_text.index('org3'),
                        orgs_dropdown_text.index('org1'))
Beispiel #2
0
    def test_publisher_course_on_new_pub_fe(self):
        org = self.organization_extension.organization
        course = factories.CourseFactory()

        # When no ORGS_ON_OLD_PUBLISHER list present
        self.assertFalse(is_publisher_course_on_new_pub_fe(course))

        with self.settings(ORGS_ON_OLD_PUBLISHER=org.key):
            # When ORGS_ON_OLD_PUBLISHER list present and course has no orgs
            self.assertTrue(is_publisher_course_on_new_pub_fe(course))

        course.organizations.add(org)

        with self.settings(ORGS_ON_OLD_PUBLISHER=org.key):
            # When ORGS_ON_OLD_PUBLISHER list present and course is authored by an org in the list
            self.assertFalse(is_publisher_course_on_new_pub_fe(course))

        with self.settings(ORGS_ON_OLD_PUBLISHER='example-key'):
            # When ORGS_ON_OLD_PUBLISHER list present and course is authored by an org not in the list
            self.assertTrue(is_publisher_course_on_new_pub_fe(course))

        with self.settings(ORGS_ON_OLD_PUBLISHER=org.key):
            org2 = cm_factories.OrganizationFactory()
            course.organizations.add(org2)
            # When ORGS_ON_OLD_PUBLISHER list present and course is authored by orgs both on and off the list
            self.assertFalse(is_publisher_course_on_new_pub_fe(course))
    def test_authoring_organizations_changed(self):
        with mock.patch(self.salesforce_util_path) as mock_salesforce_util:
            # Does not update for non-draftstest_comments.py
            organization = factories.OrganizationFactory()
            course = factories.CourseFactory(draft=False)

            course.authoring_organizations.add(organization)
            mock_salesforce_util().create_course.assert_not_called()

            # Updates for drafts when an auth org is added (new) courses
            organization = factories.OrganizationFactory()

            course = factories.CourseFactory(draft=True)

            course.authoring_organizations.add(organization)
            mock_salesforce_util().create_course.assert_called()
Beispiel #4
0
 def ingest_mock_data(self):
     self.mock_login_response()
     people = self.mock_api()
     factories.OrganizationFactory(name='MIT')
     for person in people:
         Person.objects.create(uuid=person['uuid'], partner=self.partner)
     self.loader.ingest()
     return people
Beispiel #5
0
    def test_ingest(self):
        self.mock_login_response()
        people = self.mock_api()
        factories.OrganizationFactory(name='MIT')

        self.loader.ingest()

        for person in people:
            self.assert_person_loaded(person)
    def setUp(self):
        super().setUp()

        # Disable marketing site password just to save us from having to mock the responses
        self.partner = factories.PartnerFactory(marketing_site_api_password=None)

        # Fill out a bunch of types and modes. Exact mode parameters don't matter, just the resulting seat types.
        self.audit_seat_type = factories.SeatTypeFactory.audit()
        self.verified_seat_type = factories.SeatTypeFactory.verified()
        self.audit_mode = Mode.objects.get(slug=Seat.AUDIT)
        self.verified_mode = Mode.objects.get(slug=Seat.VERIFIED)
        self.audit_track = Track.objects.get(seat_type=self.audit_seat_type, mode=self.audit_mode)
        self.verified_track = Track.objects.get(seat_type=self.verified_seat_type, mode=self.verified_mode)
        self.empty_run_type = CourseRunType.objects.get(slug=CourseRunType.EMPTY)
        self.audit_run_type = CourseRunType.objects.get(slug=CourseRunType.AUDIT)
        self.va_run_type = CourseRunType.objects.get(slug=CourseRunType.VERIFIED_AUDIT)
        self.empty_course_type = CourseType.objects.get(slug=CourseType.EMPTY)
        self.va_course_type = CourseType.objects.get(slug=CourseType.VERIFIED_AUDIT)
        self.audit_course_type = CourseType.objects.get(slug=CourseType.AUDIT)

        # Now create some courses and orgs that will be found to match the above, in the simple happy path case.
        self.org = factories.OrganizationFactory(partner=self.partner, key='Org1')
        self.course = factories.CourseFactory(partner=self.partner, authoring_organizations=[self.org],
                                              type=self.empty_course_type,
                                              key=f'{self.org.key}+Course1')
        self.entitlement = factories.CourseEntitlementFactory(partner=self.partner, course=self.course,
                                                              mode=self.verified_seat_type)
        self.audit_run = factories.CourseRunFactory(course=self.course, type=self.empty_run_type,
                                                    key='course-v1:Org1+Course1+A')
        self.audit_seat = factories.SeatFactory(course_run=self.audit_run, type=self.audit_seat_type)
        self.verified_run = factories.CourseRunFactory(course=self.course, type=self.empty_run_type,
                                                       key='course-v1:Org1+Course1+V')
        self.verified_seat = factories.SeatFactory(course_run=self.verified_run, type=self.verified_seat_type)
        self.verified_audit_seat = factories.SeatFactory(course_run=self.verified_run, type=self.audit_seat_type)

        # Create parallel obj / course for argument testing
        self.org2 = factories.OrganizationFactory(partner=self.partner, key='Org2')
        self.org3 = factories.OrganizationFactory(partner=self.partner, key='Org3')
        self.course2 = factories.CourseFactory(partner=self.partner, authoring_organizations=[self.org2, self.org3],
                                               type=self.empty_course_type,
                                               key=f'{self.org2.key}+Course1')
        self.c2_audit_run = factories.CourseRunFactory(course=self.course2, type=self.empty_run_type)
        self.c2_audit_seat = factories.SeatFactory(course_run=self.c2_audit_run, type=self.audit_seat_type)
    def test_update_or_create_salesforce_organization(self):
        with mock.patch(self.salesforce_util_path) as mock_salesforce_util:
            organization = factories.OrganizationFactory()

            mock_salesforce_util().create_publisher_organization.assert_called()
            mock_salesforce_util().update_publisher_organization.assert_not_called()

            organization.name = 'changed'
            organization.save()

            mock_salesforce_util().update_publisher_organization.assert_called()
Beispiel #8
0
 def test_org_synonyms(self):
     """ Test that synonyms work for organization names """
     title = 'UniversityX'
     authoring_organizations = [
         factories.OrganizationFactory(name='University')
     ]
     factories.CourseRunFactory(
         title=title,
         course__partner=self.partner,
         authoring_organizations=authoring_organizations)
     factories.ProgramFactory(
         title=title,
         partner=self.partner,
         authoring_organizations=authoring_organizations)
     response1 = self.process_response({'q': title})
     response2 = self.process_response({'q': 'University'})
     assert response1 == response2
    def test_update_or_create_salesforce_course(self):
        with mock.patch(self.salesforce_util_path) as mock_salesforce_util:
            # Does not update for non-drafts
            course = factories.CourseFactory(draft=True)

            mock_salesforce_util().create_course.assert_not_called()
            mock_salesforce_util().update_course.assert_not_called()

            course.save()

            # This shows that an update to a draft does not hit the salesforce update method
            mock_salesforce_util().update_course.assert_not_called()
            organization = factories.OrganizationFactory()
            course.authoring_organizations.add(organization)

            course.draft = False
            course.title = 'changed'
            course.save()

            assert 1 == mock_salesforce_util().update_course.call_count
Beispiel #10
0
 def setUp(self):
     super(OrganizationTests, self).setUp()
     self.organization = factories.OrganizationFactory()