예제 #1
0
 def test_success_merge_multiple_groups_db(self):
     testuser = mommy.make(settings.AUTH_USER_MODEL)
     testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
     group1 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group2 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group3 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group4 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group2)
     core_mommy.candidate(group=group3)
     core_mommy.candidate(group=group4)
     core_mommy.examiner(group=group1)
     core_mommy.examiner(group=group2)
     core_mommy.examiner(group=group3)
     core_mommy.examiner(group=group4)
     self.mock_http302_postrequest(
         cradmin_role=testassignment,
         cradmin_instance=self.__mockinstance_with_devilryrole('departmentadmin'),
         requestuser=testuser,
         requestkwargs={
             'data': {
                 'selected_items': [group1.id, group2.id, group3.id, group4.id]
             }
         })
     self.assertFalse(AssignmentGroup.objects.filter(id=group2.id).exists())
     self.assertFalse(AssignmentGroup.objects.filter(id=group3.id).exists())
     self.assertFalse(AssignmentGroup.objects.filter(id=group4.id).exists())
     self.assertTrue(AssignmentGroup.objects.filter(id=group1.id).exists())
예제 #2
0
 def test_success_merge_multiple_groups_db(self):
     testuser = mommy.make(settings.AUTH_USER_MODEL)
     testassignment = mommy.make_recipe(
         'devilry.apps.core.assignment_activeperiod_start')
     group1 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group2 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group3 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group4 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group2)
     core_mommy.candidate(group=group3)
     core_mommy.candidate(group=group4)
     core_mommy.examiner(group=group1)
     core_mommy.examiner(group=group2)
     core_mommy.examiner(group=group3)
     core_mommy.examiner(group=group4)
     self.mock_http302_postrequest(
         cradmin_role=testassignment,
         cradmin_instance=self.__mockinstance_with_devilryrole(
             'departmentadmin'),
         requestuser=testuser,
         requestkwargs={
             'data': {
                 'selected_items':
                 [group1.id, group2.id, group3.id, group4.id]
             }
         })
     self.assertFalse(AssignmentGroup.objects.filter(id=group2.id).exists())
     self.assertFalse(AssignmentGroup.objects.filter(id=group3.id).exists())
     self.assertFalse(AssignmentGroup.objects.filter(id=group4.id).exists())
     self.assertTrue(AssignmentGroup.objects.filter(id=group1.id).exists())
예제 #3
0
 def test_examiner_count_filter(self):
     testuser = mommy.make(settings.AUTH_USER_MODEL)
     testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
     group1 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group2 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group2)
     core_mommy.examiner(group=group2)
     core_mommy.examiner(group=group2)
     mockresponse = self.mock_http200_getrequest_htmls(
         cradmin_role=testassignment,
         cradmin_instance=self.__mockinstance_with_devilryrole('departmentadmin'),
         requestuser=testuser,
         viewkwargs={
             'filters_string': 'examinercount-eq-2'
         })
     self.assertEqual(
         1,
         mockresponse.selector.count('.django-cradmin-listbuilder-itemvalue'))
예제 #4
0
 def test_examiner_count_filter(self):
     testuser = mommy.make(settings.AUTH_USER_MODEL)
     testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
     group1 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     group2 = mommy.make('core.AssignmentGroup', parentnode=testassignment)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group1)
     core_mommy.candidate(group=group2)
     core_mommy.examiner(group=group2)
     core_mommy.examiner(group=group2)
     mockresponse = self.mock_http200_getrequest_htmls(
         cradmin_role=testassignment,
         cradmin_instance=self.__mockinstance_with_devilryrole('departmentadmin'),
         requestuser=testuser,
         viewkwargs={
             'filters_string': 'examinercount-2'
         })
     self.assertEqual(
         1,
         mockresponse.selector.count('.django-cradmin-listbuilder-itemvalue'))
    def test_merge_assignmentgroup_multiple_times(self):
        test_assignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        group1 = mommy.make('core.AssignmentGroup', parentnode=test_assignment, name='group1')
        group2 = mommy.make('core.AssignmentGroup', parentnode=test_assignment, name='group2')
        group3 = mommy.make('core.AssignmentGroup', parentnode=test_assignment, name='group3')
        group4 = mommy.make('core.AssignmentGroup', parentnode=test_assignment, name='group4')

        core_mommy.candidate(group=group1)
        core_mommy.candidate(group=group1)
        core_mommy.candidate(group=group2)
        core_mommy.candidate(group=group3)
        core_mommy.candidate(group=group4)
        core_mommy.examiner(group=group1)
        core_mommy.examiner(group=group2)
        core_mommy.examiner(group=group2)
        core_mommy.examiner(group=group3)
        group1_state = group1.get_current_state()
        group2_state = group2.get_current_state()
        group3_state = group3.get_current_state()
        group4_state = group4.get_current_state()

        AssignmentGroup.merge_groups([group1, group3])
        AssignmentGroup.merge_groups([group2, group4])

        group1_merge_history = AssignmentGroupHistory.objects.get(assignment_group__id=group1.id).merge_history
        group2_merge_history = AssignmentGroupHistory.objects.get(assignment_group__id=group2.id).merge_history
        self.assertDictEqual(group1_merge_history['groups'][0]['state'], group1_state)
        self.assertDictEqual(group1_merge_history['groups'][1]['state'], group3_state)
        self.assertDictEqual(group2_merge_history['groups'][0]['state'], group2_state)
        self.assertDictEqual(group2_merge_history['groups'][1]['state'], group4_state)
        group1 = AssignmentGroup.objects.get(id=group1.id)
        group2 = AssignmentGroup.objects.get(id=group2.id)

        # Checking one more level in the Btree
        group1_state = AssignmentGroup.objects.get(id=group1.id).get_current_state()
        group2_state = AssignmentGroup.objects.get(id=group2.id).get_current_state()
        AssignmentGroup.merge_groups([group1, group2])
        group1_merge_history_new = AssignmentGroupHistory.objects.get(assignment_group__id=group1.id).merge_history
        self.assertListEqual(group1_merge_history_new['groups'][0]['groups'], group1_merge_history['groups'])
        self.assertListEqual(group1_merge_history_new['groups'][1]['groups'], group2_merge_history['groups'])
        self.assertDictEqual(group1_merge_history_new['groups'][0]['state'], group1_state)
        self.assertDictEqual(group1_merge_history_new['groups'][1]['state'], group2_state)