def test_create_comment_for_course_case_salesforce_case_id_not_set(self): create_case_path = self.salesforce_util_path + '.create_case_for_course' course = CourseFactoryNoSignals(partner=self.salesforce_config.partner, salesforce_id='TestSalesforceId') user = UserFactory() body = 'Test body' # Need to modify state of the instance passed in def new_create_course_case(self, instance): # pylint: disable=unused-argument instance.salesforce_case_id = 'SomeSalesforceId' instance.save() with mock.patch(self.salesforce_path) as mock_salesforce: with mock.patch(create_case_path, new=new_create_course_case): util = SalesforceUtil(self.salesforce_config.partner) assert course.salesforce_case_id is None util.create_comment_for_course_case(course, user, body) mock_salesforce().FeedItem.create.assert_called_with({ 'ParentId': course.salesforce_case_id, 'Body': util.format_user_comment_body(user, body, None) }) assert course.salesforce_case_id is not None
def test_create_comment_for_course_case_raises_exceptions(self): create_case_path = self.salesforce_util_path + '.create_case_for_course' course = CourseFactoryNoSignals(partner=self.salesforce_config.partner, salesforce_id='TestSalesforceId') user = UserFactory() body = 'Test body' # Need to modify state of the instance passed in and make it None to simulate an error def new_create_course_case(self, instance): # pylint: disable=unused-argument instance.salesforce_case_id = None instance.save() with mock.patch(self.salesforce_path): with mock.patch(create_case_path, new=new_create_course_case): util = SalesforceUtil(self.salesforce_config.partner) assert course.salesforce_case_id is None with pytest.raises(SalesforceMissingCaseException): util.create_comment_for_course_case(course, user, body)
def test_create_comment_for_course_case_salesforce_case_id_set(self): create_case_path = self.salesforce_util_path + '.create_case_for_course' course = CourseFactoryNoSignals(partner=self.salesforce_config.partner, salesforce_case_id='TestSalesforceId') user = UserFactory() body = 'Test body' with mock.patch(self.salesforce_path) as mock_salesforce: with mock.patch(create_case_path) as mock_create_case_for_course: util = SalesforceUtil(self.salesforce_config.partner) util.create_comment_for_course_case(course, user, body) mock_salesforce().FeedItem.create.assert_called_with({ 'ParentId': course.salesforce_case_id, 'Body': util.format_user_comment_body(user, body, None) }) mock_create_case_for_course.assert_not_called()