Пример #1
0
    def test_create_course_salesforce_id_not_set(self):
        course = CourseFactoryNoSignals(partner=self.salesforce_config.partner)
        organization = OrganizationFactoryNoSignals(
            key='edX',
            partner=self.salesforce_config.partner,
            salesforce_id='Test')
        course.authoring_organizations.add(organization)
        partner = self.salesforce_config.partner

        return_value = {'id': 'SomeSalesforceId'}

        with mock.patch(self.salesforce_path) as mock_salesforce:
            mock_salesforce().Course__c.create.return_value = return_value
            util = SalesforceUtil(self.salesforce_config.partner)
            util.create_course(course)
            mock_salesforce().Course__c.create.assert_called_with({
                'Course_Name__c':
                course.title,
                'Link_to_Publisher__c':
                '{url}/courses/{uuid}'.format(
                    url=partner.publisher_url.strip('/'), uuid=course.uuid)
                if partner.publisher_url else None,
                'Link_to_Admin_Portal__c':
                '{url}/admin/course_metadata/course/{id}/change/'.format(
                    url=partner.site.domain.strip('/'), id=course.id)
                if partner.site.domain else None,
                'Course_Key__c':
                course.key,
                'Publisher_Organization__c':
                organization.salesforce_id,
            })
            assert course.salesforce_id == return_value.get('id')
Пример #2
0
    def test_create_course_salesforce_id_set(self):
        course = CourseFactoryNoSignals(partner=self.salesforce_config.partner,
                                        salesforce_id='Test')

        with mock.patch(self.salesforce_path) as mock_salesforce:
            util = SalesforceUtil(self.salesforce_config.partner)
            util.create_course(course)
            mock_salesforce().Course__c.create.assert_not_called()
Пример #3
0
    def test_create_course_organization_salesforce_id_not_set(self):
        create_pub_org_path = (self.salesforce_util_path +
                               '.create_publisher_organization')

        course = CourseFactoryNoSignals(partner=self.salesforce_config.partner)
        organization = OrganizationFactoryNoSignals(
            key='edX', partner=self.salesforce_config.partner)
        course.authoring_organizations.add(organization)
        partner = self.salesforce_config.partner

        return_value = {'id': 'SomeSalesforceId'}

        # Need to modify state of the instance passed in
        def new_create_organization(self, instance):  # pylint: disable=unused-argument
            instance.salesforce_id = 'SomeSalesforceId'
            instance.save()

        with mock.patch(self.salesforce_path) as mock_salesforce:
            with mock.patch(create_pub_org_path, new=new_create_organization):
                mock_salesforce().Course__c.create.return_value = return_value
                util = SalesforceUtil(self.salesforce_config.partner)
                assert organization.salesforce_id is None
                util.create_course(course)
                organization.refresh_from_db()
                mock_salesforce().Course__c.create.assert_called_with({
                    'Course_Name__c':
                    course.title,
                    'Link_to_Publisher__c':
                    '{url}/courses/{uuid}'.format(
                        url=partner.publisher_url.strip('/'), uuid=course.uuid)
                    if partner.publisher_url else None,
                    'Link_to_Admin_Portal__c':
                    '{url}/admin/course_metadata/course/{id}/change/'.format(
                        url=partner.site.domain.strip('/'), id=course.id)
                    if partner.site.domain else None,
                    'Course_Key__c':
                    course.key,
                    'Publisher_Organization__c':
                    organization.salesforce_id,
                })

                assert organization.salesforce_id is not None
                assert course.salesforce_id == return_value.get('id')