def create_graded_assignment(self, desc, result_id, outcome_service): """ Create and save a new GradedAssignment model in the test database. """ assignment = GradedAssignment(user=self.user, course_key=self.course.id, usage_key=desc.location, outcome_service=outcome_service, lis_result_sourcedid=result_id, version_number=0) assignment.save() return assignment
class BaseOutcomeTest(TestCase): """ Super type for tests of both the leaf and composite outcome celery tasks. """ def setUp(self): super(BaseOutcomeTest, self).setUp() self.course_key = CourseLocator( org='some_org', course='some_course', run='some_run' ) self.usage_key = BlockUsageLocator( course_key=self.course_key, block_type='problem', block_id='block_id' ) self.user = UserFactory.create() self.consumer = LtiConsumer( consumer_name='Lti Consumer Name', consumer_key='consumer_key', consumer_secret='consumer_secret', instance_guid='tool_instance_guid' ) self.consumer.save() outcome = OutcomeService( lis_outcome_service_url='http://example.com/service_url', lti_consumer=self.consumer ) outcome.save() self.assignment = GradedAssignment( user=self.user, course_key=self.course_key, usage_key=self.usage_key, outcome_service=outcome, lis_result_sourcedid='sourcedid', version_number=1, ) self.assignment.save() self.send_score_update_mock = self.setup_patch( 'lms.djangoapps.lti_provider.outcomes.send_score_update', None ) def setup_patch(self, function_name, return_value): """ Patch a method with a given return value, and return the mock """ mock = MagicMock(return_value=return_value) new_patch = patch(function_name, new=mock) new_patch.start() self.addCleanup(new_patch.stop) return mock
class SignAndSendReplaceResultTest(TestCase): """ Tests for the sign_and_send_replace_result method in outcomes.py """ def setUp(self): super(SignAndSendReplaceResultTest, self).setUp() self.course_key = CourseLocator( org='some_org', course='some_course', run='some_run' ) self.usage_key = BlockUsageLocator( course_key=self.course_key, block_type='problem', block_id='block_id' ) self.user = UserFactory.create() consumer = LtiConsumer( consumer_name='consumer', consumer_key='consumer_key', consumer_secret='secret' ) consumer.save() outcome = OutcomeService( lis_outcome_service_url='http://example.com/service_url', lti_consumer=consumer, ) outcome.save() self.assignment = GradedAssignment( user=self.user, course_key=self.course_key, usage_key=self.usage_key, outcome_service=outcome, lis_result_sourcedid='sourcedid', ) self.assignment.save() @patch('requests.post', return_value='response') def test_sign_and_send_replace_result(self, post_mock): response = outcomes.sign_and_send_replace_result(self.assignment, 'xml') post_mock.assert_called_with( 'http://example.com/service_url', data='xml', auth=ANY, headers={'content-type': 'application/xml'} ) self.assertEqual(response, 'response')