def setUp(self): self.setup_sample_course() self.assignment1 = ProjectFactory.create( title='Alpha', course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') self.response1 = ProjectFactory.create( title="Response 1", course=self.sample_course, author=self.student_one, policy='InstructorShared', parent=self.assignment1) self.asset = AssetFactory(course=self.sample_course) SherdNote.objects.global_annotation( self.asset, self.student_one, auto_create=True) self.student_one_selection1 = SherdNoteFactory( asset=self.asset, author=self.student_one, tags=',student_one_selection', title="Selection", range1=116.25, range2=6.75) self.student_one_selection2 = SherdNoteFactory( asset=self.asset, author=self.student_one, title="Selection", range1=116.25, range2=6.75) self.student_two_selection = SherdNoteFactory( asset=self.asset, author=self.student_two, title="Selection", range1=16.25, range2=2.75) self.add_citation(self.response1, self.student_one_selection1) self.add_citation(self.response1, self.student_two_selection)
def test_assignment_response_tags(self): assignment = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], project_type='assignment') visible_response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=assignment, date_submitted=datetime.today()) draft_response = ProjectFactory.create(course=self.sample_course, author=self.student_two, policy=PUBLISH_DRAFT[0], parent=assignment, date_submitted=datetime.today()) request = RequestFactory().get('/') request.course = self.sample_course request.user = self.student_one responses = assignment_responses(assignment, request) self.assertEqual(len(responses), 1) self.assertEqual(responses[0], visible_response) self.assertEquals(published_assignment_responses(assignment), 1) responses = my_assignment_responses(assignment, self.student_two) self.assertEqual(responses.count(), 1) self.assertEqual(responses.first().content_object, draft_response) responses = my_assignment_responses(assignment, self.student_one) self.assertEqual(responses.count(), 1) self.assertEqual(responses.first().content_object, visible_response)
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 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_description(self): project = Project.objects.get(id=self.project_private.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Draft') project = Project.objects.get(id=self.project_class_shared.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Shared with Class') project = Project.objects.get(id=self.project_instructor_shared.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Shared with Instructor') assignment = Project.objects.get(id=self.assignment.id) self.assertEquals(assignment.description(), 'Composition Assignment') self.assertEquals(assignment.visibility_short(), 'Shared with Class') sassignment = Project.objects.get(id=self.selection_assignment.id) self.assertEquals(sassignment.description(), 'Selection Assignment') r = ProjectFactory.create(course=self.sample_course, author=self.student_one, parent=self.selection_assignment) self.assertEquals(r.description(), 'Selection Assignment Response') r = ProjectFactory.create(course=self.sample_course, author=self.student_one, parent=self.assignment) self.assertEquals(r.description(), 'Composition Assignment Response') r = ProjectFactory.create(course=self.sample_course, author=self.student_one, parent=self.sequence_assignment) self.assertEquals(r.description(), 'Sequence Assignment Response')
def test_unresponded_assignments(self): lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 3) self.assertTrue(self.selection_assignment in lst) self.assertTrue(self.sequence_assignment in lst) self.assertTrue(self.assignment in lst) # add a response & retry ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 2) self.assertTrue(self.assignment in lst) self.assertTrue(self.sequence_assignment in lst) # add a response & retry ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_DRAFT[0], parent=self.assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 1) self.assertTrue(self.sequence_assignment in lst)
def test_many_responses_by_course(self): # additional responses ensure selected collaborations/projects # don't line-up by default response1 = ProjectFactory.create( title='Zeta', course=self.sample_course, author=self.student_three, date_submitted=datetime.now(), policy=PUBLISH_WHOLE_CLASS[0], parent=self.assignment) # private response response2 = ProjectFactory.create( title='Omega', course=self.sample_course, author=self.student_one, policy=PUBLISH_DRAFT[0], parent=self.assignment) response4 = ProjectFactory.create( title='Gam', course=self.sample_course, author=self.student_three, date_submitted=datetime.now(), policy=PUBLISH_WHOLE_CLASS[0], parent=self.assignment) response4.delete() response3 = ProjectFactory.create( title='Beta', course=self.sample_course, author=self.student_two, date_submitted=datetime.now(), policy=PUBLISH_WHOLE_CLASS[0], parent=self.assignment) self.assert_responses_by_course(self.student_one, [response3, response1, response2], []) self.assert_responses_by_course(self.instructor_one, [response3, response1], [response2]) self.assert_responses_by_course(self.student_two, [response3, response1], [response2])
def test_unresponded_assignments(self): lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 2) self.assertTrue(self.selection_assignment in lst) self.assertTrue(self.assignment in lst) # add a response & retry ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PublicEditorsAreOwners', parent=self.selection_assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 1) self.assertTrue(self.assignment in lst) # add a response & retry ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 0)
def test_unresponded_assignments(self): lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 3) self.assertTrue(self.selection_assignment in lst) self.assertTrue(self.sequence_assignment in lst) self.assertTrue(self.assignment in lst) # add a response & retry ProjectFactory.create(course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 2) self.assertTrue(self.assignment in lst) self.assertTrue(self.sequence_assignment in lst) # add a response & retry ProjectFactory.create(course=self.sample_course, author=self.student_one, policy=PUBLISH_DRAFT[0], parent=self.assignment) lst = Project.objects.unresponded_assignments(self.sample_course, self.student_one) self.assertEquals(len(lst), 1) self.assertTrue(self.sequence_assignment in lst)
def test_sort(self): url = reverse('project-sort') c = self.client c.login(username=self.instructor_one.username, password='******') self.switch_course(self.client, self.sample_course) project1 = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy='CourseProtected', ordinality=0) project2 = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy='CourseProtected', ordinality=1) data = {'project': [project2.id, project1.id]} response = c.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) # ordinality should be reversed project = Project.objects.get(id=project1.id) self.assertEquals(project.ordinality, 1) project = Project.objects.get(id=project2.id) self.assertEquals(project.ordinality, 0)
def test_faculty_compositions(self): compositions = Project.objects.faculty_compositions( self.sample_course, self.student_one) self.assertEquals(len(compositions), 0) # instructor composition beta = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], ordinality=2, title='Beta') gamma = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], ordinality=3, title='Gamma') alpha = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy=PUBLISH_WHOLE_CLASS[0], ordinality=1, title='Alpha') compositions = Project.objects.faculty_compositions( self.sample_course, self.student_one) self.assertEquals(len(compositions), 3) self.assertEquals(compositions[0], alpha) self.assertEquals(compositions[1], beta) self.assertEquals(compositions[2], gamma)
def test_assignment_delete(self): ctype = ContentType.objects.get(model='project', app_label='projects') response1 = ProjectFactory.create(title='Zeta', course=self.sample_course, author=self.student_three, date_submitted=datetime.now(), policy='PublicEditorsAreOwners', parent=self.assignment) self.assertEquals(response1.assignment(), self.assignment) response2 = ProjectFactory.create(title='Omega', course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) self.assertEquals(response1.assignment(), self.assignment) project_id = self.assignment.id url = reverse('project-delete', args=[project_id]) self.client.login(username=self.instructor_one.username, password='******') self.switch_course(self.client, self.sample_course) response = self.client.post(url, {}) self.assertEquals(response.status_code, 302) with self.assertRaises(Project.DoesNotExist): Project.objects.get(id=project_id) with self.assertRaises(Collaboration.DoesNotExist): Collaboration.objects.get(content_type=ctype, object_pk=str(project_id)) self.assertIsNone(response1.assignment()) self.assertIsNone(response2.assignment())
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_migrate_materials_sample_course(self): self.project1 = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy='PrivateEditorsAreOwners') self.project2 = ProjectFactory.create(course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') self.assertTrue(self.client.login( username=self.instructor_three.username, password="******")) set_course_url = '/?set_course=%s&next=/' % \ self.sample_course.group.name response = self.client.get(set_course_url, follow=True) self.assertEquals(response.status_code, 200) url = '/dashboard/migrate/materials/%s/' % self.sample_course.id response = self.client.get(url, {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEquals(response.status_code, 200) the_json = json.loads(response.content) self.assertEquals(the_json['course']['title'], 'Sample Course') self.assertEquals(len(the_json['assets']), 1) self.assertEquals(the_json['assets'][0]['title'], self.asset1.title) self.assertEquals(the_json['assets'][0]['annotation_count'], 1) self.assertEquals(len(the_json['projects']), 1) self.assertEquals(the_json['projects'][0]['title'], self.project2.title)
def test_get_context_data_a_response(self): my_response = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) response = ProjectFactory.create(course=self.sample_course, author=self.student_two, policy='PrivateEditorsAreOwners', parent=self.assignment) url = reverse('project-workspace', args=[response.id]) request = RequestFactory().get(url) request.course = self.sample_course request.user = self.student_one view = SequenceAssignmentView() view.request = request view.project = self.assignment ctx = view.get_context_data(project_id=response.id) self.assertEquals(ctx['assignment'], self.assignment) self.assertFalse(ctx['assignment_can_edit']) self.assertFalse(ctx['response_can_edit']) self.assertEquals(ctx['my_response'], my_response) self.assertEquals(ctx['the_response'], response) self.assertEquals(ctx['responses'], [my_response]) self.assertTrue(ctx['show_instructions'])
def test_get_context_data_a_response(self): my_response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) response = ProjectFactory.create( course=self.sample_course, author=self.student_two, policy='PrivateEditorsAreOwners', parent=self.assignment) url = reverse('project-workspace', args=[response.id]) request = RequestFactory().get(url) request.course = self.sample_course request.user = self.student_one view = SequenceAssignmentView() view.request = request view.project = self.assignment ctx = view.get_context_data(project_id=response.id) self.assertEquals(ctx['assignment'], self.assignment) self.assertFalse(ctx['assignment_can_edit']) self.assertFalse(ctx['response_can_edit']) self.assertEquals(ctx['my_response'], my_response) self.assertEquals(ctx['the_response'], response) self.assertEquals(ctx['responses'], [my_response]) self.assertTrue(ctx['show_instructions'])
def test_description(self): project = Project.objects.get(id=self.project_private.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Draft') project = Project.objects.get(id=self.project_class_shared.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Published to Class') project = Project.objects.get(id=self.project_instructor_shared.id) self.assertEquals(project.description(), 'Composition') self.assertEquals(project.visibility_short(), 'Submitted to Instructor') assignment = Project.objects.get(id=self.assignment.id) self.assertEquals(assignment.description(), 'Composition Assignment') self.assertEquals(assignment.visibility_short(), 'Published to Class') sassignment = Project.objects.get(id=self.selection_assignment.id) self.assertEquals(sassignment.description(), 'Selection Assignment') r = ProjectFactory.create( course=self.sample_course, author=self.student_one, parent=self.selection_assignment) self.assertEquals(r.description(), 'Selection Assignment Response') r = ProjectFactory.create( course=self.sample_course, author=self.student_one, parent=self.assignment) self.assertEquals(r.description(), 'Composition Assignment Response') r = ProjectFactory.create( course=self.sample_course, author=self.student_one, parent=self.sequence_assignment) self.assertEquals(r.description(), 'Sequence Assignment Response')
def test_assignment_delete(self): ctype = ContentType.objects.get(model='project', app_label='projects') response1 = ProjectFactory.create( title='Zeta', course=self.sample_course, author=self.student_three, date_submitted=datetime.now(), policy='PublicEditorsAreOwners', parent=self.assignment) self.assertEquals(response1.assignment(), self.assignment) response2 = ProjectFactory.create( title='Omega', course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) self.assertEquals(response1.assignment(), self.assignment) project_id = self.assignment.id url = reverse('project-delete', args=[project_id]) self.client.login(username=self.instructor_one.username, password='******') self.switch_course(self.client, self.sample_course) response = self.client.post(url, {}) self.assertEquals(response.status_code, 302) with self.assertRaises(Project.DoesNotExist): Project.objects.get(id=project_id) with self.assertRaises(Collaboration.DoesNotExist): Collaboration.objects.get(content_type=ctype, object_pk=str(project_id)) self.assertIsNone(response1.assignment()) self.assertIsNone(response2.assignment())
def test_responses_for_bad_assignment_state(self): ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_INSTRUCTOR_SHARED[0], parent=self.assignment) self.assignment.get_collaboration().delete() r = self.assignment.responses(self.sample_course, self.instructor_one) self.assertEquals(len(r), 0)
def setUp(self): self.setup_sample_course() self.asset1 = AssetFactory(course=self.sample_course) global_annotation, created = SherdNote.objects.global_annotation( self.asset1, self.student_three, auto_create=True ) self.assertTrue(global_annotation.is_global_annotation()) whole_item_annotation = SherdNoteFactory( asset=self.asset1, author=self.student_three, title="Whole Item Selection", range1=0, range2=0 ) self.assertFalse(whole_item_annotation.is_global_annotation()) real_annotation = SherdNoteFactory( asset=self.asset1, author=self.student_three, title="Selection", range1=116.25, range2=6.75 ) self.assertFalse(real_annotation.is_global_annotation()) self.assignment1 = ProjectFactory.create( title="Alpha", course=self.sample_course, author=self.instructor_one, policy="CourseProtected", project_type="assignment", ) self.response1 = ProjectFactory.create( title="Response 1", course=self.sample_course, author=self.student_one, policy="InstructorShared", parent=self.assignment1, ) self.response2 = ProjectFactory.create( title="Response 2", date_submitted=datetime.now(), course=self.sample_course, author=self.student_two, policy="InstructorShared", parent=self.assignment1, ) self.assignment2 = ProjectFactory.create( title="Beta", course=self.sample_course, author=self.instructor_one, policy="CourseProtected", project_type="assignment", ) self.project = ProjectFactory( title="Gamma", course=self.sample_course, author=self.instructor_one, policy="CourseProtected" ) self.add_citation(self.project, global_annotation) self.add_citation(self.project, whole_item_annotation) self.add_citation(self.project, real_annotation)
def test_can_cite(self): # notes in an unsubmitted project are not citable regardless of viewer self.assertFalse( self.project_private.can_cite(self.sample_course, self.student_two)) self.assertTrue( self.project_instructor_shared.can_cite(self.sample_course, self.student_two)) # parent assignment: responses always visible response = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertTrue(response.can_cite(self.sample_course, self.student_two)) # parent assignment: responses never visible self.selection_assignment.response_view_policy = 'never' self.selection_assignment.save() self.assertFalse( response.can_cite(self.sample_course, self.student_two)) # parent assignment: responses visible after due_date passes # or on viewer submit yesterday = datetime.today() + timedelta(-1) self.selection_assignment.response_view_policy = 'submitted' self.selection_assignment.due_date = yesterday self.selection_assignment.save() self.assertTrue(response.can_cite(self.sample_course, self.student_two)) tomorrow = datetime.today() + timedelta(1) self.selection_assignment.due_date = tomorrow self.selection_assignment.save() self.assertFalse( response.can_cite(self.sample_course, self.student_two)) response = ProjectFactory.create(course=self.sample_course, author=self.student_two, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertFalse( response.can_cite(self.sample_course, self.student_two)) response = ProjectFactory.create(course=self.sample_course, author=self.student_three, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertTrue(response.can_cite(self.sample_course, self.student_two))
def test_responses_by_course(self): # no responses self.assert_responses_by_course(self.student_one, [], []) self.assert_responses_by_course(self.instructor_one, [], []) # private response response = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy=PUBLISH_DRAFT[0], parent=self.assignment) self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [], [response]) self.assert_responses_by_course(self.student_two, [], [response]) # submit response response.create_or_update_collaboration(PUBLISH_WHOLE_CLASS[0]) response.date_submitted = datetime.now() response.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [response], []) # change assignment policy to never self.assignment.response_view_policy = RESPONSE_VIEW_NEVER[0] self.assignment.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [], [response]) # change assignment policy to submitted self.assignment.response_view_policy = RESPONSE_VIEW_SUBMITTED[0] self.assignment.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [], [response]) # student_two submits response2 = ProjectFactory.create(course=self.sample_course, author=self.student_two, date_submitted=datetime.now(), policy=PUBLISH_WHOLE_CLASS[0], parent=self.assignment) self.assert_responses_by_course(self.student_one, [response, response2], []) self.assert_responses_by_course(self.instructor_one, [response, response2], []) self.assert_responses_by_course(self.student_two, [response, response2], [])
def test_faculty_compositions(self): compositions = Project.objects.faculty_compositions( self.sample_course, self.student_one) self.assertEquals(len(compositions), 0) # instructor composition ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy='CourseProtected') compositions = Project.objects.faculty_compositions( self.sample_course, self.student_one) self.assertEquals(len(compositions), 1)
def can_read_assignment_response(self, parent): # always response = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=parent) self.assertTrue(response.can_read(self.sample_course, self.student_one)) self.assertTrue(response.can_read(self.sample_course, self.student_two)) self.assertTrue( response.can_read(self.sample_course, self.instructor_one)) # never parent.response_view_policy = \ RESPONSE_VIEW_NEVER[0] parent.save() self.assertTrue(response.can_read(self.sample_course, self.student_one)) self.assertFalse( response.can_read(self.sample_course, self.student_two)) self.assertTrue( response.can_read(self.sample_course, self.instructor_one)) # submitted parent.response_view_policy = \ RESPONSE_VIEW_SUBMITTED[0] parent.save() self.assertTrue(response.can_read(self.sample_course, self.student_one)) self.assertFalse( response.can_read(self.sample_course, self.student_two)) self.assertTrue( response.can_read(self.sample_course, self.instructor_one)) # student two created a response response2 = ProjectFactory.create(course=self.sample_course, author=self.student_two, parent=parent) self.assertFalse( response.can_read(self.sample_course, self.student_two)) # student two submits his response (mock) response2.create_or_update_collaboration(PUBLISH_WHOLE_CLASS[0]) response2.date_submitted = datetime.now() response2.save() self.assertTrue(response.can_read(self.sample_course, self.student_two))
def can_read_assignment_response(self, parent): # always response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=parent) self.assertTrue(response.can_read( self.sample_course, self.student_one)) self.assertTrue(response.can_read( self.sample_course, self.student_two)) self.assertTrue(response.can_read( self.sample_course, self.instructor_one)) # never parent.response_view_policy = \ RESPONSE_VIEW_NEVER[0] parent.save() self.assertTrue(response.can_read( self.sample_course, self.student_one)) self.assertFalse(response.can_read( self.sample_course, self.student_two)) self.assertTrue(response.can_read( self.sample_course, self.instructor_one)) # submitted parent.response_view_policy = \ RESPONSE_VIEW_SUBMITTED[0] parent.save() self.assertTrue(response.can_read( self.sample_course, self.student_one)) self.assertFalse(response.can_read( self.sample_course, self.student_two)) self.assertTrue(response.can_read( self.sample_course, self.instructor_one)) # student two created a response response2 = ProjectFactory.create( course=self.sample_course, author=self.student_two, parent=parent) self.assertFalse(response.can_read( self.sample_course, self.student_two)) # student two submits his response (mock) response2.create_or_update_collaboration(PUBLISH_WHOLE_CLASS[0]) response2.date_submitted = datetime.now() response2.save() self.assertTrue(response.can_read( self.sample_course, self.student_two))
def test_responses_by_course(self): # no responses self.assert_responses_by_course(self.student_one, [], []) self.assert_responses_by_course(self.instructor_one, [], []) # private response response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_DRAFT[0], parent=self.assignment) self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [], [response]) self.assert_responses_by_course(self.student_two, [], [response]) # submit response response.create_or_update_collaboration(PUBLISH_WHOLE_CLASS[0]) response.date_submitted = datetime.now() response.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [response], []) # change assignment policy to never self.assignment.response_view_policy = RESPONSE_VIEW_NEVER[0] self.assignment.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [], [response]) # change assignment policy to submitted self.assignment.response_view_policy = RESPONSE_VIEW_SUBMITTED[0] self.assignment.save() self.assert_responses_by_course(self.student_one, [response], []) self.assert_responses_by_course(self.instructor_one, [response], []) self.assert_responses_by_course(self.student_two, [], [response]) # student_two submits response2 = ProjectFactory.create( course=self.sample_course, author=self.student_two, date_submitted=datetime.now(), policy=PUBLISH_WHOLE_CLASS[0], parent=self.assignment) self.assert_responses_by_course(self.student_one, [response, response2], []) self.assert_responses_by_course(self.instructor_one, [response, response2], []) self.assert_responses_by_course(self.student_two, [response, response2], [])
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
def test_can_cite(self): # notes in an unsubmitted project are not citable regardless of viewer self.assertFalse(self.project_private.can_cite( self.sample_course, self.student_two)) self.assertTrue(self.project_instructor_shared.can_cite( self.sample_course, self.student_two)) # parent assignment: responses always visible response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertTrue( response.can_cite(self.sample_course, self.student_two)) # parent assignment: responses never visible self.selection_assignment.response_view_policy = 'never' self.selection_assignment.save() self.assertFalse( response.can_cite(self.sample_course, self.student_two)) # parent assignment: responses visible after due_date passes # or on viewer submit yesterday = datetime.today() + timedelta(-1) self.selection_assignment.response_view_policy = 'submitted' self.selection_assignment.due_date = yesterday self.selection_assignment.save() self.assertTrue( response.can_cite(self.sample_course, self.student_two)) tomorrow = datetime.today() + timedelta(1) self.selection_assignment.due_date = tomorrow self.selection_assignment.save() self.assertFalse( response.can_cite(self.sample_course, self.student_two)) response = ProjectFactory.create( course=self.sample_course, author=self.student_two, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertFalse(response.can_cite( self.sample_course, self.student_two)) response = ProjectFactory.create( course=self.sample_course, author=self.student_three, policy=PUBLISH_WHOLE_CLASS[0], parent=self.selection_assignment, date_submitted=datetime.today()) self.assertTrue(response.can_cite( self.sample_course, self.student_two))
def test_responses(self): response1 = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='InstructorShared', parent=self.assignment) ProjectFactory.create( course=self.sample_course, author=self.student_two, policy='InstructorShared', parent=self.assignment) r = self.assignment.responses(self.sample_course, self.instructor_one) self.assertEquals(len(r), 2) r = self.assignment.responses_by(self.sample_course, self.instructor_one, self.student_one) self.assertEquals(r[0], response1)
def test_create(self): course = CourseFactory() note = SherdNoteFactory() project = ProjectFactory() r = self.client.post( reverse('sequenceasset-list'), { 'course': course.pk, 'spine': note.pk, 'project': project.pk, 'media_elements': [], 'text_elements': [], }, format='json') self.assertEqual(r.status_code, 201) sa = SequenceAsset.objects.first() self.assertEqual(sa.course, sa.course) self.assertEqual(sa.author, self.u) self.assertEqual(sa.spine, note) self.assertEqual(ProjectSequenceAsset.objects.count(), 1) psa = ProjectSequenceAsset.objects.first() self.assertEqual(psa.sequence_asset, sa) self.assertEqual(psa.project, project)
def test_set_parent(self): project = ProjectFactory.create(course=self.sample_course, author=self.student_one) self.assertIsNone(project.assignment()) project.set_parent(self.assignment.id) self.assertEquals(project.assignment(), self.assignment)
def test_get_context_data(self): response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) url = reverse('project-workspace', args=[self.assignment.id]) request = RequestFactory().get(url) request.course = self.sample_course request.user = self.student_one view = SelectionAssignmentView() view.request = request view.project = self.assignment ctx = view.get_context_data(project_id=self.assignment.id) self.assertEquals(ctx['assignment'], self.assignment) self.assertFalse(ctx['assignment_can_edit']) self.assertTrue(ctx['response_can_edit']) self.assertEquals(ctx['my_response'], response) self.assertEquals(ctx['the_response'], response) self.assertEquals(ctx['item'], self.asset) self.assertEquals(ctx['response_view_policies'], RESPONSE_VIEW_POLICY) self.assertEquals(ctx['submit_policy'], 'CourseProtected') self.assertTrue('vocabulary' in ctx) self.assertTrue('item_json' in ctx)
def test_collaboration_sync_model(self): project = ProjectFactory.create(course=self.sample_course, author=self.student_one) collaboration = project.get_collaboration() self.assertEquals(collaboration.policy_record.policy_name, PUBLISH_DRAFT[0]) project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 1) self.assertTrue(self.student_one in users) # add some participants project.participants.add(self.student_two) project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 2) self.assertTrue(self.student_one in users) self.assertTrue(self.student_two in users) # remove some participants project.participants.remove(self.student_two) project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 1) self.assertTrue(self.student_one in users) self.assertFalse(self.student_two in users)
def test_create_instructor_feedback(self): self.setup_sample_course() project = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='InstructorShared') data = { 'publish': 'PrivateStudentAndFaculty', 'inherit': 'true', 'app_label': 'projects', 'model': 'project', 'obj_pk': project.id, 'comment_html': 'Instructor Feedback' } request = RequestFactory().post('/discussion/create/', data) request.user = self.instructor_one request.course = self.sample_course request.collaboration_context, created = \ Collaboration.objects.get_or_create( content_type=ContentType.objects.get_for_model(Course), object_pk=str(self.sample_course.pk)) discussion_create(request) discussion = project.feedback_discussion() self.assertIsNotNone(discussion)
def test_course_protected(self): policy = CourseProtected() course = self.sample_course project = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='CourseProtected') collaboration = Collaboration.objects.get_for_object(project) user = self.student_one self.assertTrue(policy.read(collaboration, course, user)) self.assertTrue(policy.edit(collaboration, course, user)) self.assertTrue(policy.manage(collaboration, course, user)) self.assertTrue(policy.delete(collaboration, course, user)) user = self.student_two self.assertTrue(policy.read(collaboration, course, user)) self.assertFalse(policy.edit(collaboration, course, user)) self.assertFalse(policy.manage(collaboration, course, user)) self.assertFalse(policy.delete(collaboration, course, user)) user = self.instructor_one self.assertTrue(policy.read(collaboration, course, user)) self.assertFalse(policy.edit(collaboration, course, user)) self.assertFalse(policy.manage(collaboration, course, user)) self.assertFalse(policy.delete(collaboration, course, user))
def test_set_parent(self): project = ProjectFactory.create( course=self.sample_course, author=self.student_one) self.assertIsNone(project.assignment()) project.set_parent(self.assignment.id) self.assertEquals(project.assignment(), self.assignment)
def test_get_context_data(self): response = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners', parent=self.assignment) url = reverse('project-workspace', args=[self.assignment.id]) request = RequestFactory().get(url) request.course = self.sample_course request.user = self.student_one view = SelectionAssignmentView() view.request = request view.project = self.assignment ctx = view.get_context_data(project_id=self.assignment.id) self.assertEquals(ctx['assignment'], self.assignment) self.assertFalse(ctx['assignment_can_edit']) self.assertTrue(ctx['response_can_edit']) self.assertEquals(ctx['my_response'], response) self.assertEquals(ctx['the_response'], response) self.assertEquals(ctx['item'], self.asset) self.assertEquals(ctx['response_view_policies'], RESPONSE_VIEW_POLICY) self.assertEquals(ctx['submit_policy'], 'CourseProtected') self.assertTrue('vocabulary' in ctx) self.assertTrue('item_json' in ctx)
def test_collaboration_sync_model(self): project = ProjectFactory.create( course=self.sample_course, author=self.student_one) collaboration = project.get_collaboration() self.assertEquals(collaboration.policy_record.policy_name, 'PrivateEditorsAreOwners') project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 1) self.assertTrue(self.student_one in users) # add some participants project.participants.add(self.student_two) project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 2) self.assertTrue(self.student_one in users) self.assertTrue(self.student_two in users) # remove some participants project.participants.remove(self.student_two) project.collaboration_sync_group(collaboration) self.assertIsNotNone(collaboration.group) users = collaboration.group.user_set.all() self.assertEquals(users.count(), 1) self.assertTrue(self.student_one in users) self.assertFalse(self.student_two in users)
def test_create_instructor_feedback(self): self.setup_sample_course() project = ProjectFactory.create(course=self.sample_course, author=self.student_one, policy='InstructorShared') data = { 'publish': 'PrivateStudentAndFaculty', 'inherit': 'true', 'app_label': 'projects', 'model': 'project', 'obj_pk': project.id, 'comment_html': 'Instructor Feedback' } request = RequestFactory().post('/discussion/create/', data) request.user = self.instructor_one request.course = self.sample_course request.collaboration_context, created = \ Collaboration.objects.get_or_create( content_type=ContentType.objects.get_for_model(Course), object_pk=self.sample_course.pk) view = DiscussionCreateView() view.request = request view.post(request) discussion = project.feedback_discussion() self.assertIsNotNone(discussion)
def test_create_without_spine_with_track_elements(self): course = CourseFactory() project = ProjectFactory() note = SherdNoteFactory() r = self.client.post( reverse('sequenceasset-list'), { 'course': course.pk, 'spine': '', 'project': project.pk, 'media_elements': [ { 'media': note.pk, 'start_time': Decimal('0'), 'end_time': Decimal('10'), } ], 'text_elements': [ { 'text': 'My text', 'start_time': Decimal('0'), 'end_time': Decimal('10'), } ] }, format='json') self.assertEqual( r.status_code, 400, 'Attempting to create a SequenceAsset without a spine but ' 'with track elements should be invalid.')
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='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)
def test_create_with_track_elements_with_large_decimals(self): course = CourseFactory() note = SherdNoteFactory() note2 = SherdNoteFactory() project = ProjectFactory() r = self.client.post( reverse('sequenceasset-list'), { 'course': course.pk, 'spine': note.pk, 'project': project.pk, 'media_elements': [ { 'media': note2.pk, 'start_time': Decimal('0.9999999999992222'), 'end_time': Decimal('10.15955395959359395'), } ], 'text_elements': [ { 'text': 'My text', 'start_time': Decimal('0.19898591249142984912849218'), 'end_time': Decimal('10.853598923859285928598958392'), }, { 'text': 'My text 2', 'start_time': Decimal('11'), 'end_time': Decimal('148744.835739573575'), }, ] }, format='json') self.assertEqual(r.status_code, 201) sa = SequenceAsset.objects.first() self.assertEqual(sa.course, sa.course) self.assertEqual(sa.author, self.u) self.assertEqual(sa.spine, note) self.assertEqual(ProjectSequenceAsset.objects.count(), 1) psa = ProjectSequenceAsset.objects.first() self.assertEqual(psa.sequence_asset, sa) self.assertEqual(psa.project, project) self.assertEqual(SequenceTextElement.objects.count(), 2) e0 = SequenceTextElement.objects.first() e1 = SequenceTextElement.objects.last() self.assertEqual(e0.text, 'My text') self.assertEqual(e0.start_time, Decimal('0.19899')) self.assertEqual(e0.end_time, Decimal('10.85360')) self.assertEqual(e1.text, 'My text 2') self.assertEqual(e1.start_time, Decimal('11')) self.assertEqual(e1.end_time, Decimal('148744.83574')) self.assertEqual(SequenceMediaElement.objects.count(), 1) e0 = SequenceMediaElement.objects.first() self.assertEqual(e0.media, note2) self.assertEqual(e0.start_time, Decimal('1.00000')) self.assertEqual(e0.end_time, Decimal('10.15955'))
def test_public_view(self): assignment_response = ProjectFactory.create( date_submitted=datetime.now(), course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_WORLD[0], parent=self.assignment) response = self.client.get(assignment_response.public_url(), {}) self.assertEquals(response.status_code, 403)
def test_append_remove_child(self): parent = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy="CourseProtected", project_type="assignment" ) response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy="PrivateEditorsAreOwners" ) parent.get_collaboration().append_child(response) collaboration = response.get_collaboration() self.assertEquals(collaboration.get_parent().content_object, parent) parent.get_collaboration().remove_children() collaboration.refresh_from_db() self.assertIsNone(collaboration.get_parent())
def setUp(self): self.setup_sample_course() self.assignment = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='sequence-assignment')
def setUp(self): self.setup_sample_course() self.setup_alternate_course() self.project = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy='PrivateEditorsAreOwners', project_type='sequence-assignment')
def test_reset_publish_to_world(self): public = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PublicEditorsAreOwners') self.assertEquals(public.public_url(), '/s/collaboration/7/') Project.objects.reset_publish_to_world(self.sample_course) self.assertIsNone(public.public_url())
def test_append_remove_child(self): parent = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') response = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy='PrivateEditorsAreOwners') parent.get_collaboration().append_child(response) collaboration = response.get_collaboration() self.assertEquals(collaboration.get_parent().content_object, parent) parent.get_collaboration().remove_children() collaboration.refresh_from_db() self.assertIsNone(collaboration.get_parent())
def test_bound_assignment_form_with_responses(self): self.sample_course.add_detail(ALLOW_PUBLIC_COMPOSITIONS_KEY, 1) assignment = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_CLASS[0], project_type=PROJECT_TYPE_ASSIGNMENT) ProjectFactory.create( course=self.sample_course, author=self.student_one, title="Student One Response", policy=PUBLISH_WHOLE_CLASS[0], parent=assignment) data = {} frm = ProjectForm(self.request, instance=assignment, data=data) self.assertEquals(frm.initial['publish'], PUBLISH_WHOLE_CLASS[0]) lst = frm.fields['publish'].choices self.assertEquals(len(lst), 1) self.assertEquals(lst[0][0], PUBLISH_WHOLE_CLASS[0])
def test_create_duplicate(self): course = CourseFactory() note = SherdNoteFactory() project = ProjectFactory() r = self.client.post( reverse('sequenceasset-list'), { 'course': course.pk, 'spine': note.pk, 'project': project.pk, 'media_elements': [ ], 'text_elements': [ { 'text': 'My text', 'start_time': Decimal('0'), 'end_time': Decimal('10'), } ] }, format='json') self.assertEqual(r.status_code, 201) sa = SequenceAsset.objects.first() self.assertEqual(sa.course, sa.course) self.assertEqual(sa.author, self.u) self.assertEqual(sa.spine, note) self.assertEqual(ProjectSequenceAsset.objects.count(), 1) psa = ProjectSequenceAsset.objects.first() self.assertEqual(psa.sequence_asset, sa) self.assertEqual(psa.project, project) self.assertEqual(SequenceTextElement.objects.count(), 1) r = self.client.post( reverse('sequenceasset-list'), { 'course': course.pk, 'spine': note.pk, 'project': project.pk, 'media_elements': [ ], 'text_elements': [ { 'text': 'My text', 'start_time': Decimal('0'), 'end_time': Decimal('10'), } ] }, format='json') self.assertEqual( r.status_code, 400, 'Creating two SequenceAssets for the same combination ' 'of author / project should be invalid.') self.assertEqual(SequenceAsset.objects.count(), 1)
def setUp(self): self.setup_sample_course() self.setup_alternate_course() self.project = ProjectFactory.create( course=self.sample_course, author=self.instructor_one, policy='PrivateEditorsAreOwners', project_type='selection-assignment')
def test_responses(self): response1 = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_INSTRUCTOR_SHARED[0], parent=self.assignment) response2 = ProjectFactory.create( course=self.sample_course, author=self.student_two, policy=PUBLISH_INSTRUCTOR_SHARED[0], parent=self.assignment) r = self.assignment.responses(self.sample_course, self.instructor_one) self.assertEquals(len(r), 2) r = self.assignment.responses(self.sample_course, self.instructor_one, self.student_one) self.assertEquals(r[0], response1) r = self.assignment.responses(self.sample_course, self.instructor_one, self.student_two) self.assertEquals(r[0], response2)
def setUp(self): self.setup_sample_course() self.asset1 = AssetFactory(course=self.sample_course) global_annotation, created = SherdNote.objects.global_annotation( self.asset1, self.student_three, auto_create=True) self.assertTrue(global_annotation.is_global_annotation()) whole_item_annotation = SherdNoteFactory( asset=self.asset1, author=self.student_three, title="Whole Item Selection", range1=0, range2=0) self.assertFalse(whole_item_annotation.is_global_annotation()) real_annotation = SherdNoteFactory( asset=self.asset1, author=self.student_three, title="Selection", range1=116.25, range2=6.75) self.assertFalse(real_annotation.is_global_annotation()) self.assignment1 = ProjectFactory.create( title='Alpha', course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') self.response1 = ProjectFactory.create( title="Response 1", course=self.sample_course, author=self.student_one, policy='InstructorShared', parent=self.assignment1) self.response2 = ProjectFactory.create( title="Response 2", date_submitted=datetime.now(), course=self.sample_course, author=self.student_two, policy='InstructorShared', parent=self.assignment1) self.assignment2 = ProjectFactory.create( title='Beta', course=self.sample_course, author=self.instructor_one, policy='CourseProtected', project_type='assignment') self.project = ProjectFactory(title='Gamma', course=self.sample_course, author=self.instructor_one, policy='CourseProtected') self.add_citation(self.project, global_annotation) self.add_citation(self.project, whole_item_annotation) self.add_citation(self.project, real_annotation)
def test_reset_publish_to_world(self): public = ProjectFactory.create( course=self.sample_course, author=self.student_one, policy=PUBLISH_WHOLE_WORLD[0]) self.assertEquals( public.public_url(), '/s/%s/project/%s/' % (self.sample_course.slug(), public.id)) Project.objects.reset_publish_to_world(self.sample_course) self.assertIsNone(public.public_url())