Example #1
0
    def test_requires_salesforce_update(self):
        org = OrganizationFactoryNoSignals(
            partner=self.salesforce_config.partner)
        org.description = 'changed'
        self.assertEqual(requires_salesforce_update('organization', org),
                         False)

        org.name = 'changed'
        self.assertEqual(requires_salesforce_update('organization', org), True)

        course = CourseFactory()
        course.short_description = 'changed'
        self.assertEqual(requires_salesforce_update('course', course), False)

        course.title = 'changed'
        self.assertEqual(requires_salesforce_update('course', course), True)

        course_run = CourseRunFactory()
        course_run.full_description = 'changed'
        self.assertEqual(requires_salesforce_update('course_run', course_run),
                         False)

        course_run.key = 'changed'
        self.assertEqual(requires_salesforce_update('course_run', course_run),
                         True)
Example #2
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')
Example #3
0
 def setUp(self):
     super().setUp()
     self.salesforce_config = SalesforceConfigurationFactory(partner=self.partner)
     self.user = UserFactory(is_staff=True)
     self.request.user = self.user
     self.request.site.partner = self.partner
     self.client.login(username=self.user.username, password=USER_PASSWORD)
     self.course = CourseFactoryNoSignals(partner=self.partner, title='Fake Test', key='edX+Fake101', draft=True)
     self.org = OrganizationFactoryNoSignals(key='edX', partner=self.partner)
     self.course.authoring_organizations.add(self.org)
Example #4
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')
Example #5
0
    def test_create_account_salesforce_id_set(self):
        organization = OrganizationFactoryNoSignals(
            key='edX',
            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_publisher_organization(organization)

            mock_salesforce(
            ).Publisher_Organization__c.create.assert_not_called()
Example #6
0
    def test_update_publisher_organization(self, salesforce_id):
        """Test Cases: updating organization with a salesforce_id, with no salesforce_id"""
        organization = OrganizationFactoryNoSignals(
            partner=self.salesforce_config.partner,
            salesforce_id=salesforce_id)

        with mock.patch(self.salesforce_path) as mock_salesforce:
            util = SalesforceUtil(self.salesforce_config.partner)
            util.update_publisher_organization(organization)
            if salesforce_id:
                mock_salesforce(
                ).Publisher_Organization__c.update.assert_called()
            else:
                mock_salesforce(
                ).Publisher_Organization__c.update.assert_not_called()
Example #7
0
    def test_create_account_salesforce_id_not_set(self):
        organization = OrganizationFactoryNoSignals(
            key='edX', partner=self.salesforce_config.partner)

        return_value = {'id': 'SomeSalesforceId'}

        with mock.patch(self.salesforce_path) as mock_salesforce:
            mock_salesforce(
            ).Publisher_Organization__c.create.return_value = return_value
            util = SalesforceUtil(self.salesforce_config.partner)
            util.create_publisher_organization(organization)
            mock_salesforce(
            ).Publisher_Organization__c.create.assert_called_with({
                'Organization_Name__c':
                organization.name,
                'Organization_Key__c':
                organization.key,
            })
            assert organization.salesforce_id == return_value.get('id')