class TODViewsTests(TestCase): """ """ def setUp(self): """ """ course = LTICourse(course_name="Fake Course", course_id="BlueMonkeyFake") course.save() self.assignment = Assignment(assignment_name="Test", pagination_limit=10, course=course) self.assignment.save() self.tod = TargetObject(target_title="TObj2", target_author="Test Author", target_content="Fake Content2", target_citation="Fake Citation2", target_type="tx") self.tod.save() self.assignment.assignment_objects.add(self.tod) self.tool_consumer = create_test_tc() self.other_request = self.tool_consumer.generate_launch_data() def tearDown(self): """ """ del self.assignment del self.tod del self.tool_consumer del self.other_request def test_call_view_loads(self): """ """ response = self.client.post('lti_init/launch_lti/annotation/%s/%d' % (self.assignment.assignment_id, self.tod.id), self.other_request) self.assertTrue(open_target_object(response, self.assignment.assignment_id, self.tod.id).status_code == 200) response2 = self.client.post('lti_init/launch_lti/annotation/%s/fake_id' % self.assignment.assignment_id) self.assertRaises(Http404, open_target_object, response, self.assignment.assignment_id, 34) def test_get_admin_url(self): """ """ print self.tod.get_admin_url()
class TODViewsTests(TestCase): def setUp(self): """ 1. Creates a test course. 2. Creates a test Assignment. 3. Creates a fake Target Object record. 4. Starts the LTI tool consumer and makes a data launch request. """ user = User(username="******", email="dfslkjfijeflkj") user.save() lti_profile = LTIProfile.objects.create( user=user, name=user.username, anon_id="luis123" ) lti_profile.save() course = LTICourse(course_name="Fake Course", course_id="BlueMonkeyFake") course.save() course.course_admins.add(lti_profile) self.assignment = Assignment( assignment_name="Test", pagination_limit=10, course=course ) self.assignment.save() self.tod = TargetObject( target_title="TObj2", target_author="Test Author", target_content="Fake Content2", target_citation="Fake Citation2", target_type="tx", ) self.tod.save() self.aTarget = AssignmentTargets( assignment=self.assignment, target_object=self.tod, order=1, target_external_css="", target_instructions="Fake Instructions", target_external_options="", ) self.target_path = reverse("hx_lti_initializer:launch_lti") self.launch_url = "http://testserver{}".format(self.target_path) self.resource_link_id = "some_string_to_be_the_fake_resource_link_id" self.consumer = ToolConsumer( consumer_key=settings.CONSUMER_KEY, consumer_secret=settings.LTI_SECRET, launch_url=self.launch_url, params={ "lti_message_type": "basic-lti-launch-request", "lti_version": "LTI-1p0", "resource_link_id": self.resource_link_id, "lis_person_sourcedid": lti_profile.name, "lis_outcome_service_url": "fake_url", "user_id": lti_profile.anon_id, "roles": ["Learner"], "context_id": course.course_id, }, ) self.lti_params = self.consumer.generate_launch_data() def tearDown(self): del self.assignment del self.tod def test_call_view_loads(self): lti_params = self.consumer.generate_launch_data() response0 = self.client.post(self.target_path, lti_params) self.assertTrue(response0.status_code == 302) target_url = reverse( "target_object_database:open_target_object", kwargs={"collection_id": self.assignment.id, "target_obj_id": self.tod.id,}, ) response = self.client.get(target_url) self.assertTrue(response.status_code == 200) target_url = reverse( "target_object_database:open_target_object", kwargs={"collection_id": self.assignment.id, "target_obj_id": "987654321",}, ) response = self.client.get(target_url) self.assertTrue(response.status_code == 404) '''
class TOD_ImplementationTests(TestCase): """ """ def createFakeUser(self, username, userid): user = User.objects.create_user(username, userid) user.set_unusable_password() user.is_superuser = False user.is_staff = False user.save() lti_profile = LTIProfile.objects.create(user=user) return user, lti_profile def setUp(self): """ """ self.sampleImplementation = TOD_Implementation() self.user1, self.ltiprofile1 = self.createFakeUser("fakeusername1", "fakeuserid1") self.user2, self.ltiprofile2 = self.createFakeUser("fakeusername2", "fakeuserid2") self.samplecourse = LTICourse.create_course( "fake_course", self.ltiprofile1 ) self.samplecourse.course_name = "Fake Course" self.samplecourse.save() self.target1 = TargetObject( target_title="TObj1", target_author="Test Author", target_content="Fake Content", target_citation="Fake Citation", target_type="tx" ) self.target1.save() self.target1.target_courses.add(self.samplecourse) self.target2 = TargetObject( target_title="TObj2", target_author="Test Author", target_content="Fake Content2", target_citation="Fake Citation2", target_type="tx" ) self.target2.save() self.target2.target_courses.add(self.samplecourse) def tearDown(self): """ """ del self.sampleImplementation del self.ltiprofile1 del self.ltiprofile2 del self.samplecourse del self.target1 del self.target2 def test_implentation_of_TODAPI_LTI(self): """ """ self.assertIsInstance(self.sampleImplementation, TOD_Implementation) self.assertIsInstance(self.sampleImplementation, TODAPI_LTI) def test_get_own_targets_from_course(self): """ """ self.assertTrue(len(TOD_Implementation.get_own_targets_from_course("fake_course")) == 2) # noqa self.assertRaises(ObjectDoesNotExist, TOD_Implementation.get_own_targets_from_course, 'fake_course2') # noqa course2 = LTICourse.create_course('fake_course2', self.ltiprofile1) self.assertTrue(len(TOD_Implementation.get_own_targets_from_course("fake_course2")) == 0) # noqa def test_get_dict_of_files_from_courses(self): """ """ dict_of_targets = TOD_Implementation.get_dict_of_files_from_courses( LTICourse.get_all_courses() ) self.assertIsInstance(dict_of_targets, dict) self.assertTrue(len(dict_of_targets['Fake Course']) == 2) self.assertTrue(self.target1 in dict_of_targets['Fake Course']) self.assertTrue(self.target2 in dict_of_targets['Fake Course']) def test_get_own_targets_as_user(self): """ """ self.assertTrue(len(TOD_Implementation.get_own_targets_as_user(self.ltiprofile1)) == 2) # noqa self.assertTrue(len(TOD_Implementation.get_own_targets_as_user(self.ltiprofile2)) == 0) # noqa
class TODViewsTests(TestCase): """ """ def setUp(self): """ 1. Creates a test course. 2. Creates a test Assignment. 3. Creates a fake Target Object record. 4. Starts the LTI tool consumer and makes a data launch request. """ user = User(username="******", email="dfslkjfijeflkj") user.save() lti_profile = LTIProfile.objects.create(user=user) course = LTICourse(course_name="Fake Course", course_id="BlueMonkeyFake") course.save() course.course_admins.add(lti_profile) self.assignment = Assignment(assignment_name="Test", pagination_limit=10, course=course) self.assignment.save() self.tod = TargetObject(target_title="TObj2", target_author="Test Author", target_content="Fake Content2", target_citation="Fake Citation2", target_type="tx") self.tod.save() self.aTarget = AssignmentTargets( assignment=self.assignment, target_object=self.tod, order=1, target_external_css="", target_instructions="Fake Instructions", target_external_options="") self.tool_consumer = create_test_tc() self.other_request = self.tool_consumer.generate_launch_data() def tearDown(self): """ """ del self.assignment del self.tod del self.tool_consumer del self.other_request def test_call_view_loads(self): """ """ response = self.client.post( 'lti_init/launch_lti/annotation/%s/%d' % (self.assignment.assignment_id, self.tod.id), self.other_request) self.assertTrue( open_target_object(response, self.assignment.assignment_id, self.tod.id).status_code == 200) response2 = self.client.post( 'lti_init/launch_lti/annotation/%s/fake_id' % self.assignment.assignment_id) self.assertRaises(Http404, open_target_object, response2, self.assignment.assignment_id, 34) def test_get_admin_url(self): """ """ self.assertEqual( self.tod.get_admin_url(), '/admin/target_object_database/targetobject/%d/' % self.tod.id)