예제 #1
0
    def test_save(self):
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image')
        asset2 = AssetFactory.create(course=self.sample_course,
                                     primary_source='youtube')

        url = reverse('project-save', args=[self.project.id])

        # author
        self.client.login(username=self.instructor_one.username,
                          password='******')
        self.switch_course(self.client, self.sample_course)
        data = {'title': 'Updated', 'body': 'Body Text', 'item': asset1.id}
        response = self.client.post(url,
                                    data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)

        # verify
        project = Project.objects.get(id=self.project.id)
        self.assertEquals(project.title, 'Updated')
        self.assertEquals(project.body, 'Body Text')
        self.assertEquals(project.assignmentitem_set.count(), 1)
        self.assertEquals(project.assignmentitem_set.first().asset, asset1)

        # swap out the asset
        data = {'title': 'Updated', 'body': 'Body Text', 'item': asset2.id}
        response = self.client.post(url,
                                    data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)
        self.assertEquals(project.assignmentitem_set.count(), 1)
        self.assertEquals(project.assignmentitem_set.first().asset, asset2)
예제 #2
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        # Sample Course Image Asset
        self.faculty_asset = AssetFactory.create(course=self.sample_course,
                                                 author=self.instructor_one,
                                                 primary_source='image')
        self.student_asset = AssetFactory.create(course=self.sample_course,
                                                 author=self.student_one,
                                                 primary_source='image')

        self.student_note1 = SherdNoteFactory(
            asset=self.faculty_asset, author=self.student_one,
            tags=',image1', body='student note on student asset')
        self.student_note2 = SherdNoteFactory(
            asset=self.student_asset, author=self.student_one,
            tags=',image2', body='student note on faculty asset')
        self.faculty_note1 = SherdNoteFactory(
            asset=self.faculty_asset, author=self.instructor_one,
            tags=',image3', body='faculty note on faculty asset')
        self.faculty_note2 = SherdNoteFactory(
            asset=self.student_asset, author=self.instructor_one,
            tags=',image4', body='faculty note on student asset')

        self.alt_asset = AssetFactory.create(course=self.alt_course,
                                             author=self.alt_student,
                                             primary_source='image')
        self.alt_note = SherdNoteFactory(
            asset=self.alt_asset, author=self.alt_student,
            tags=',image1', body='student note on student asset')

        self.faculty_composition = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='InstructorShared')
        self.student_composition = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='CourseProtected')
        self.assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='CourseProtected', project_type='assignment')
        self.assignment_response = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='PrivateEditorsAreOwners', parent=self.assignment)

        self.alt_composition = ProjectFactory.create(
            course=self.alt_course, author=self.student_one,
            policy='CourseProtected')

        self.discussion = self.create_discussion(
            self.sample_course, self.instructor_one)
        self.comment = self.add_comment(self.discussion, self.student_one)

        self.alt_discussion = self.create_discussion(
            self.alt_course, self.alt_instructor)
        self.alt_comment = self.add_comment(self.alt_discussion,
                                            self.alt_student)

        self.superuser = UserFactory(is_superuser=True, is_staff=True)
        self.add_as_faculty(self.sample_course, self.superuser)
예제 #3
0
    def test_embed_view(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        note = SherdNoteFactory(asset=asset, author=self.instructor_one,
                                title='Selection')

        nonce = '%smthc' % datetime.datetime.now().isoformat()
        digest = hmac.new(
            'secret',
            '%s:%s:%s' % (self.sample_course.id, note.id, nonce),
            hashlib.sha1).hexdigest()

        view = AssetEmbedView()
        view.request = RequestFactory().get(
            '/', {'nonce': nonce, 'hmac': digest},
            HTTP_REFERER='http://testserver/a/b/c/')
        view.request.course = self.sample_course
        view.request.user = self.instructor_one

        with self.assertRaises(Http404):
            view.get_context_data(course_id=self.sample_course.id,
                                  annot_id=note.id)

        secrets = {'http://testserver/': 'secret'}
        with self.settings(SERVER_ADMIN_SECRETKEYS=secrets):
            ctx = view.get_context_data(course_id=self.sample_course.id,
                                        annot_id=note.id)

            self.assertTrue('item' in ctx)
            self.assertEquals(ctx['item_id'], asset.id)
            self.assertEquals(ctx['selection_id'], note.id)
            self.assertEquals(ctx['presentation'], 'gallery')
            self.assertEquals(ctx['title'], 'Selection')
예제 #4
0
 def test_unicode(self):
     asset1 = AssetFactory.create(course=self.sample_course,
                                  primary_source='image',
                                  author=self.instructor_one,
                                  title="Item Title")
     self.assertEquals(asset1.__unicode__(),
                       'Item Title <%s> (Sample Course)' % asset1.id)
예제 #5
0
    def setUp(self):
        self.setup_sample_course()

        self.assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy=PUBLISH_WHOLE_CLASS[0],
            project_type='selection-assignment')

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        self.assets = Asset.objects.filter(id=self.asset.id)

        AssignmentItemFactory.create(project=self.assignment, asset=self.asset)

        self.response_one = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='PrivateEditorsAreOwners', parent=self.assignment)
        self.note_one = SherdNoteFactory(
            asset=self.asset, author=self.student_one,
            body='student one selection note', range1=0, range2=1)
        ProjectNoteFactory(project=self.response_one, annotation=self.note_one)

        self.response_two = ProjectFactory.create(
            course=self.sample_course, author=self.student_two,
            policy='PrivateEditorsAreOwners', parent=self.assignment)
        self.note_two = SherdNoteFactory(
            asset=self.asset, author=self.student_one,
            body='student one selection note', range1=0, range2=1)
        ProjectNoteFactory(project=self.response_two, annotation=self.note_two)

        self.mixin = RestrictedMaterialsMixin()
        self.mixin.request = RequestFactory().get('/')
        self.mixin.request.course = self.sample_course
예제 #6
0
    def test_get_by_args(self):
        success, asset = Asset.objects.get_by_args(
            {'foo': 'bar'}, asset__course=self.sample_course)
        self.assertFalse(success)
        self.assertIsNone(asset)

        data = {
            'title': 'Z',
            'url': 'https://www.google.com/search=X',
            'metadata-image': '',
            'image': 'data:image/jpeg;base64,/9j/'
        }
        success, asset = Asset.objects.get_by_args(
            data, asset__course=self.sample_course)
        self.assertTrue(success)
        self.assertIsNone(asset)

        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='mp4_pseudo',
                                     author=self.instructor_one)

        data = {'title': asset1.title, 'mp4_pseudo': asset1.primary.url}

        success, asset = Asset.objects.get_by_args(
            data, asset__course=self.sample_course)
        self.assertTrue(success)
        self.assertEqual(asset1, asset)
예제 #7
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        # instructor that sees both Sample Course & Alternate Course
        self.instructor_three = UserFactory(username='******')
        self.add_as_faculty(self.sample_course, self.instructor_three)
        self.add_as_faculty(self.alt_course, self.instructor_three)

        # Sample Course Image Asset
        self.asset1 = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')

        self.student_note = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',student_one_selection',
            body='student one selection note', range1=0, range2=1)
        self.student_ga = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',student_one_item',
            body='student one item note',
            title=None, range1=None, range2=None)
        self.instructor_note = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_selection,',
            body='instructor one selection note', range1=0, range2=1)
        self.instructor_ga = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_item,',
            body='instructor one item note',
            title=None, range1=None, range2=None)
예제 #8
0
    def test_get_selection(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        gann = SherdNoteFactory(
            asset=asset, author=self.instructor_one,
            title=None, range1=None, range2=None)
        note = SherdNoteFactory(asset=asset, author=self.instructor_one,
                                title='Selection')

        view = AssetEmbedListView()

        keys = ['foo-1234']
        self.assertIsNone(view.get_selection(keys, self.instructor_one))

        with self.assertRaises(Http404):
            keys = ['item-666']
            view.get_selection(keys, self.instructor_one)

        with self.assertRaises(Http404):
            keys = ['selection-666']
            view.get_selection(keys, self.instructor_one)

        keys = ['item-%s' % asset.id]
        view = AssetEmbedListView()
        self.assertEquals(view.get_selection(keys, self.instructor_one), gann)

        keys = ['selection-%s' % note.id]
        view = AssetEmbedListView()
        self.assertEquals(view.get_selection(keys, self.instructor_one), note)
예제 #9
0
    def test_upload_references(self):
        asset1 = AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29956"], "license": [""]}')
        AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29956"], "license": [""]}')
        asset3 = AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29957"], "license": [""]}')
        asset4 = AssetFactory.create(course=self.sample_course,
                                     metadata_blob='{}')

        self.assertEqual(asset1.upload_references(), 2)
        self.assertEqual(asset3.upload_references(), 1)
        self.assertEqual(asset4.upload_references(), 0)
예제 #10
0
 def test_unicode(self):
     asset1 = AssetFactory.create(course=self.sample_course,
                                  primary_source='image',
                                  author=self.instructor_one,
                                  title="Item Title")
     self.assertEqual(smart_text(asset1),
                      'Item Title <%s> (Sample Course)' % asset1.id)
예제 #11
0
    def test_get_by_args(self):
        success, asset = Asset.objects.get_by_args(
            {'foo': 'bar'}, asset__course=self.sample_course)
        self.assertFalse(success)
        self.assertIsNone(asset)

        data = {'title': 'Z',
                'url': 'https://www.google.com/search=X',
                'metadata-image': '',
                'image': 'data:image/jpeg;base64,/9j/'}
        success, asset = Asset.objects.get_by_args(
            data, asset__course=self.sample_course)
        self.assertTrue(success)
        self.assertIsNone(asset)

        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='mp4_pseudo',
                                     author=self.instructor_one)

        data = {'title': asset1.title,
                'mp4_pseudo': asset1.primary.url}

        success, asset = Asset.objects.get_by_args(
            data, asset__course=self.sample_course)
        self.assertTrue(success)
        self.assertEquals(asset1, asset)
예제 #12
0
    def test_get_selection(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        gann = SherdNoteFactory(asset=asset,
                                author=self.instructor_one,
                                title=None,
                                range1=None,
                                range2=None)
        note = SherdNoteFactory(asset=asset,
                                author=self.instructor_one,
                                title='Selection')

        view = AssetEmbedListView()

        keys = ['foo-1234']
        self.assertIsNone(view.get_selection(keys, self.instructor_one))

        with self.assertRaises(Http404):
            keys = ['item-666']
            view.get_selection(keys, self.instructor_one)

        with self.assertRaises(Http404):
            keys = ['selection-666']
            view.get_selection(keys, self.instructor_one)

        keys = ['item-%s' % asset.id]
        view = AssetEmbedListView()
        self.assertEquals(view.get_selection(keys, self.instructor_one), gann)

        keys = ['selection-%s' % note.id]
        view = AssetEmbedListView()
        self.assertEquals(view.get_selection(keys, self.instructor_one), note)
예제 #13
0
    def test_asset_title_save_as_author_global_annotation(self):
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     title="Item Title",
                                     author=self.instructor_one)

        gann = SherdNoteFactory(asset=asset1,
                                author=self.instructor_one,
                                title=None,
                                range1=None,
                                range2=None)

        self.assert_(
            self.client.login(username=self.instructor_one.username,
                              password="******"))
        self.switch_course(self.client, self.sample_course)

        # Update passing in a non-global annotation. This should fail
        post_data = {'asset-title': "Updated Item Title"}
        url = "/asset/save/%s/annotations/%s/" % (asset1.id, gann.id)
        response = self.client.post(url,
                                    post_data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)
        asset = Asset.objects.get(id=asset1.id)
        self.assertEquals(asset.title, "Updated Item Title")
예제 #14
0
    def test_image(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image')

        self.assertEqual(asset.media_type(), 'image')
        self.assertTrue(asset.primary.is_image())
        self.assertFalse(asset.primary.is_audio())
예제 #15
0
    def test_asset_detail(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        self.switch_course(self.client, self.sample_course)

        asset1 = AssetFactory.create(course=self.sample_course,
                                     author=self.instructor_one,
                                     primary_source='image')

        response = self.client.get('/asset/%s/' % asset1.id, {},
                                   HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        the_json = json.loads(response.content)
        self.assertTrue("space_owner" not in the_json)
        self.assertEquals(len(the_json["panels"]), 1)

        panel = the_json["panels"][0]
        self.assertIsNone(panel["current_annotation"])
        self.assertEquals(panel["current_asset"], asset1.id)
        self.assertEquals(panel["panel_state"], "open")
        self.assertEquals(panel["panel_state_label"], "Annotate Media")
        self.assertTrue(panel["show_collection"])
        self.assertEquals(panel["template"], "asset_workspace")
        self.assertTrue(panel["update_history"])
        self.assertEquals(len(panel["owners"]), 6)

        context = panel["context"]
        self.assertEquals(context["type"], "asset")
예제 #16
0
    def test_asset_detail(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))

        asset1 = AssetFactory.create(course=self.sample_course,
                                     author=self.instructor_one,
                                     primary_source='image')

        response = self.client.get('/asset/%s/' % asset1.id, {},
                                   HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        the_json = json.loads(response.content)
        self.assertTrue("space_owner" not in the_json)
        self.assertEquals(len(the_json["panels"]), 1)

        panel = the_json["panels"][0]
        self.assertIsNone(panel["current_annotation"])
        self.assertEquals(panel["current_asset"], str(asset1.id))
        self.assertEquals(panel["panel_state"], "open")
        self.assertEquals(panel["panel_state_label"], "Annotate Media")
        self.assertTrue(panel["show_collection"])
        self.assertEquals(panel["template"], "asset_workspace")
        self.assertTrue(panel["update_history"])
        self.assertEquals(len(panel["owners"]), 6)

        context = panel["context"]
        self.assertEquals(context["type"], "asset")
예제 #17
0
    def setUp(self):
        self.setup_sample_course()

        self.assignment = ProjectFactory.create(
            course=self.sample_course,
            author=self.instructor_one,
            policy=PUBLISH_WHOLE_CLASS[0],
            project_type="selection-assignment",
        )

        self.asset = AssetFactory.create(course=self.sample_course, primary_source="image")
        self.assets = Asset.objects.filter(id=self.asset.id)

        AssignmentItemFactory.create(project=self.assignment, asset=self.asset)

        self.response_one = ProjectFactory.create(
            course=self.sample_course, author=self.student_one, policy="PrivateEditorsAreOwners", parent=self.assignment
        )
        self.note_one = SherdNoteFactory(
            asset=self.asset, author=self.student_one, body="student one selection note", range1=0, range2=1
        )
        ProjectNoteFactory(project=self.response_one, annotation=self.note_one)

        self.response_two = ProjectFactory.create(
            course=self.sample_course, author=self.student_two, policy="PrivateEditorsAreOwners", parent=self.assignment
        )
        self.note_two = SherdNoteFactory(
            asset=self.asset, author=self.student_one, body="student one selection note", range1=0, range2=1
        )
        ProjectNoteFactory(project=self.response_two, annotation=self.note_two)

        self.mixin = RestrictedMaterialsMixin()
        self.mixin.request = RequestFactory().get("/")
        self.mixin.request.course = self.sample_course
예제 #18
0
    def test_image(self):
        asset = AssetFactory.create(
            course=self.sample_course, primary_source='image')

        self.assertEquals(asset.media_type(), 'image')
        self.assertTrue(asset.primary.is_image())
        self.assertFalse(asset.primary.is_audio())
예제 #19
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        # instructor that sees both Sample Course & Alternate Course
        self.instructor_three = UserFactory(username='******')
        self.add_as_faculty(self.sample_course, self.instructor_three)
        self.add_as_faculty(self.alt_course, self.instructor_three)

        self.sample_course = Course.objects.get(title='Sample Course')
        self.alt_course = Course.objects.get(title="Alternate Course")

        self.asset1 = AssetFactory.create(course=self.sample_course,
                                          author=self.instructor_one,
                                          primary_source='image')

        self.student_note = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',student_one_selection',
            body='student one selection note', range1=0, range2=1)
        self.student_ga = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',image, student_one_global,',
            body='student one global note',
            title=None, range1=None, range2=None)
        self.instructor_note = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_selection,',
            body='instructor one selection note', range1=1, range2=2)
        self.instructor_ga = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_global,',
            body='instructor one global note',
            title=None, range1=None, range2=None)

        self.asset2 = AssetFactory.create(course=self.sample_course,
                                          author=self.instructor_one,
                                          primary_source='video')
        self.asset2_instructor_note = SherdNoteFactory(
            asset=self.asset2, author=self.instructor_one,
            tags=',video, instructor_one_selection,',
            body='instructor one selection note', range1=0, range2=1)
        self.asset2_instructor_ga = SherdNoteFactory(
            asset=self.asset2, author=self.instructor_one,
            tags=',video, instructor_one_global,',
            body='instructor one global note',
            title=None, range1=None, range2=None)
예제 #20
0
    def test_video(self):
        asset = AssetFactory.create(
            course=self.sample_course, primary_source='youtube')

        # youtube -- asset #1
        self.assertEquals(asset.media_type(), 'video')
        self.assertFalse(asset.primary.is_image())
        self.assertFalse(asset.primary.is_audio())
예제 #21
0
    def test_asset_workspace_course_lookup(self):
        self.assertIsNone(asset_workspace_courselookup())

        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image')

        self.assertEquals(asset_workspace_courselookup(asset_id=asset1.id),
                          asset1.course)
예제 #22
0
    def test_video(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='youtube')

        # youtube -- asset #1
        self.assertEqual(asset.media_type(), 'video')
        self.assertFalse(asset.primary.is_image())
        self.assertFalse(asset.primary.is_audio())
예제 #23
0
    def test_upload_references(self):
        asset1 = AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29956"], "license": [""]}')
        AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29956"], "license": [""]}')
        asset3 = AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{"wardenclyffe-id": ["29957"], "license": [""]}')
        asset4 = AssetFactory.create(
            course=self.sample_course,
            metadata_blob='{}')

        self.assertEqual(asset1.upload_references(), 2)
        self.assertEqual(asset3.upload_references(), 1)
        self.assertEqual(asset4.upload_references(), 0)
예제 #24
0
    def test_asset_workspace_course_lookup(self):
        self.assertIsNone(asset_workspace_courselookup())

        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image')

        self.assertEquals(asset_workspace_courselookup(asset_id=asset1.id),
                          asset1.course)
예제 #25
0
    def test_get_dimensions_video(self):
        asset = AssetFactory.create(
            course=self.sample_course, primary_source='youtube')

        self.assertEquals(asset.media_type(), 'video')

        view = AssetEmbedListView()
        dims = view.get_dimensions(asset.primary)
        self.assertEquals(dims['width'], view.EMBED_VIDEO_WIDTH)
        self.assertEquals(dims['height'], view.EMBED_VIDEO_HEIGHT)
예제 #26
0
    def test_get_dimensions_video(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='youtube')

        self.assertEquals(asset.media_type(), 'video')

        view = AssetEmbedListView()
        dims = view.get_dimensions(asset.primary)
        self.assertEquals(dims['width'], EMBED_WIDTH)
        self.assertEquals(dims['height'], EMBED_HEIGHT)
예제 #27
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        # Sample Course Image Asset
        self.asset1 = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')

        self.student_note = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',student_one_selection',
            body='student one selection note', range1=0, range2=1)
        self.student_ga = SherdNoteFactory(
            asset=self.asset1, author=self.student_one,
            tags=',student_one_item',
            body='student one item note',
            title=None, range1=None, range2=None)
        self.instructor_note = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_selection,',
            body='instructor one selection note', range1=0, range2=1)
        self.instructor_ga = SherdNoteFactory(
            asset=self.asset1, author=self.instructor_one,
            tags=',image, instructor_one_item,',
            body='instructor one item note',
            title=None, range1=None, range2=None)

        # Sample Course Projects
        self.project_private = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='PrivateEditorsAreOwners')

        self.project_instructor_shared = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='InstructorShared')

        self.project_class_shared = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='CourseProtected')

        self.assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='CourseProtected', project_type='assignment')
        self.add_citation(self.assignment, self.student_note)
        self.add_citation(self.assignment, self.instructor_note)
        self.add_citation(self.assignment, self.student_ga)
        self.add_citation(self.assignment, self.instructor_ga)

        self.selection_assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='CourseProtected', project_type='selection-assignment')

        self.draft_assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='PrivateEditorsAreOwners', project_type='assignment')
예제 #28
0
    def test_metadata(self):
        asset1 = AssetFactory.create(
            course=self.sample_course, primary_source='image',
            author=self.instructor_one,
            metadata_blob='{"category": ["Education"], "author": ["CCNMTL"]}',
            title="Item Title")

        ctx = asset1.metadata()
        self.assertEquals(ctx['author'], [u'CCNMTL'])
        self.assertEquals(ctx['category'], [u'Education'])

        asset2 = AssetFactory.create(course=self.sample_course)
        self.assertEquals(asset2.metadata(), {})

        asset3 = AssetFactory.create(
            course=self.sample_course, primary_source='image',
            author=self.instructor_one,
            metadata_blob='#$%^&*()_',
            title="Item Title")
        self.assertEquals(asset3.metadata(), {})
예제 #29
0
    def setUp(self):
        self.setup_sample_course()

        self.project = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='CourseProtected')
        self.collaboration = self.project.get_collaboration()

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        self.asset2 = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')

        self.note = SherdNoteFactory(
            asset=self.asset, author=self.student_one,
            tags=',student_one_selection',
            body='student one selection note', range1=0, range2=1)

        self.note2 = SherdNoteFactory(
            asset=self.asset2, author=self.student_one, title='note2')
예제 #30
0
    def setUp(self):
        # sandbox course
        self.sandbox_course = CourseFactory(title="Mediathread Guest Sandbox")
        self.sandbox_instructor = UserFactory(username='******')
        self.sandbox_student = UserFactory(username='******')

        self.add_as_student(self.sandbox_course, self.sandbox_student)
        self.add_as_faculty(self.sandbox_course, self.sandbox_instructor)

        self.sandbox_asset_instructor = AssetFactory.create(
            course=self.sandbox_course, author=self.sandbox_instructor,
            primary_source='image')

        self.sandbox_note_instructor = SherdNoteFactory(
            asset=self.sandbox_asset_instructor,
            author=self.sandbox_instructor)
        self.sandbox_note_student = SherdNoteFactory(
            asset=self.sandbox_asset_instructor, author=self.sandbox_student)

        self.sandbox_asset_student = AssetFactory.create(
            course=self.sandbox_course, author=self.sandbox_student,
            primary_source='image')

        self.sandbox_project_instructor = ProjectFactory.create(
            course=self.sandbox_course, author=self.sandbox_instructor,
            policy='PrivateEditorsAreOwners')
        self.sandbox_project_student = ProjectFactory.create(
            course=self.sandbox_course, author=self.sandbox_student,
            policy='PrivateEditorsAreOwners')

        # sample course
        self.setup_sample_course()
        self.add_as_faculty(self.sample_course, self.sandbox_instructor)
        sample_asset = AssetFactory.create(
            course=self.sample_course, author=self.sandbox_instructor,
            primary_source='image')
        SherdNote.objects.global_annotation(
            sample_asset, self.sandbox_instructor, auto_create=True)
        ProjectFactory.create(
            course=self.sample_course, author=self.sandbox_instructor,
            policy='PrivateEditorsAreOwners')
예제 #31
0
    def test_update_reference_in_string(self):
        extra_asset = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')
        extra_note = SherdNoteFactory(asset=extra_asset,
                                      author=self.student_one)

        new_asset = AssetFactory.create(course=self.sample_course,
                                        primary_source='image')

        project = ProjectFactory.create(course=self.sample_course,
                                        author=self.student_one,
                                        policy='PrivateEditorsAreOwners')
        self.add_citation(project, self.instructor_note)
        self.add_citation(project, extra_note)

        # old-style whole-item annotation
        project.body = '%s <a class="materialCitation" \
            href="/asset/%s/">Whole Item</a></p>'                                                  % \
            (project.body, self.asset1.id)

        new_text = new_asset.update_references_in_string(
            project.body, self.asset1)

        new_asset_href = "/asset/%s/" % (new_asset.id)
        self.assertTrue(new_text.find(new_asset_href) > 0)

        old_asset_href = "/asset/%s/" % self.asset1.id
        self.assertTrue(new_text.find(old_asset_href) > 0)

        citations = SherdNote.objects.references_in_string(
            new_text, new_asset.author)
        self.assertEqual(len(citations), 3)
        self.assertEqual(citations[0].id, self.instructor_note.id)
        self.assertEqual(citations[0].asset.id, self.asset1.id)

        self.assertEqual(citations[1].id, extra_note.id)
        self.assertEqual(citations[1].asset.id, extra_asset.id)

        gann = new_asset.global_annotation(new_asset.author, False)
        self.assertEqual(citations[2].id, gann.id)
        self.assertEqual(citations[2].asset.id, new_asset.id)
예제 #32
0
    def test_update_reference_in_string(self):
        extra_asset = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')
        extra_note = SherdNoteFactory(
            asset=extra_asset, author=self.student_one)

        new_asset = AssetFactory.create(course=self.sample_course,
                                        primary_source='image')

        project = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='PrivateEditorsAreOwners')
        self.add_citation(project, self.instructor_note)
        self.add_citation(project, extra_note)

        # old-style whole-item annotation
        project.body = '%s <a class="materialCitation" \
            href="/asset/%s/">Whole Item</a></p>' % \
            (project.body, self.asset1.id)

        new_text = new_asset.update_references_in_string(project.body,
                                                         self.asset1)

        new_asset_href = "/asset/%s/" % (new_asset.id)
        self.assertTrue(new_text.find(new_asset_href) > 0)

        old_asset_href = "/asset/%s/" % self.asset1.id
        self.assertTrue(new_text.find(old_asset_href) > 0)

        citations = SherdNote.objects.references_in_string(new_text,
                                                           new_asset.author)
        self.assertEquals(len(citations), 3)
        self.assertEquals(citations[0].id, self.instructor_note.id)
        self.assertEquals(citations[0].asset.id, self.asset1.id)

        self.assertEquals(citations[1].id, extra_note.id)
        self.assertEquals(citations[1].asset.id, extra_asset.id)

        gann = new_asset.global_annotation(new_asset.author, False)
        self.assertEquals(citations[2].id, gann.id)
        self.assertEquals(citations[2].asset.id, new_asset.id)
예제 #33
0
    def test_save(self):
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image')
        asset2 = AssetFactory.create(course=self.sample_course,
                                     primary_source='youtube')

        url = reverse('project-save', args=[self.project.id])

        # author
        self.client.login(username=self.instructor_one.username,
                          password='******')
        data = {
            'title': 'Updated',
            'body': 'Body Text',
            'item': asset1.id
        }
        response = self.client.post(url, data)
        self.assertEquals(response.status_code, 405)

        response = self.client.post(url, data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)

        # verify
        project = Project.objects.get(id=self.project.id)
        self.assertEquals(project.title, 'Updated')
        self.assertEquals(project.body, 'Body Text')
        self.assertEquals(project.assignmentitem_set.count(), 1)
        self.assertEquals(project.assignmentitem_set.first().asset, asset1)

        # swap out the asset
        data = {
            'title': 'Updated',
            'body': 'Body Text',
            'item': asset2.id
        }
        response = self.client.post(url, data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)
        self.assertEquals(project.assignmentitem_set.count(), 1)
        self.assertEquals(project.assignmentitem_set.first().asset, asset2)
예제 #34
0
    def test_migrate_note_regular_annotations(self):
        alt_asset = AssetFactory.create(course=self.alt_course,
                                        primary_source='image')

        # migrate a regular annotation
        new_note = SherdNote.objects.migrate_one(
            self.instructor_note, alt_asset, self.instructor_three, True, True)
        self.assertFalse(new_note.is_global_annotation())
        self.assertEquals(new_note.author, self.instructor_three)
        self.assertEquals(new_note.title, self.instructor_note.title)
        self.assertEquals(new_note.tags, self.instructor_note.tags)
        self.assertEquals(new_note.body, self.instructor_note.body)
예제 #35
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        self.assignment = ProjectFactory.create(
            course=self.sample_course, author=self.instructor_one,
            policy='PrivateEditorsAreOwners',
            project_type='selection-assignment')

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        AssignmentItemFactory.create(project=self.assignment, asset=self.asset)
예제 #36
0
    def test_metadata(self):
        asset1 = AssetFactory.create(
            course=self.sample_course,
            primary_source='image',
            author=self.instructor_one,
            metadata_blob='{"category": ["Education"], "author": ["CCNMTL"]}',
            title="Item Title")

        ctx = asset1.metadata()
        self.assertEqual(ctx['author'], [u'CCNMTL'])
        self.assertEqual(ctx['category'], [u'Education'])

        asset2 = AssetFactory.create(course=self.sample_course)
        self.assertEqual(asset2.metadata(), {})

        asset3 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     author=self.instructor_one,
                                     metadata_blob='#$%^&*()_',
                                     title="Item Title")
        self.assertEqual(asset3.metadata(), {})
예제 #37
0
    def test_project(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image')
        note = SherdNoteFactory(
            asset=asset, author=self.student_one,
            tags=',student_one_selection',
            body='student one selection note', range1=0, range2=1)

        asset2 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image')
        to_be_deleted = SherdNoteFactory(
            asset=asset2, author=self.student_one, title='to be deleted')

        project = ProjectFactory.create(
            course=self.sample_course, author=self.student_one,
            policy='CourseProtected')

        self.add_citation(project, note)
        self.add_citation(project, to_be_deleted)
        asset2.delete()

        collaboration = project.get_collaboration()
        DiscussionIndex.update_class_references(project.body,
                                                None, None,
                                                collaboration,
                                                project.author)

        indicies = DiscussionIndex.objects.all()
        self.assertEquals(indicies.count(), 1)
        index = indicies.first()
        self.assertIsNone(index.participant)
        self.assertIsNone(index.comment)
        self.assertEquals(index.collaboration, collaboration)
        self.assertEquals(index.asset, asset)

        self.assertEquals(index.get_type_label(), 'project')
        self.assertEquals(index.content_object, asset)
        self.assertEquals(index.clump_parent(), project)
        self.assertIsNone(index.get_parent_url())
        self.assertEquals(index.body, '')
예제 #38
0
    def test_annotation_save_no_annotation_exists(self):
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     title="Item Title")

        self.assert_(self.client.login(username=self.instructor_one.username,
                                       password="******"))

        url = "/asset/save/%s/annotations/%s/" % (asset1.id, 42)
        post_data = {'annotation-range1': -4.5}
        response = self.client.post(url, post_data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 403)
예제 #39
0
    def test_create_or_update_item(self):
        project = ProjectFactory.create(
            course=self.sample_course, author=self.student_one)

        project.create_or_update_item(self.asset1.id)
        self.assertEquals(project.assignmentitem_set.first().asset,
                          self.asset1)

        asset2 = AssetFactory.create(course=self.sample_course,
                                     primary_source='youtube')

        project.create_or_update_item(asset2.id)
        self.assertEquals(project.assignmentitem_set.first().asset, asset2)
예제 #40
0
    def test_create_or_update_item(self):
        project = ProjectFactory.create(course=self.sample_course,
                                        author=self.student_one)

        project.create_or_update_item(self.asset1.id)
        self.assertEquals(project.assignmentitem_set.first().asset,
                          self.asset1)

        asset2 = AssetFactory.create(course=self.sample_course,
                                     primary_source='youtube')

        project.create_or_update_item(asset2.id)
        self.assertEquals(project.assignmentitem_set.first().asset, asset2)
예제 #41
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        self.assignment = ProjectFactory.create(
            course=self.sample_course,
            author=self.instructor_one,
            policy='PrivateEditorsAreOwners',
            project_type='selection-assignment')

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        AssignmentItemFactory.create(project=self.assignment, asset=self.asset)
예제 #42
0
    def setUp(self):
        self.setup_sample_course()

        self.project = ProjectFactory.create(course=self.sample_course,
                                             author=self.student_one,
                                             policy='CourseProtected')
        self.collaboration = self.project.get_collaboration()

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        self.asset2 = AssetFactory.create(course=self.sample_course,
                                          primary_source='image')

        self.note = SherdNoteFactory(asset=self.asset,
                                     author=self.student_one,
                                     tags=',student_one_selection',
                                     body='student one selection note',
                                     range1=0,
                                     range2=1)

        self.note2 = SherdNoteFactory(asset=self.asset2,
                                      author=self.student_one,
                                      title='note2')
예제 #43
0
    def setUp(self):
        self.setup_sample_course()

        self.assignment = ProjectFactory.create(
            course=self.sample_course,
            author=self.instructor_one,
            policy='CourseProtected',
            project_type='selection-assignment')

        self.asset = AssetFactory.create(course=self.sample_course,
                                         primary_source='image')
        AssignmentItemFactory.create(project=self.assignment, asset=self.asset)

        self.response_one = ProjectFactory.create(
            course=self.sample_course,
            author=self.student_one,
            title="Student One Response",
            policy='PrivateEditorsAreOwners',
            parent=self.assignment)
        self.note_one = SherdNoteFactory(asset=self.asset,
                                         author=self.student_one,
                                         body='student one selection note',
                                         range1=0,
                                         range2=1)
        ProjectNoteFactory(project=self.response_one, annotation=self.note_one)

        self.response_two = ProjectFactory.create(
            course=self.sample_course,
            author=self.student_two,
            policy='PrivateEditorsAreOwners',
            parent=self.assignment)
        self.note_two = SherdNoteFactory(asset=self.asset,
                                         author=self.student_two,
                                         title="Student One Response",
                                         body='student two selection note',
                                         range1=0,
                                         range2=1)
        ProjectNoteFactory(project=self.response_two, annotation=self.note_two)

        ProjectFactory.create(course=self.sample_course,
                              author=self.student_three,
                              policy='CourseProtected',
                              parent=self.assignment,
                              date_submitted=datetime.now())

        url = reverse('project-item-view',
                      args=[self.assignment.id, self.asset.id])
        self.view = ProjectItemView()
        self.view.request = RequestFactory().get(url)
        self.view.request.course = self.sample_course
예제 #44
0
    def test_migrate_note_regular_annotations(self):
        alt_asset = AssetFactory.create(course=self.alt_course,
                                        primary_source='image')

        # migrate a regular annotation
        new_note = SherdNote.objects.migrate_one(self.instructor_note,
                                                 alt_asset,
                                                 self.instructor_three, True,
                                                 True)
        self.assertFalse(new_note.is_global_annotation())
        self.assertEqual(new_note.author, self.instructor_three)
        self.assertEqual(new_note.title, self.instructor_note.title)
        self.assertEqual(new_note.tags, self.instructor_note.tags)
        self.assertEqual(new_note.body, self.instructor_note.body)
예제 #45
0
    def test_most_recent(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))

        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     author=self.instructor_one)

        response = self.client.get('/asset/most_recent/', {}, follow=True)
        self.assertEquals(response.status_code, 200)

        url = 'http://testserver/asset/%s/' % asset1.id
        self.assertEquals(response.redirect_chain, [(url, 302)])
예제 #46
0
    def test_asset_access(self):
        item = AssetFactory.create(course=self.alt_course,
                                   primary_source='image')
        note = SherdNoteFactory(asset=item, author=self.alt_instructor,
                                title="Selection", range1=1, range2=2)

        item_url = reverse('asset-view', kwargs={'asset_id': item.id})
        note_url = reverse('annotation-view',
                           kwargs={'asset_id': item.id, 'annot_id': note.id})

        # sample course members can't see alt course assets
        self.client.login(username=self.student_one.username, password='******')
        self.assertEquals(self.client.get(item_url).status_code, 404)
        self.assertEquals(self.client.get(note_url).status_code, 404)
예제 #47
0
    def test_most_recent(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        self.switch_course(self.client, self.sample_course)
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     author=self.instructor_one)

        response = self.client.get('/asset/most_recent/', {}, follow=True)
        self.assertEquals(response.status_code, 200)

        url = '/course/%s/react/asset/%s/' % \
            (self.sample_course.id, asset1.id)
        self.assertEquals(response.redirect_chain, [(url, 302)])
예제 #48
0
    def test_get_iframe_url(self):
        view = AssetEmbedListView()
        view.request = RequestFactory().get('/')
        view.request.course = self.sample_course

        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        note = SherdNoteFactory(asset=asset, author=self.instructor_one,
                                title='Selection')

        url = view.get_iframe_url('secret', note)
        prefix = 'http%3A%2F%2Ftestserver%2Fasset%2Fembed%2Fview%2F1%2F1%2F%3F'
        self.assertTrue(url.startswith(prefix))
        self.assertTrue('nonce' in url)
        self.assertTrue('hmac' in url)
예제 #49
0
    def test_annotation_save_no_annotation_exists(self):
        asset1 = AssetFactory.create(course=self.sample_course,
                                     primary_source='image',
                                     title="Item Title")

        self.assert_(
            self.client.login(username=self.instructor_one.username,
                              password="******"))
        self.switch_course(self.client, self.sample_course)

        url = "/asset/save/%s/annotations/%s/" % (asset1.id, 42)
        post_data = {'annotation-range1': -4.5}
        response = self.client.post(url,
                                    post_data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 403)
예제 #50
0
    def test_get_iframe_url(self):
        view = AssetEmbedListView()
        view.request = RequestFactory().get('/')
        view.request.course = self.sample_course

        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        note = SherdNoteFactory(asset=asset,
                                author=self.instructor_one,
                                title='Selection')

        url = view.get_iframe_url('secret', note)
        x = 'http%3A%2F%2Ftestserver%2Fasset%2Fembed%2Fview%2F{}%2F{}%2F%3F'
        prefix = x.format(self.sample_course.id, note.id)
        self.assertTrue(url.startswith(prefix))
        self.assertTrue('nonce' in url)
        self.assertTrue('hmac' in url)
예제 #51
0
    def test_migrate_note_global_annotations(self):
        alt_asset = AssetFactory.create(course=self.alt_course,
                                        primary_source='image')

        # migrate a global annotation
        global_note = SherdNote.objects.migrate_one(
            self.instructor_ga, alt_asset, self.instructor_three, True, True)
        self.assertTrue(global_note.is_global_annotation())
        self.assertEquals(global_note.author, self.instructor_three)
        self.assertEquals(global_note.title, None)
        self.assertEquals(global_note.tags, self.instructor_ga.tags)
        self.assertEquals(global_note.body, self.instructor_ga.body)

        # try to migrate another global annotation as well
        # the global annotation that was already created will come back
        another_note = SherdNote.objects.migrate_one(
            self.student_ga, alt_asset, self.instructor_three, True, True)
        self.assertEquals(another_note, global_note)
예제 #52
0
    def test_get_dimensions_image(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        primary = asset.primary

        view = AssetEmbedListView()
        dims = view.get_dimensions(primary)
        self.assertEquals(dims['width'], EMBED_WIDTH)
        self.assertEquals(dims['height'], EMBED_HEIGHT)

        # set a width/height
        primary.width = 400
        primary.height = 600
        primary.save()

        dims = view.get_dimensions(primary)
        self.assertEquals(dims['width'], EMBED_WIDTH)
        self.assertEquals(dims['height'], EMBED_HEIGHT)
예제 #53
0
    def test_migrate_selection_assignment(self):
        assignment1 = ProjectFactory.create(
            course=self.sample_course,
            author=self.instructor_one,
            policy=PUBLISH_WHOLE_CLASS[0],
            title="Assignment 1",
            response_view_policy=RESPONSE_VIEW_NEVER[0],
            project_type='selection-assignment')
        assignment2 = ProjectFactory.create(
            course=self.sample_course,
            author=self.instructor_one,
            policy=PUBLISH_WHOLE_CLASS[0],
            title="Assignment 2",
            project_type='selection-assignment')

        asset = AssetFactory.create(course=self.sample_course,
                                    title='Sample',
                                    primary_source='image')

        AssignmentItemFactory.create(project=assignment1, asset=asset)
        AssignmentItemFactory.create(project=assignment2, asset=asset)

        projects = [assignment1, assignment2]
        object_map = {'assets': {}, 'notes': {}, 'projects': {}}
        object_map = Project.objects.migrate(projects, self.alt_course,
                                             self.alt_instructor, object_map,
                                             True, True)

        self.assertEquals(self.alt_course.asset_set.count(), 1)
        alt_asset = self.alt_course.asset_set.first()
        self.assertTrue(alt_asset.title, 'Sample')
        self.assertNotEqual(alt_asset.id, asset.id)

        self.assertEquals(self.alt_course.project_set.count(), 2)

        a = Project.objects.get(course=self.alt_course, title='Assignment 1')
        self.assertEquals(a.response_view_policy, RESPONSE_VIEW_NEVER[0])
        ai = AssignmentItem.objects.get(project=a)
        self.assertEquals(ai.asset, alt_asset)

        a = Project.objects.get(course=self.alt_course, title='Assignment 2')
        ai = AssignmentItem.objects.get(project=a)
        self.assertEquals(ai.asset, alt_asset)
예제 #54
0
    def test_get_dimensions_image(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        primary = asset.primary

        view = AssetEmbedListView()
        dims = view.get_dimensions(primary)
        self.assertEquals(dims['width'], view.EMBED_IMAGE_WIDTH)
        self.assertEquals(dims['height'], view.EMBED_IMAGE_WIDTH)

        # set a width/height
        primary.width = 400
        primary.height = 600
        primary.save()

        dims = view.get_dimensions(primary)
        self.assertEquals(dims['width'], view.EMBED_IMAGE_WIDTH)
        self.assertEquals(dims['height'], 400)
예제 #55
0
    def setUp(self):
        self.setup_sample_course()
        self.setup_alternate_course()

        # instructor that sees both Sample Course & Alternate Course
        self.instructor_three = UserFactory(username='******')
        self.add_as_faculty(self.sample_course, self.instructor_three)
        self.add_as_faculty(self.alt_course, self.instructor_three)

        # Sample Course Image Asset
        self.asset1 = AssetFactory.create(course=self.sample_course,
                                          primary_source='image',
                                          author=self.instructor_one)

        self.student_note = SherdNoteFactory(asset=self.asset1,
                                             author=self.student_one,
                                             tags=',student_one_selection',
                                             body='student one selection note',
                                             range1=0,
                                             range2=1)
        self.student_ga = SherdNoteFactory(asset=self.asset1,
                                           author=self.student_one,
                                           tags=',student_one_item',
                                           body='student one item note',
                                           title=None,
                                           range1=None,
                                           range2=None)
        self.instructor_note = SherdNoteFactory(
            asset=self.asset1,
            author=self.instructor_one,
            tags=',image, instructor_one_selection,',
            body='instructor one selection note',
            range1=0,
            range2=1)
        self.instructor_ga = SherdNoteFactory(
            asset=self.asset1,
            author=self.instructor_one,
            tags=',image, instructor_one_item,',
            body='instructor one item note',
            title=None,
            range1=None,
            range2=None)
예제 #56
0
    def test_asset_detail_alternate(self):
        self.assertTrue(
            self.client.login(username=self.instructor_three.username,
                              password='******'))

        response = self.switch_course(self.client, self.sample_course)
        self.assertEquals(response.status_code, 200)

        asset1 = AssetFactory.create(course=self.alt_course,
                                     author=self.alt_instructor,
                                     primary_source='image')

        # Alternate Course Asset
        response = self.client.get('/asset/%s/' % asset1.id)
        self.assertEquals(response.status_code, 200)

        self.assertTemplateUsed(response, "assetmgr/asset_not_found.html")
        self.assertContains(response, "Oops!")
        self.assertContains(response, "Sample Course")
        self.assertContains(response, "Alternate Course")
예제 #57
0
    def test_asset_access(self):
        item = AssetFactory.create(course=self.alt_course,
                                   primary_source='image')
        note = SherdNoteFactory(asset=item,
                                author=self.alt_instructor,
                                title="Selection",
                                range1=1,
                                range2=2)

        item_url = reverse('asset-view', kwargs={'asset_id': item.id})
        note_url = reverse('annotation-view',
                           kwargs={
                               'asset_id': item.id,
                               'annot_id': note.id
                           })

        # sample course members can't see alt course assets
        self.client.login(username=self.student_one.username, password='******')
        self.assertEquals(self.client.get(item_url).status_code, 404)
        self.assertEquals(self.client.get(note_url).status_code, 404)
예제 #58
0
    def test_embed_view(self):
        asset = AssetFactory.create(course=self.sample_course,
                                    primary_source='image',
                                    author=self.instructor_one)
        note = SherdNoteFactory(asset=asset,
                                author=self.instructor_one,
                                title='Selection')

        nonce = '%smthc' % datetime.datetime.now().isoformat()
        digest = hmac.new(
            'secret'.encode('utf-8'),
            '{}:{}:{}'.format(self.sample_course.id, note.id,
                              nonce).encode('utf-8'),
            hashlib.sha1).hexdigest()

        view = AssetEmbedView()
        view.request = RequestFactory().get(
            '/', {
                'nonce': nonce,
                'hmac': digest
            },
            HTTP_REFERER='http://testserver/a/b/c/')
        view.request.course = self.sample_course
        view.request.user = self.instructor_one

        with self.assertRaises(Http404):
            view.get_context_data(course_id=self.sample_course.id,
                                  annot_id=note.id)

        secrets = {'http://testserver/': 'secret'}
        with self.settings(SERVER_ADMIN_SECRETKEYS=secrets):
            ctx = view.get_context_data(course_id=self.sample_course.id,
                                        annot_id=note.id)

            self.assertTrue('item' in ctx)
            self.assertEquals(ctx['item_id'], asset.id)
            self.assertEquals(ctx['selection_id'], note.id)
            self.assertEquals(ctx['presentation'], 'medium')
            self.assertEquals(ctx['title'], 'Selection')
예제 #59
0
    def test_asset_delete(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        self.switch_course(self.client, self.sample_course)

        asset1 = AssetFactory.create(course=self.sample_course,
                                     author=self.instructor_one,
                                     primary_source='image')
        self.student_note = SherdNoteFactory(asset=asset1,
                                             author=self.student_one)
        self.instructor_note = SherdNoteFactory(asset=asset1,
                                                author=self.instructor_one)

        response = self.client.get('/asset/delete/%s/' % asset1.id, {},
                                   HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEquals(response.status_code, 200)

        notes = asset1.sherdnote_set.filter(author=self.instructor_one)
        self.assertEquals(notes.count(), 0)
        notes = asset1.sherdnote_set.filter(author=self.student_one)
        self.assertEquals(notes.count(), 1)
예제 #60
0
    def test_migrate_note_global_annotations(self):
        alt_asset = AssetFactory.create(course=self.alt_course,
                                        primary_source='image')

        # migrate a global annotation
        global_note = SherdNote.objects.migrate_one(self.instructor_ga,
                                                    alt_asset,
                                                    self.instructor_three,
                                                    True, True)
        self.assertTrue(global_note.is_global_annotation())
        self.assertEqual(global_note.author, self.instructor_three)
        self.assertEqual(global_note.title, None)
        self.assertEqual(global_note.tags, self.instructor_ga.tags)
        self.assertEqual(global_note.body, self.instructor_ga.body)

        # try to migrate another global annotation as well
        # the global annotation that was already created will come back
        another_note = SherdNote.objects.migrate_one(self.student_ga,
                                                     alt_asset,
                                                     self.instructor_three,
                                                     True, True)
        self.assertEqual(another_note, global_note)