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)
def test_update_reference_in_string(self): old_asset = AssetFactory(course=self.sample_course, author=self.student_one) old_note = SherdNoteFactory(asset=old_asset, author=self.student_one, title="Selection", range1=43, range2=75) alt_note = SherdNoteFactory( asset=old_asset, author=self.student_one, title="Alt Selection", range1=43, range2=75 ) new_asset = AssetFactory(course=self.sample_course, author=self.student_one) new_note = SherdNoteFactory(asset=new_asset, author=self.student_one, title="Selection", range1=43, range2=75) text = ( '<p><a href="/asset/%s/annotations/%s/">Selection</a>' '</p><p><a href="/asset/%s/annotations/%s/">Selection</a>' '</p><p><a href="/asset/%s/annotations/%s/">Alt Selection</a>' '</p><a href="/asset/%s/">Global</a></p>' % (old_asset.id, old_note.id, old_asset.id, old_note.id, old_asset.id, alt_note.id, old_asset.id) ) new_text = new_note.update_references_in_string(text, old_note) citations = SherdNote.objects.references_in_string(new_text, old_note.author) self.assertEquals(len(citations), 4) self.assertEquals(citations[0].id, new_note.id) self.assertEquals(citations[0].asset.id, new_note.asset.id) self.assertEquals(citations[1].id, new_note.id) self.assertEquals(citations[1].asset.id, new_note.asset.id) self.assertEquals(citations[2].id, alt_note.id) self.assertEquals(citations[2].asset.id, old_asset.id) gann = old_asset.global_annotation(self.student_one, auto_create=False) self.assertEquals(citations[3].id, gann.id) self.assertEquals(citations[3].asset.id, old_asset.id)
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)
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')
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)
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
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())
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)
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)
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")
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)
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())
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)
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)
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)
def test_annotation_create_global(self): asset = AssetFactory(course=self.sample_course, primary_source='image') request = RequestFactory().post('/', {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') request.user = self.student_one request.course = self.sample_course response = annotation_create_global(request, asset.id) self.assertEquals(response.status_code, 200) ga = asset.global_annotation(self.student_one, auto_create=False) self.assertIsNotNone(ga) the_json = loads(response.content) self.assertEquals(the_json['asset']['id'], asset.id) self.assertEquals(the_json['annotation']['id'], ga.id) # invalid asset with self.assertRaises(Http404): annotation_create_global(request, 1234)
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')
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')
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(), {})
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')
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)
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)
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)
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)
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, '')
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)
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)
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)])
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)
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)
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)
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)
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)
def setUp(self): super(self.__class__, self).setUp() self.asset = AssetFactory(course=self.sample_course, author=self.student_one) self.ga1 = SherdNoteFactory(asset=self.asset, author=self.student_one, tags=',student_one_item', title=None, range1=None, range2=None) self.assertTrue(self.ga1.is_global_annotation()) self.note1 = SherdNoteFactory(asset=self.asset, author=self.student_one, tags=',student_one_selection', range1=0, range2=1) self.ga2 = SherdNoteFactory(asset=self.asset, author=self.student_two, tags=',student_two_item', title=None, range1=None, range2=None) self.note2 = SherdNoteFactory(asset=self.asset, author=self.student_two, tags=',student_two_selection', range1=0, range2=1) self.ga3 = SherdNoteFactory(asset=self.asset, author=self.instructor_one, tags=',instructor_one_item', title=None, range1=None, range2=None) self.note3 = SherdNoteFactory(asset=self.asset, author=self.instructor_one, tags=',image,instructor_one_selection,', range1=0, range2=1)
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")
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)
def test_get_global_annotation(self): asset = AssetFactory(course=self.sample_course) author = self.instructor_one ann, created = SherdNote.objects.global_annotation(asset, author) self.assertTrue(created) ann, created = SherdNote.objects.global_annotation(asset, author) self.assertFalse(created) self.assertEquals(ann.title, None) self.assertEquals(ann.title, None) self.assertEquals(ann.body, None) self.assertEquals(ann.tags, '') author = self.student_one ann, created = SherdNote.objects.global_annotation(asset, author) self.assertTrue(created) self.assertEquals(ann.title, None) self.assertEquals(ann.body, None) self.assertEquals(ann.tags, '')
def test_add_session_status(self): item = AssetFactory( id=1, title='Item', course=self.sample_course, author=self.student_one, primary_source='mp4_panopto') session = {'Name': 'bar', 'Id': 1} self.ingester.add_session_status( self.sample_course, session, item, self.student_one, False) messages = [m.message for m in get_messages(self.request)] self.assertTrue( 'bar (1) saved as <a href="/asset/1/">Item</a> for Student One' in messages) session = {'Name': 'bar', 'Id': 1} self.ingester.add_session_status( self.sample_course, session, item, self.student_one, True) messages = [m.message for m in get_messages(self.request)] self.assertTrue( ('bar (1) saved as <a href="/asset/1/">Item</a>' ' for Student One. <b>student_one is a new user</b>') in messages)
def test_range_as_timecode(self): asset = AssetFactory(course=self.sample_course) global_annotation, created = SherdNote.objects.global_annotation( asset, self.student_three, auto_create=True) self.assertEquals(global_annotation.range_as_timecode(), "") whole_item_annotation = SherdNoteFactory(asset=asset, author=self.student_three) self.assertEquals(whole_item_annotation.range_as_timecode(), "") real_annotation = SherdNoteFactory(asset=asset, author=self.student_three, range1=28, range2=39) self.assertEquals(real_annotation.range_as_timecode(), "0:28 - 0:39") real_annotation = SherdNoteFactory(asset=asset, author=self.student_three, range1=43, range2=75) self.assertEquals(real_annotation.range_as_timecode(), "0:43 - 01:15")
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')
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)
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)
def test_create_sherdnote_on_classmates_asset(self): """ Ensure we can create a new SherdNote (annotation) object on a classmate's asset. """ asset = AssetFactory(primary_source='image', author=self.student_one, course=self.sample_course) url = reverse('sherdnote-create', kwargs={'asset_id': asset.pk}) data = { 'title': 'note title', 'body': 'note body', 'range1': 23, 'range2': 27.565, } response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(SherdNote.objects.count(), 2) note = SherdNote.objects.get(title='note title') self.assertEqual(note.author, self.u)
def test_asset_title_save_as_non_author(self): asset1 = AssetFactory.create(course=self.sample_course, primary_source='image', title="Item Title") student_ga = SherdNoteFactory(asset=asset1, author=self.student_one, title=None, range1=None, range2=None) # Update as the asset's non-original author with ga. This should fail self.assert_( self.client.login(username=self.student_one.username, password="******")) post_data = {'asset-title': "Student Item"} url = "/asset/save/%s/annotations/%s/" % (asset1.id, student_ga.id) response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) updated_asset = Asset.objects.get(id=asset1.id) self.assertEquals(updated_asset.title, "Item Title")
def test_annotation_save(self): asset1 = AssetFactory.create(course=self.sample_course, primary_source='image', title="Item Title") note = SherdNoteFactory(asset=asset1, author=self.instructor_one) 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 url = "/asset/save/%s/annotations/%s/" % (asset1.id, note.id) post_data = {'annotation-range1': -4.5, 'annotation-range2': 23.0} response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) updated_note = SherdNote.objects.get(id=note.id) self.assertEquals(updated_note.range1, -4.5) self.assertEquals(updated_note.range2, 23.0)
def test_is_global_annotation(self): asset = AssetFactory(course=self.sample_course) global_annotation, created = SherdNote.objects.global_annotation( asset, self.student_three, auto_create=True) self.assertTrue(global_annotation.is_global_annotation()) self.assertEquals(global_annotation.display_title(), asset.title) whole_item_annotation = SherdNoteFactory(asset=asset, author=self.student_three, title="Whole Item Selection", range1=0, range2=0) self.assertFalse(whole_item_annotation.is_global_annotation()) self.assertEquals(whole_item_annotation.display_title(), 'Whole Item Selection') real_annotation = SherdNoteFactory(asset=asset, author=self.student_three, title="Selection", range1=116.25, range2=6.75) self.assertFalse(real_annotation.is_global_annotation()) self.assertEquals(real_annotation.display_title(), 'Selection')
def test_tags_split(self): asset = AssetFactory(course=self.sample_course) ann, created = SherdNote.objects.global_annotation( asset, self.instructor_one) # no tags tags = ann.tags_split() self.assertEquals(len(tags), 0) # one tag ann.tags = ',foobar' ann.save() tags = ann.tags_split() self.assertEquals(len(tags), 1) self.assertEquals(tags[0].name, 'foobar') # two tags ann.tags = ',youtube, test_instructor_item' ann.save() tags = ann.tags_split() self.assertEquals(len(tags), 2) self.assertEquals(tags[0].name, 'test_instructor_item') self.assertEquals(tags[1].name, 'youtube')
def test_assets_by_course_and_user(self): # tweak an asset to have a non-primary archive label asset2 = AssetFactory.create(course=self.sample_course, author=self.instructor_one, primary_source='image') metadata = Source.objects.create(asset=asset2, label='archive', primary=False, url="http://ccnmtl.columbia.edu") asset2.source_set.add(metadata) assets = Asset.objects.by_course_and_user(self.sample_course, self.instructor_one) self.assertEqual(assets.count(), 1) self.assertIsNotNone(assets[0], asset2) assets = Asset.objects.by_course_and_user(self.sample_course, self.student_one) self.assertEqual(assets.count(), 1) self.assertIsNotNone(assets[0], asset2) assets = Asset.objects.by_course_and_user(self.sample_course, self.student_two) self.assertEqual(assets.count(), 0)
def test_get(self): asset = AssetFactory(course=self.sample_course, primary_source='image') self.client.login(username=self.student_one.username, password='******') SherdNoteFactory(asset=asset, author=self.student_one, tags=',student_one_selection', range1=0, range2=1) SherdNoteFactory(asset=asset, author=self.student_one, tags=',student_one_item', title=None, range1=None, range2=None) response = self.client.get(self.url, {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) the_json = loads(response.content) self.assertTrue('tags' in the_json) self.assertEquals(len(the_json['tags']), 2) self.assertEquals(the_json['tags'][0]['name'], 'student_one_item') self.assertEquals(the_json['tags'][1]['name'], 'student_one_selection')
def test_annotation_create(self): data = { 'annotation-title': 'Annotation Test', 'annotation-body': 'notes go here', 'annotation-annotation_data': '', 'annotation-range1': -4.5, 'annotation-range2': 23, 'annotation-tags': 'foo,bar' } request = RequestFactory().post('/', data) request.user = self.student_one request.course = self.sample_course with self.assertRaises(Http404): annotation_create(request, 1234) asset = AssetFactory(course=self.sample_course, primary_source='image') response = annotation_create(request, asset.id) self.assertEquals(response.status_code, 302) note = SherdNote.objects.get(title='Annotation Test', asset=asset) self.assertEquals(note.range1, -4.5) self.assertEquals(note.range2, 23) self.assertEquals(note.tags, 'foo,bar')
def test_exclude_primary_types(self): asset2 = AssetFactory( course=self.sample_course, author=self.student_one, primary_source='youtube', ) youtube_note = SherdNoteFactory(asset=asset2, author=self.student_one, tags=',student_one_selection', range1=0, range2=1) qs = SherdNote.objects.filter(author=self.student_one) self.assertEquals(qs.count(), 3) notes = qs.exclude_primary_types(['youtube']) self.assertEquals(notes.count(), 2) self.assertTrue(self.student_one_ga in notes) self.assertTrue(self.student_one_note in notes) notes = qs.exclude_primary_types(['image']) self.assertEquals(notes.count(), 1) self.assertEquals(notes[0], youtube_note)
def test_order_by(self): self.assertTrue( self.client.login(username=self.student_one.username, password='******')) asset1 = AssetFactory.create(title='abcde', course=self.sample_course, author=self.student_one, primary_source='image') SherdNoteFactory(asset=asset1, author=self.student_one) asset2 = AssetFactory.create(title='zebra', course=self.sample_course, author=self.student_one, primary_source='image') SherdNoteFactory(asset=asset2, author=self.student_one) asset3 = AssetFactory.create(title='maurice', course=self.sample_course, author=self.instructor_one, primary_source='image') SherdNoteFactory(asset=asset3, author=self.student_one) asset4 = AssetFactory.create(title='ZZzzzzz', course=self.sample_course, author=self.student_one, primary_source='image') SherdNoteFactory(asset=asset4, author=self.student_one) # Make 50 more items in this course to trigger pagination for i in range(50): asset = AssetFactory.create(title='item {}'.format(i), course=self.sample_course, author=self.student_one, primary_source='image') SherdNoteFactory(asset=asset, author=self.student_one) url = '/api/asset/?order_by=title' response = self.client.get(url) the_json = json.loads(response.content) self.assertEqual(the_json.get('asset_count'), 56) objects = the_json['assets'] self.assertEqual(len(objects), 20) self.assertEqual(objects[0]['primary_type'], 'image') self.assertEqual(objects[0]['title'], 'abcde') self.assertEqual(objects[10]['title'], 'item 17') self.assertEqual(objects[19]['title'], 'item 25') url = '/api/asset/?order_by=-title' response = self.client.get(url) the_json = json.loads(response.content) self.assertEqual(the_json.get('asset_count'), 56) objects = the_json['assets'] self.assertEqual(len(objects), 20) self.assertEqual(objects[0]['title'], 'ZZzzzzz') self.assertEqual(objects[0]['primary_type'], 'image') self.assertEqual(objects[19]['title'], 'item 40') url = '/api/asset/?order_by=author' response = self.client.get(url) the_json = json.loads(response.content) self.assertEqual(the_json.get('asset_count'), 56) objects = the_json['assets'] self.assertEqual(len(objects), 20) self.assertEqual(objects[0]['primary_type'], 'image') url = '/api/asset/?order_by=-author' response = self.client.get(url) the_json = json.loads(response.content) self.assertEqual(the_json.get('asset_count'), 56) objects = the_json['assets'] self.assertEqual(len(objects), 20) self.assertEqual(objects[0]['primary_type'], 'image')
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=PUBLISH_DRAFT[0]) self.project_instructor_shared = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_INSTRUCTOR_SHARED[0], date_submitted=datetime.today()) self.project_class_shared = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0]) self.assignment = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], 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=PUBLISH_WHOLE_CLASS[0], project_type=PROJECT_TYPE_SELECTION_ASSIGNMENT) self.sequence_assignment = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], project_type=PROJECT_TYPE_SEQUENCE_ASSIGNMENT) self.draft_assignment = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy=PUBLISH_DRAFT[0], project_type='assignment')
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)
def test_filter_by_vocabulary(self): taxonomy = { 'Shapes': ['Square', 'Triangle'], 'Colors': ['Red', 'Blue', 'Green'] } self.create_vocabularies(self.sample_course, taxonomy) a1 = AssetFactory(course=self.sample_course, author=self.student_one) note1 = SherdNoteFactory(asset=a1, author=self.student_one, title="The Award", tags=',student_one_selection', body='student one selection note', range1=0, range2=1) note2 = SherdNoteFactory(asset=a1, author=self.student_two, title="Nice Tie", tags=',student_two_selection', body='student two selection note', range1=0, range2=1) note3 = SherdNoteFactory(asset=a1, author=self.instructor_one, title="Our esteemed leaders", tags=',image, instructor_one_selection,', body='instructor one selection note', range1=0, range2=1) # OR'd within vocabulary, AND'd across vocabulary shapes = Vocabulary.objects.get(name='shapes') colors = Vocabulary.objects.get(name='colors') red = Term.objects.get(name='red') blue = Term.objects.get(name='blue') green = Term.objects.get(name='green') square = Term.objects.get(name='square') triangle = Term.objects.get(name='triangle') self.create_term_relationship(note1, red) self.create_term_relationship(note2, blue) self.create_term_relationship(note3, red) self.create_term_relationship(note3, square) # get all notes that are tagged red or blue ctx = {'%s' % colors.id: [red.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 2) ctx = {'%s' % colors.id: [blue.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 1) ctx = {'%s' % colors.id: [red.id, blue.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 3) ctx = {'%s' % shapes.id: [square.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 1) ctx = {'%s' % colors.id: [blue.id], '%s' % shapes.id: [square.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 0) ctx = {'%s' % colors.id: [red.id], '%s' % shapes.id: [square.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 1) self.assertEquals(notes[0].title, "Our esteemed leaders") ctx = {'%s' % shapes.id: [triangle.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 0) ctx = {'%s' % colors.id: [green.id], '%s' % shapes.id: [triangle.id]} notes = SherdNote.objects.filter_by_vocabulary(ctx) self.assertEquals(notes.count(), 0)
def test_create_sherdnote_with_tags_and_terms(self): """ Ensure we can create a new SherdNote (annotation) object with tags and terms. """ taxonomy = { 'Shapes': ['Square', 'Triangle'], 'Colors': ['Red', 'Blue', 'Green'] } self.create_vocabularies(self.sample_course, taxonomy) vocab1 = self.sample_course.vocabulary_set.first() vocab2 = self.sample_course.vocabulary_set.last() term1 = vocab1.term_set.first() term2 = vocab1.term_set.all()[1] term3 = vocab2.term_set.last() asset = AssetFactory(primary_source='image', author=self.u, course=self.sample_course) url = reverse('sherdnote-create', kwargs={'asset_id': asset.pk}) response = self.client.post(url, {}, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, 'Empty POST data fails') data = { 'title': 'Image annotation', 'body': 'Image annotation body', 'range1': -2, 'range2': -1, 'tags': 'tag1 tag2 abc', 'terms': [term1.pk, term2.pk, term3.pk], 'annotation_data': { 'geometry': { 'type': 'Polygon', 'coordinates': [[[[276.88964843749994, 128.6806640625], [323.78417968749994, 14.2275390625], [435.80566406249994, 100.990234375], [276.88964843749994, 128.6806640625]]]] }, 'default': False, 'x': -2, 'y': -1, 'zoom': 1, 'extent': [ 276.88964843749994, 14.2275390625, 435.80566406249994, 128.6806640625 ] } } response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(SherdNote.objects.count(), 2) note = SherdNote.objects.get(title='Image annotation') self.assertEqual(note.body, 'Image annotation body') self.assertEqual(note.range1, -2) self.assertEqual(note.range2, -1) self.assertEqual(note.author, self.u) self.assertEqual(note.tags, 'tag1 tag2 abc') self.assertEqual(len(note.termrelationship_set.all()), 3) # Test annotation data (this saves/loads as JSON text) annotation_data = note.annotation() self.assertEqual(annotation_data['geometry']['type'], 'Polygon') self.assertEqual(annotation_data['geometry']['coordinates'][0][0][0], [276.88964843749994, 128.6806640625]) self.assertEqual(annotation_data['extent'], [ 276.88964843749994, 14.2275390625, 435.80566406249994, 128.6806640625 ])
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) # Sample Course Projects self.project_private = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners') self.add_citation(self.project_private, self.student_note) self.add_citation(self.project_private, self.student_ga) self.project_instructor_shared = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='InstructorShared') self.add_citation(self.project_instructor_shared, self.student_note) self.add_citation(self.project_instructor_shared, self.student_ga) self.project_class_shared = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='CourseProtected') self.add_citation(self.project_class_shared, self.student_note) self.add_citation(self.project_class_shared, self.student_ga) self.assignment = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') # Alt Course Projects self.project_private_alt_course = ProjectFactory.create( course=self.alt_course, author=self.alt_student, policy='PrivateEditorsAreOwners') self.project_public_alt_course = ProjectFactory.create( course=self.alt_course, author=self.alt_student, policy='PrivateEditorsAreOwners')