コード例 #1
0
    def setUp(self):
        today = date.today()
        self.academic_year = AcademicYearFactory(year=today.year, start_date=today)

        # Creation Container / UE and components related
        self.l_container = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1210",
                                                        in_charge=True)
        _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container,
                                                   acronym="LBIR1210",subtype=learning_unit_year_subtypes.FULL)
        _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container,
                                                   acronym="LBIR1210A", subtype=learning_unit_year_subtypes.PARTIM)
        _create_learning_unit_year_with_components(academic_year=self.academic_year, l_container=self.l_container,
                                                   acronym="LBIR1210B", subtype=learning_unit_year_subtypes.PARTIM)

        # Creation Tutors
        self.tutor_1 = TutorFactory(person=PersonFactory(first_name="Tom", last_name="Dupont", global_id='00012345'))
        self.tutor_2 = TutorFactory(person=PersonFactory(first_name="Paul", last_name="Durant", global_id='08923545'))

        # Creation Attribution and Attributions Charges - Tutor 1 - Holder
        attribution_tutor_1 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1,
                                                    function=function.HOLDER)
        _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210", Decimal(15.5), Decimal(10))
        _create_attribution_charge(self.academic_year, attribution_tutor_1, "LBIR1210A", None, Decimal(5))

        # Creation Attribution and Attributions Charges - Tutor 2 - Co-holder
        attribution_tutor_2 = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_2,
                                                    function=function.CO_HOLDER)
        _create_attribution_charge(self.academic_year, attribution_tutor_2, "LBIR1210B", Decimal(7.5))
コード例 #2
0
    def test_post_overview_with_lecturing_and_practical_component_partim(self):
        lbira2101a_next = _create_learning_container_with_components("LBIRA2101A", self.application_academic_year,
                                                                     volume_lecturing=20, volume_practical_exercices=20,
                                                                         subtype=learning_unit_year_subtypes.PARTIM)
        lbira2101a_current = _create_learning_container_with_components(
            "LBIRA2101A", self.current_academic_year,
            volume_lecturing=20, volume_practical_exercices=20,
            subtype=learning_unit_year_subtypes.PARTIM)
        _link_components_and_learning_unit_year_to_container(lbira2101a_current, "LBIRA2101",
                                                             subtype=learning_unit_year_subtypes.FULL)
        _link_components_and_learning_unit_year_to_container(lbira2101a_next, "LBIRA2101",
                                                             subtype=learning_unit_year_subtypes.FULL)
        self.attribution.delete()
        self.attribution = AttributionNewFactory(
            global_id=self.tutor.person.global_id,
            applications=[_get_application_example(lbira2101a_next, "10", "10")]
        )

        url = reverse('applications_overview')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertEqual(len(context['applications']), 1)
        self.assertEqual(context['applications'][0]['acronym'], lbira2101a_next.acronym)
        with self.assertRaises(KeyError):
            context['applications'][0]['PRACTICAL_EXERCISES']
        with self.assertRaises(KeyError):
            context['applications'][0]['LECTURING']
コード例 #3
0
    def setUp(self):
        self.academic_year = AcademicYearFactory(year=2017)
        external_id = tutor_application_epc.LEARNING_CONTAINER_YEAR_PREFIX_EXTERNAL_ID + '35654987_2017'
        self.lbir1200 = LearningUnitYearFactory(
            academic_year=self.academic_year,
            acronym="LBIR1200",
            learning_container_year__academic_year=self.academic_year,
            learning_container_year__acronym="LBIR1200",
            learning_container_year__external_id=external_id)
        self.lagro2630 = LearningUnitYearFactory(
            academic_year=self.academic_year,
            acronym="LAGRO2630",
            learning_container_year__academic_year=self.academic_year,
            learning_container_year__acronym="LAGRO2630",
        )

        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        person = PersonFactory(global_id="98363454")
        external_id = tutor_application_epc.TUTOR_PREFIX_EXTERNAL_ID + '2089590559'
        self.tutor = TutorFactory(external_id=external_id, person=person)

        # Create two tutor applications
        applications = [
            _get_application_example(self.lbir1200, '30.5', '40.5'),
            _get_application_example(self.lagro2630, '12.5', '0')
        ]
        self.attribution = AttributionNewFactory(global_id=person.global_id,
                                                 applications=applications)
コード例 #4
0
    def setUp(self):
        # Create academic year
        self.academic_year = AcademicYearFactory(year=2017)
        # Create several learning container year - 2017
        self.lbir1200_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1200")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1200_2017)
        self.lbir1250_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1250")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1250_2017)
        self.lbir1300_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1300")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1300_2017)
        self.lagro1200_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LAGRO1200")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lagro1200_2017)

        # Create several learning container year - 2016
        self.academic_year_2016 = AcademicYearFactory(year=2016)
        self.lbir1200_2016 = LearningContainerYearFactory(academic_year=self.academic_year_2016, acronym="LBIR1200")
        LearningUnitYearFactory(academic_year=self.academic_year_2016, learning_container_year=self.lbir1200_2016)
        self.lbir1250_2016 = LearningContainerYearFactory(academic_year=self.academic_year_2016, acronym="LBIR1250")
        LearningUnitYearFactory(academic_year=self.academic_year_2016, learning_container_year=self.lbir1250_2016)

        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        person = PersonFactory(global_id="98363454")
        self.tutor = TutorFactory(person=person)

        applications = [
            _get_application_example(self.lbir1200_2017, '3.5', '35.6'),  # Application 2017
            _get_application_example(self.lbir1300_2017, '7.5', '25'),   # Application 2017
            _get_application_example(self.lbir1200_2016, '2', '30'),  # Application 2016
        ]
        self.attribution = AttributionNewFactory(global_id=person.global_id,
                                                 attributions=_get_attributions_default(),
                                                 applications=applications)
コード例 #5
0
    def setUp(self):
        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        self.person = PersonFactory(global_id="98363454")
        TutorFactory(person=self.person)

        _create_multiple_academic_year()
        self.current_academic_year = create_current_academic_year()

        # Creation Json which will be store on attribution
        attributions = _get_attributions_dict(self.current_academic_year.year)
        self.attrib = AttributionNewFactory(global_id=self.person.global_id,
                                            attributions=attributions)
コード例 #6
0
    def setUp(self):
        # Create Group tutor
        Group.objects.create(name="tutors")

        # Create user
        user = UserFactory(username="******")
        person = PersonFactory(global_id="578945612", user=user)
        self.tutor = TutorFactory(person=person)

        # Add permission and log into app
        add_permission(user, "can_access_attribution_application")
        self.client.force_login(user)

        # Create current academic year
        self.current_academic_year = create_current_academic_year()

        # Create application year
        # Application is always next year
        self.application_academic_year = AcademicYearFactory(

            year=self.current_academic_year.year + 1
        )

        # Create Event to allow teacher to register
        start_date = datetime.datetime.today() - datetime.timedelta(days=10)
        end_date = datetime.datetime.today() + datetime.timedelta(days=15)
        self.academic_calendar = AcademicCalendarFactory(
            academic_year=self.current_academic_year,
            reference=academic_calendar_type.TEACHING_CHARGE_APPLICATION,
            start_date=start_date,
            end_date=end_date
        )
        self.agro_entity = EntityFactory()
        self.agro_entity_version = EntityVersionFactory(entity=self.agro_entity, acronym="AGRO",
                                                        entity_type='FACULTY',
                                                        start_date=self.academic_calendar.start_date,
                                                        end_date=self.academic_calendar.end_date)

        self.drt_entity = EntityFactory()
        self.drt_entity_version = EntityVersionFactory(entity=self.drt_entity, acronym="DRT",
                                                       entity_type='FACULTY',
                                                       start_date=self.academic_calendar.start_date,
                                                       end_date=self.academic_calendar.end_date)

        # Creation context with multiple learning container year
        self._create_multiple_learning_container_year()
        self.attribution = AttributionNewFactory(
            global_id=person.global_id,
            applications=self._get_default_application_list(),
            attributions=self._get_default_attribution_list()
        )
コード例 #7
0
    def test_delete_all_learning_units_year_case_success_have_attribution_new_without_charge(
            self):
        learning_unit_years = self.learning_unit_year_list
        ly1 = learning_unit_years[1]
        AttributionNewFactory(
            learning_container_year=ly1.learning_container_year)
        request_factory = RequestFactory()

        request = request_factory.post(
            reverse(delete_all_learning_units_year, args=[ly1.id]))
        request.user = self.user
        setattr(request, 'session', 'session')
        setattr(request, '_messages', FallbackStorage(request))

        response = delete_all_learning_units_year(request, ly1.id)

        msg_level = [m.level for m in get_messages(request)]
        msg = [m.message for m in get_messages(request)]
        self.assertEqual(len(msg), 5)
        self.assertIn(messages.SUCCESS, msg_level)

        for y in range(4):
            self.assertFalse(
                LearningUnitYear.objects.filter(
                    pk=learning_unit_years[y].pk).exists())

        # Check redirection to identification
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url, reverse('learning_units'))
コード例 #8
0
    def test_post_overview_with_lecturing_and_practical_component_partim(self):
        self.attribution.delete()
        self.attribution = AttributionNewFactory(
            global_id=self.tutor.person.global_id,
            applications=[_get_application_example(self.lbira2101_next, "10", "10")]
        )

        url = reverse('applications_overview')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[-1]
        self.assertEqual(len(context['applications']), 1)
        self.assertEqual(context['applications'][0]['acronym'], self.lbira2101_next.acronym)
        with self.assertRaises(KeyError):
            context['applications'][0]['PRACTICAL_EXERCISES']
        with self.assertRaises(KeyError):
            context['applications'][0]['LECTURING']
コード例 #9
0
 def test_find_no_teachers_for_year(self):
     AttributionNewFactory(global_id="123456789",
                           attributions=[{
                               'year': YEAR_2017,
                               'acronym': LCHM1111
                           }])
     results = mdl_attribution.attribution_new.find_teachers(
         LCHM1111, YEAR_2016)
     self.assertEqual(len(results), 0)
コード例 #10
0
    def test_get_2_teachers_in_order(self):
        acronym_LCHM1111 = 'LCHM1111'
        acronym_LDVLP2627 = 'LDVLP2627'
        acronym_LDROI1110 = 'LDROI1110'

        # Create first teacher with one attribution on LCHM1111 and others
        person_first_alphabetical_order = PersonFactory(global_id='12345678',
                                                        last_name='Antonelli')
        attribution_teacher_1_LCHM1111 = {
            'year': 2017,
            'acronym': acronym_LCHM1111
        }
        attributions_teacher1 = [
            attribution_teacher_1_LCHM1111, {
                'year': 2016,
                'acronym': acronym_LDVLP2627
            }, {
                'year': 2017,
                'acronym': acronym_LDVLP2627
            }, {
                'year': 2017,
                'acronym': acronym_LDROI1110
            }
        ]

        AttributionNewFactory(
            global_id=person_first_alphabetical_order.global_id,
            attributions=attributions_teacher1)
        # Create second teacher with one attribution on LCHM1111
        person_second_alphabetical_order = PersonFactory(global_id='987654321',
                                                         last_name='Barnet')
        attribution_teacher_2_LCHM1111 = {
            'year': 2017,
            'acronym': acronym_LCHM1111
        }
        attributions_teacher2 = [attribution_teacher_2_LCHM1111]
        AttributionNewFactory(
            global_id=person_second_alphabetical_order.global_id,
            attributions=attributions_teacher2)
        #
        attributions_result = attribution.get_teachers(acronym_LCHM1111, 2017)
        self.assertEqual(len(attributions_result), 2)
        self.assertEqual(attributions_result[0][attribution.PERSON_KEY],
                         person_first_alphabetical_order)
コード例 #11
0
    def test_two_attribution_function_to_same_learning_unit(self):
        new_attrib = AttributionNewFactory(learning_container_year=self.l_container, tutor=self.tutor_1,
                                           function=function.COORDINATOR)
        _create_attribution_charge(self.academic_year, new_attrib, "LBIR1210", Decimal(0), Decimal(0))
        attrib_list = attribution_json._compute_list()
        self.assertIsInstance(attrib_list, list)
        self.assertEqual(len(attrib_list), 2)

        attrib_tutor_1 = next(
                 (attrib for attrib in attrib_list if attrib['global_id'] == self.tutor_1.person.global_id),
                  None
        )
        self.assertEqual(len(attrib_tutor_1['attributions']), 3)
コード例 #12
0
def build_attributions_for_2_teachers_on_a_learning_unit(an_acronym, yr):
    attributionLCHM1111 = {'year': yr, 'acronym': an_acronym}

    AttributionNewFactory(global_id="123456789",
                          attributions=[
                              attributionLCHM1111, {
                                  'year': YEAR_2016,
                                  'acronym': 'LDVLP2627'
                              }, {
                                  'year': yr,
                                  'acronym': 'LDVLP2627'
                              }, {
                                  'year': yr,
                                  'acronym': 'LDROI1110'
                              }
                          ])
    AttributionNewFactory(global_id="987654321",
                          attributions=[
                              attributionLCHM1111, {
                                  'year': YEAR_2016,
                                  'acronym': 'LAGRO1256'
                              }
                          ])
コード例 #13
0
    def test_delete_all_learning_units_year_case_error_have_attributionnew_with_charge(
            self):
        learning_unit_years = self.learning_unit_year_list
        ly1 = learning_unit_years[1]
        attrib_new_1 = AttributionNewFactory(
            learning_container_year=ly1.learning_container_year)
        learning_component_year_1 = LearningComponentYearFactory(
            learning_unit_year=ly1)
        AttributionChargeNewFactory(
            attribution=attrib_new_1,
            learning_component_year=learning_component_year_1)

        request_factory = RequestFactory()

        request = request_factory.post(
            reverse(delete_all_learning_units_year, args=[ly1.id]))
        request.user = self.user

        setattr(request, 'session', 'session')
        setattr(request, '_messages', FallbackStorage(request))

        response = delete_all_learning_units_year(request, ly1.id)

        # Get message from context
        msg = [m.message for m in get_messages(request)]
        msg_level = [m.level for m in get_messages(request)]
        self.assertEqual(len(msg), 1)
        self.assertIn(messages.ERROR, msg_level)

        # Check error message
        subtype = _('The partim') if ly1.is_partim() else _(
            'The learning unit')
        self.assertIn(
            _("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s"
              ) % {
                  'subtype': subtype,
                  'acronym': ly1.acronym,
                  'tutor': attrib_new_1.tutor,
                  'year': ly1.academic_year
              }, msg)

        # Check that record is not deleted
        self.assertTrue(LearningUnitYear.objects.filter(pk=ly1.pk).exists())

        # Check redirection to identification
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.url,
            reverse('learning_unit', kwargs={'learning_unit_year_id': ly1.pk}))
コード例 #14
0
    def setUpTestData(cls):
        tutor = TutorFactory(person=PersonFactory())
        cls.attribution = AttributionNewFactory(
            tutor=tutor,
            substitute=PersonFactory()
        )
        cls.luy = LearningUnitYearFactory()
        cls.attribution_charge = AttributionChargeNewFactory(
            attribution=cls.attribution,
            learning_component_year__learning_unit_year=cls.luy
        )

        cls.person = PersonFactory()
        url_kwargs = {
            'acronym': cls.luy.acronym,
            'year': cls.luy.academic_year.year
        }
        cls.url = reverse('learning_unit_api_v1:learningunitattributions_read', kwargs=url_kwargs)
コード例 #15
0
    def test_get_results_coordinator_without_volume(self):
        AttributionNew.objects.all().delete()
        attribution_without_volume = AttributionNewFactory(
            learning_container_year=self.luy.learning_container_year,
            function=Functions.COORDINATOR.name,
        )
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        attribution_annotated = AttributionNew.objects.annotate(
            first_name=F('tutor__person__first_name'),
            middle_name=F('tutor__person__middle_name'),
            last_name=F('tutor__person__last_name'),
            email=F('tutor__person__email'),
            global_id=F('tutor__person__global_id'),
        ).get(id=attribution_without_volume.pk)

        serializer = LearningUnitAttributionSerializer([attribution_annotated], many=True)
        self.assertEqual(response.data, serializer.data)
コード例 #16
0
    def setUp(self):
        self.country = CountryFactory()
        self.academic_yr = AcademicYearFactory(year=timezone.now().year)
        self.start_date = self.academic_yr.start_date
        self.end_date = self.academic_yr.end_date

        self.list_learning_unit_container_year = self._create_list_containers(4)
        self.list_learning_unit_year = self._create_list_learning_units_from_containers(
            self.list_learning_unit_container_year)
        self.list_entity_version = self._create_list_entities_version()
        self._add_entities_to_containers(
            self.list_entity_version,
            self.list_learning_unit_container_year
        )
        self.tutor = TutorFactory()
        self.attribution = AttributionNewFactory(tutor=self.tutor)
        self.learning_component = LearningComponentYearFactory(learning_unit_year=self.list_learning_unit_year[0])
        self.attribution_charge_new = \
            AttributionChargeNewFactory(attribution=self.attribution,
                                        learning_component_year=self.learning_component)
コード例 #17
0
    def test_check_related_partims_deletion(self):
        l_container_year = LearningContainerYearFactory()
        LearningUnitYearFactory(
            acronym="LBIR1212",
            learning_container_year=l_container_year,
            academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL,
            learning_unit=self.learning_unit)
        msg = deletion._check_related_partims_deletion(l_container_year)
        self.assertEqual(len(msg.values()), 0)

        l_unit_2 = LearningUnitYearFactory(acronym="LBIR1213", learning_container_year=l_container_year,
                                           academic_year=self.academic_year, subtype=learning_unit_year_subtypes.PARTIM)

        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)

        group_1 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2)
        group_2 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2)

        component = LearningComponentYearFactory(learning_unit_year=l_unit_2)

        attribution_1 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year)
        attribution_2 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year)

        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_2)

        msg = deletion._check_related_partims_deletion(l_container_year)
        msg = list(msg.values())

        self.assertEqual(len(msg), 5)
        self.assertIn(_("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s")
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'year': l_unit_2.academic_year,
                         'count': 3},
                      msg)

        msg_delete_tutor = _("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s")
        self.assertIn(msg_delete_tutor % {'subtype': _('The partim'),
                                          'acronym': l_unit_2.acronym,
                                          'year': l_unit_2.academic_year,
                                          'tutor': attribution_1.tutor},
                      msg)
        self.assertIn(msg_delete_tutor % {'subtype': _('The partim'),
                                          'acronym': l_unit_2.acronym,
                                          'year': l_unit_2.academic_year,
                                          'tutor': attribution_2.tutor},
                      msg)

        msg_delete_offer_type = _('%(subtype)s %(acronym)s is included in the group %(group)s for the year %(year)s')

        self.assertIn(msg_delete_offer_type
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'group': group_1.parent.partial_acronym,
                         'year': l_unit_2.academic_year},
                      msg)
        self.assertIn(msg_delete_offer_type
                      % {'subtype': _('The partim'),
                         'acronym': l_unit_2.acronym,
                         'group': group_2.parent.partial_acronym,
                         'year': l_unit_2.academic_year},
                      msg)
コード例 #18
0
class TutorApplicationTest(TestCase):
    def setUp(self):
        # Create academic year
        self.academic_year = AcademicYearFactory(year=2017)
        # Create several learning container year - 2017
        self.lbir1200_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1200")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1200_2017)
        self.lbir1250_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1250")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1250_2017)
        self.lbir1300_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1300")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lbir1300_2017)
        self.lagro1200_2017 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LAGRO1200")
        LearningUnitYearFactory(academic_year=self.academic_year, learning_container_year=self.lagro1200_2017)

        # Create several learning container year - 2016
        self.academic_year_2016 = AcademicYearFactory(year=2016)
        self.lbir1200_2016 = LearningContainerYearFactory(academic_year=self.academic_year_2016, acronym="LBIR1200")
        LearningUnitYearFactory(academic_year=self.academic_year_2016, learning_container_year=self.lbir1200_2016)
        self.lbir1250_2016 = LearningContainerYearFactory(academic_year=self.academic_year_2016, acronym="LBIR1250")
        LearningUnitYearFactory(academic_year=self.academic_year_2016, learning_container_year=self.lbir1250_2016)

        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        person = PersonFactory(global_id="98363454")
        self.tutor = TutorFactory(person=person)

        applications = [
            _get_application_example(self.lbir1200_2017, '3.5', '35.6'),  # Application 2017
            _get_application_example(self.lbir1300_2017, '7.5', '25'),   # Application 2017
            _get_application_example(self.lbir1200_2016, '2', '30'),  # Application 2016
        ]
        self.attribution = AttributionNewFactory(global_id=person.global_id,
                                                 attributions=_get_attributions_default(),
                                                 applications=applications)

    def test_get_application_list(self):
        global_id = self.tutor.person.global_id
        application_list = tutor_application.get_application_list(global_id, self.academic_year)
        self.assertIsInstance(application_list, list)
        self.assertEqual(len(application_list), 2)

        application_list_in_2016 = tutor_application.get_application_list(global_id, self.academic_year_2016)
        self.assertIsInstance(application_list_in_2016, list)
        self.assertEqual(len(application_list_in_2016), 1)

    def test_get_application_list_order_by(self):
        self.attribution.applications = [
            _get_application_example(self.lbir1200_2017, '3.5', '35.6'),  # Application 2017
            _get_application_example(self.lbir1250_2017, '5', '7', tutor_application_epc.UPDATE_OPERATION),
            _get_application_example(self.lbir1300_2017, '7.5', '25')  # Application 2017
        ]
        self.attribution.save()
        global_id = self.tutor.person.global_id
        application_list = tutor_application.get_application_list(global_id, self.academic_year)
        self.assertIsInstance(application_list, list)
        self.assertEqual(len(application_list), 3)
        # Check order
        self.assertEqual(application_list[0]['acronym'], self.lbir1200_2017.acronym)
        self.assertEqual(application_list[1]['acronym'], self.lbir1300_2017.acronym)
        self.assertEqual(application_list[2]['acronym'], self.lbir1250_2017.acronym)

    def test_get_application(self):
        global_id = self.tutor.person.global_id
        application_searched = tutor_application.get_application(global_id, self.lbir1200_2017)
        self.assertTrue(application_searched)
        self.assertIsInstance(application_searched, dict)
        self.assertEqual(application_searched['acronym'], self.lbir1200_2017.acronym)

    def test_get_application_not_found(self):
        global_id = self.tutor.person.global_id
        application_searched = tutor_application.get_application(global_id, self.lagro1200_2017)
        self.assertFalse(application_searched)

    def test_create_or_update_application_creation_on_existing_user(self):
        application_to_create = _get_application_example(self.lbir1250_2017, '30', '20')
        global_id = self.tutor.person.global_id
        tutor_application.create_or_update_application(global_id, application_to_create)
        application_list = tutor_application.get_application_list(global_id, self.academic_year)
        self.assertEqual(len(application_list), 3) # We should have 3 applications now
        # We should found the newest created
        self.assertTrue(next(app for app in application_list if
                             app.get('acronym') == self.lbir1250_2017.acronym))

    def test_create_or_update_application_creation_on_new_user(self):
        # Create new tutor
        new_tutor = TutorFactory(person=PersonFactory(global_id="59898988"))
        # Submit tutor application
        application_to_create = _get_application_example(self.lbir1250_2017, '30', '20')
        global_id = new_tutor.person.global_id
        tutor_application.create_or_update_application(global_id, application_to_create)
        application_list = tutor_application.get_application_list(global_id, self.academic_year)
        self.assertEqual(len(application_list), 1)  # We should have 1 application

    def test_create_or_update_application_update(self):
        application_to_update = _get_application_example(self.lbir1200_2017, '0', '10')
        global_id = self.tutor.person.global_id
        tutor_application.create_or_update_application(global_id, application_to_update)
        application_list = tutor_application.get_application_list(global_id, self.academic_year)
        self.assertEqual(len(application_list), 2)  # We should have 2 applications
        application_updated = next(app for app in application_list if
                             app.get('acronym') == self.lbir1200_2017.acronym)
        self.assertTrue(application_updated)
        self.assertEqual(application_updated.get('acronym'), self.lbir1200_2017.acronym)
        self.assertEqual(application_updated.get('charge_lecturing_asked'), Decimal(0))
        self.assertEqual(application_updated.get('charge_practical_asked'), Decimal(10))

    def test_get_application_list_with_none_lecturing_charge(self):
        new_tutor = TutorFactory(person=PersonFactory(global_id="59898988"))
        application_to_create = _get_application_example(self.lbir1200_2017, None, "15")
        global_id = new_tutor.person.global_id
        tutor_application.create_or_update_application(global_id, application_to_create)
        application_list = tutor_application.get_application_list(global_id, self.academic_year)

        application_created = application_list[0]
        self.assertTrue(application_created)
        self.assertEqual(application_created.get('acronym'), self.lbir1200_2017.acronym)
        self.assertEqual(application_created.get('charge_lecturing_asked'), Decimal(0))
        self.assertEqual(application_created.get('charge_practical_asked'), Decimal(15))

    def test_get_application_list_with_none_practical_charge(self):
        new_tutor = TutorFactory(person=PersonFactory(global_id="59898988"))
        application_to_create = _get_application_example(self.lbir1200_2017, "15", None)
        global_id = new_tutor.person.global_id
        tutor_application.create_or_update_application(global_id, application_to_create)
        application_list = tutor_application.get_application_list(global_id, self.academic_year)

        application_created = application_list[0]
        self.assertTrue(application_created)
        self.assertEqual(application_created.get('acronym'), self.lbir1200_2017.acronym)
        self.assertEqual(application_created.get('charge_lecturing_asked'), Decimal(15))
        self.assertEqual(application_created.get('charge_practical_asked'), Decimal(0))

    def test_pending_flag(self):
        global_id = self.tutor.person.global_id
        application_searched = tutor_application.get_application(global_id, self.lbir1200_2017)
        self.assertTrue(application_searched)
        tutor_application.set_pending_flag(global_id, application_searched, tutor_application_epc.UPDATE_OPERATION)
        # Research in order to verify that have pending state
        application_searched = tutor_application.get_application(global_id, self.lbir1200_2017)
        self.assertEqual(application_searched['pending'], tutor_application_epc.UPDATE_OPERATION)
        self.assertTrue(application_searched['updated_at'])

    def test_validate_application(self):
        global_id = self.tutor.person.global_id
        application_to_create = _get_application_example(self.lbir1250_2017, '30', '20')
        application_to_create['pending'] = tutor_application_epc.UPDATE_OPERATION
        tutor_application.create_or_update_application(global_id, application_to_create)
        # Check pending state
        application_searched_not_validated = tutor_application.get_application(global_id, self.lbir1250_2017)
        self.assertEqual(application_searched_not_validated['pending'], tutor_application_epc.UPDATE_OPERATION)
        self.assertTrue(application_searched_not_validated['updated_at'])
        sleep(1) # Wait 1 sec for testing updated_at field
        # Validate
        tutor_application.validate_application(global_id, self.lbir1250_2017.acronym,
                                               self.lbir1250_2017.academic_year.year)
        application_searched_validated = tutor_application.get_application(global_id, self.lbir1250_2017)
        self.assertRaises(KeyError, lambda: application_searched_validated['pending'])
        self.assertTrue(application_searched_validated['updated_at'])
        self.assertTrue(application_searched_validated['updated_at'] >
                        application_searched_not_validated['updated_at'])

    def test_delete_application(self):
        global_id = self.tutor.person.global_id
        # Before delete
        application_searched = tutor_application.get_application(global_id, self.lbir1200_2017)
        self.assertTrue(application_searched)
        # Delete process
        acronym_to_delete = self.lbir1200_2017.acronym
        year_to_delete = self.lbir1200_2017.academic_year.year
        tutor_application.delete_application(global_id, acronym_to_delete, year_to_delete)
        # After delete
        application_searched = tutor_application.get_application(global_id, self.lbir1200_2017)
        self.assertFalse(application_searched)
コード例 #19
0
class AttributionTest(TestCase):
    def setUp(self):
        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        self.person = PersonFactory(global_id="98363454")
        TutorFactory(person=self.person)

        _create_multiple_academic_year()
        self.current_academic_year = create_current_academic_year()

        # Creation Json which will be store on attribution
        attributions = _get_attributions_dict(self.current_academic_year.year)
        self.attrib = AttributionNewFactory(global_id=self.person.global_id,
                                            attributions=attributions)

    def test_get_attribution_list(self):
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list), 3)

        previous_year = self.current_academic_year.year - 1
        academic_year_2016 = AcademicYear.objects.get(year=previous_year)
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, academic_year_2016)
        self.assertEqual(len(attribution_list), 1)

        attribution_list = attribution.get_attribution_list(
            self.person.global_id)
        self.assertEqual(len(attribution_list), 3)

    def test_get_attribution_list_empty(self):
        academic_year = AcademicYearFactory(year=1990)
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, academic_year)
        self.assertFalse(attribution_list)

    def test_get_attribution_order(self):
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list), 3)
        self.assertEqual(attribution_list[0]['acronym'], "LAGRO1530")
        self.assertEqual(attribution_list[1]['acronym'], "LBIR1200")
        self.assertEqual(attribution_list[2]['acronym'], "LBIR1300")

    def test_computes_volumes_total(self):
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, self.current_academic_year)
        volumes_total = attribution.get_volumes_total(attribution_list)
        self.assertTrue(volumes_total)
        self.assertEqual(
            volumes_total.get(learning_component_year_type.LECTURING),
            Decimal(53.5))
        self.assertEqual(
            volumes_total.get(
                learning_component_year_type.PRACTICAL_EXERCISES),
            Decimal(21.5))

    def test_append_team_and_volume_delcared_vacant(self):
        #  Create Container Year and component
        _create_learning_container_with_components(
            acronym="LBIR1300",
            academic_year=self.current_academic_year,
            volume_lecturing=Decimal(15.5),
            volume_practical_exercices=Decimal(5))
        _create_learning_container_with_components(
            acronym="LBIR1200",
            academic_year=self.current_academic_year,
            volume_lecturing=Decimal(30),
            volume_practical_exercices=Decimal(75))
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))

        attribution_list = attribution.get_attribution_list(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(attribution_list[0]['acronym'], "LAGRO1530")
        self.assertEqual(attribution_list[0]['volume_lecturing_vacant'],
                         Decimal(30))
        self.assertEqual(
            attribution_list[0]['volume_practical_exercices_vacant'],
            Decimal(30))
        self.assertEqual(attribution_list[0]['team'], False)
        self.assertEqual(attribution_list[1]['acronym'], "LBIR1200")
        self.assertEqual(attribution_list[1]['volume_lecturing_vacant'],
                         Decimal(30))
        self.assertEqual(
            attribution_list[1]['volume_practical_exercices_vacant'],
            Decimal(75))
        self.assertEqual(attribution_list[1]['team'], False)
        self.assertEqual(attribution_list[2]['acronym'], "LBIR1300")
        self.assertEqual(attribution_list[2]['volume_lecturing_vacant'],
                         Decimal(15.5))
        self.assertEqual(
            attribution_list[2]['volume_practical_exercices_vacant'],
            Decimal(5))
        self.assertEqual(attribution_list[2]['team'], False)

    def test_append_start_end_academic_year(self):
        attribution_list = attribution.get_attribution_list(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(attribution_list[0]['acronym'], "LAGRO1530")
        self.assertTrue(attribution_list[0]['start_academic_year'])
        self.assertEqual(attribution_list[0]['start_academic_year'].year, 2015)
        self.assertEqual(attribution_list[0]['end_academic_year'].year,
                         self.current_academic_year.year)

        self.assertEqual(attribution_list[1]['acronym'], "LBIR1200")
        self.assertTrue(attribution_list[1]['start_academic_year'])
        self.assertEqual(attribution_list[1]['start_academic_year'].year, 2013)
        self.assertRaises(
            KeyError,
            lambda: attribution_list[1]['end_academic_year'])  # No end year

        self.assertEqual(attribution_list[2]['acronym'], "LBIR1300")
        self.assertTrue(attribution_list[2]['start_academic_year'])
        self.assertEqual(attribution_list[2]['start_academic_year'].year, 2015)
        self.assertEqual(attribution_list[2]['end_academic_year'].year,
                         self.current_academic_year.year + 1)

    def test_get_attribution_list_about_to_expire(self):
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(30), Decimal(30))
        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertTrue(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertIsNone(
            attribution_list_about_to_expired[0]['not_renewable_reason'])

    def test_get_attribution_list_about_to_expire_volume_pratical_lower(self):
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(1), Decimal(30))
        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertFalse(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertEqual(
            attribution_list_about_to_expired[0]['not_renewable_reason'],
            _("The vacant volume of the next academic year is lower than the current one"
              ))

    def test_get_attribution_list_about_to_expire_volume_lecturing__lower(
            self):
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(30), Decimal(1))
        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertFalse(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertEqual(
            attribution_list_about_to_expired[0]['not_renewable_reason'],
            _("The vacant volume of the next academic year is lower than the current one"
              ))

    def test_get_attribution_list_about_to_expire_volume_zero_is_renewable(
            self):
        self.attrib.attributions = [{
            'year': self.current_academic_year.year,
            'acronym': 'LAGRO1530',
            'title': 'Agrochimie élémentaire',
            'weight': '5.00',
            'LECTURING': '0',
            'PRACTICAL_EXERCISES': '0',
            'function': 'HOLDER',
            'start_year': 2015,
            'end_year': self.current_academic_year.year,
            'is_substitute': False
        }]
        self.attrib.save()
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(30), Decimal(30))
        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertTrue(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertEqual(
            attribution_list_about_to_expired[0]['not_renewable_reason'], None)

    def test_get_attribution_list_with_substitute_is_not_renewable(self):
        self.attrib.attributions = [{
            'year': self.current_academic_year.year,
            'acronym': 'LAGRO1530',
            'title': 'Agrochimie élémentaire',
            'weight': '5.00',
            'LECTURING': '0',
            'PRACTICAL_EXERCISES': '0',
            'function': 'HOLDER',
            'start_year': 2015,
            'end_year': self.current_academic_year.year,
            'is_substitute': True
        }]
        self.attrib.save()
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(30), Decimal(30))
        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)
        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertFalse(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertEqual(
            attribution_list_about_to_expired[0]['not_renewable_reason'],
            _('A substitute can not renew his function of substitute'))

    def test_get_attribution_list_about_to_expire_already_applied(self):
        _create_learning_container_with_components("LAGRO1530",
                                                   self.current_academic_year,
                                                   Decimal(30), Decimal(30))
        next_academic_year = AcademicYear.objects.get(
            year=self.current_academic_year.year + 1)
        _create_learning_container_with_components("LAGRO1530",
                                                   next_academic_year,
                                                   Decimal(30), Decimal(30))
        application = [{
            'remark': 'This is the remarks',
            'course_summary': 'This is the course summary',
            'charge_lecturing_asked': 30,
            'charge_practical_asked': 30,
            'acronym': "LAGRO1530",
            'year': next_academic_year.year,
            'is_substitute': False
        }]
        self.attrib.applications = application
        self.attrib.save()

        attribution_list_about_to_expired = attribution.get_attribution_list_about_to_expire(
            self.person.global_id, self.current_academic_year)

        self.assertEqual(len(attribution_list_about_to_expired), 1)
        self.assertFalse(attribution_list_about_to_expired[0]['is_renewable'])
        self.assertEqual(
            attribution_list_about_to_expired[0]['not_renewable_reason'],
            _('An application has already been submitted'))

    def test_calculate_effective_volume(self):
        vol_tot = 10.0
        planned_classes = 2
        data = {'PLANNED_CLASSES': planned_classes, 'VOLUME_TOTAL': vol_tot}
        self.assertEqual(attribution._calculate_effective_volume(data),
                         vol_tot * planned_classes)

    def test_calculate_effective_volume_incorrect(self):
        vol_tot = 10.0
        planned_classes = -1
        data = {'PLANNED_CLASSES': planned_classes, 'VOLUME_TOTAL': vol_tot}
        self.assertEqual(attribution._calculate_effective_volume(data),
                         attribution.NO_CHARGE)

    def test_calculate_effective_volume_no_volume_provided(self):
        self.assertEqual(
            attribution._calculate_effective_volume({'PLANNED_CLASSES': 1}),
            attribution.NO_CHARGE)

    def test_calculate_effective_volume_case_negative_volume(self):
        vol_tot = -10.0
        planned_classes = 1
        data = {'PLANNED_CLASSES': planned_classes, 'VOLUME_TOTAL': vol_tot}
        self.assertEqual(attribution._calculate_effective_volume(data),
                         attribution.NO_CHARGE)

    def test_get_teachers_parameter_none(self):
        self.assertIsNone(attribution.get_teachers(None, None))
        self.assertIsNone(attribution.get_teachers('LCHM1111', None))
        academic_year = AcademicYearFactory()
        self.assertIsNone(attribution.get_teachers(None, academic_year))

    def test_get_teachers_no_teacher_found(self):
        self.assertIsNone(attribution.get_teachers('LCHM1111', 2017))

    def test_get_2_teachers_in_order(self):
        acronym_LCHM1111 = 'LCHM1111'
        acronym_LDVLP2627 = 'LDVLP2627'
        acronym_LDROI1110 = 'LDROI1110'

        # Create first teacher with one attribution on LCHM1111 and others
        person_first_alphabetical_order = PersonFactory(global_id='12345678',
                                                        last_name='Antonelli')
        attribution_teacher_1_LCHM1111 = {
            'year': 2017,
            'acronym': acronym_LCHM1111
        }
        attributions_teacher1 = [
            attribution_teacher_1_LCHM1111, {
                'year': 2016,
                'acronym': acronym_LDVLP2627
            }, {
                'year': 2017,
                'acronym': acronym_LDVLP2627
            }, {
                'year': 2017,
                'acronym': acronym_LDROI1110
            }
        ]

        AttributionNewFactory(
            global_id=person_first_alphabetical_order.global_id,
            attributions=attributions_teacher1)
        # Create second teacher with one attribution on LCHM1111
        person_second_alphabetical_order = PersonFactory(global_id='987654321',
                                                         last_name='Barnet')
        attribution_teacher_2_LCHM1111 = {
            'year': 2017,
            'acronym': acronym_LCHM1111
        }
        attributions_teacher2 = [attribution_teacher_2_LCHM1111]
        AttributionNewFactory(
            global_id=person_second_alphabetical_order.global_id,
            attributions=attributions_teacher2)
        #
        attributions_result = attribution.get_teachers(acronym_LCHM1111, 2017)
        self.assertEqual(len(attributions_result), 2)
        self.assertEqual(attributions_result[0][attribution.PERSON_KEY],
                         person_first_alphabetical_order)

    def test_update_learning_unit_volume_no_components(self):
        """When no components found on database, the key 'lecturing_vol' / 'practical_exercises_vol' is set to 0.0"""
        l_container = LearningContainerYearFactory(
            acronym='LAGRO1530', academic_year=self.current_academic_year)
        LearningUnitYearFactory(acronym='LAGRO1530',
                                academic_year=self.current_academic_year,
                                learning_container_year=l_container)
        an_attribution = {
            'year': 2017,
            'acronym': 'LAGRO1530',
            'title': 'Chimie complexe',
            'weight': '5.00',
            'LECTURING': '22.5',
            'PRACTICAL_EXERCISES': '5.0',
            'function': 'HOLDER',
            'start_year': 2015,
            'end_year': 2020
        }

        attribution.update_learning_unit_volume(an_attribution,
                                                self.current_academic_year)
        self.assertEqual(an_attribution['lecturing_vol'], Decimal(0.0))
        self.assertEqual(an_attribution['practical_exercises_vol'],
                         Decimal(0.0))

    def test_calculate_component_volume(self):
        an_attribution = {
            'year': 2017,
            'acronym': 'LAGRO1530',
            'title': 'Chimie complexe',
            'weight': '5.00',
            'LECTURING': '22.5',
            'PRACTICAL_EXERCISES': '5.0',
            'function': 'HOLDER',
            'start_year': 2015,
            'end_year': 2020
        }
        l_component_lecturing = LearningComponentYearFactory(
            type=learning_component_year_type.LECTURING)
        l_component_other = LearningComponentYearFactory(type=None)
        components_computed = {
            l_component_lecturing: {
                'VOLUME_TOTAL': Decimal(15),
                'PLANNED_CLASSES': 5
            },
            l_component_other: {
                'VOLUME_TOTAL': Decimal(1),
                'PLANNED_CLASSES': 1
            }
        }
        attribution._calculate_component_volume(an_attribution,
                                                components_computed)
        self.assertEqual(an_attribution['lecturing_vol'],
                         Decimal(75))  # VOLUME_TOTAL * PLANNED_CLASSES
        self.assertRaises(KeyError,
                          lambda: an_attribution['practical_exercises_vol'])

    def test_get_attribution_vacant_none(self):
        learning_container_yr = LearningContainerYearFactory()
        self.assertIsNone(
            attribution.get_attribution_vacant(learning_container_yr))

    def test_format_no_volume(self):
        attributions_without_volume = [{'year': 2018, 'acronym': 'LBIR1200'}]
        attributions_formalized = attribution._format_str_volume_to_decimal(
            attributions_without_volume)
        self.assertEqual(attributions_formalized[0]['LECTURING'], 0.0)
        self.assertEqual(attributions_formalized[0]['PRACTICAL_EXERCISES'],
                         0.0)
コード例 #20
0
class TestTutorApplicationEpc(TestCase):
    def setUp(self):
        self.academic_year = AcademicYearFactory(year=2017)
        external_id = tutor_application_epc.LEARNING_CONTAINER_YEAR_PREFIX_EXTERNAL_ID + '35654987_2017'
        self.lbir1200 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1200",
                                                     external_id=external_id)
        self.lagro2630 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LAGRO2630")

        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        person = PersonFactory(global_id="98363454")
        external_id = tutor_application_epc.TUTOR_PREFIX_EXTERNAL_ID + '2089590559'
        self.tutor = TutorFactory(external_id=external_id, person=person)

        # Create two tutor applications
        applications = [_get_application_example(self.lbir1200, '30.5', '40.5'),
                        _get_application_example(self.lagro2630, '12.5', '0')]
        self.attribution = AttributionNewFactory(
            global_id=person.global_id,
            applications=applications
        )

    def test_extract_learning_container_year_epc_info(self):
        learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1200', 2017)
        self.assertIsInstance(learning_container_info, dict)
        self.assertEqual(learning_container_info['reference'], '35654987')
        self.assertEqual(learning_container_info['year'], 2017)

    def test_extract_learning_container_year_epc_info_empty(self):
        learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1250', 2017)
        self.assertIsInstance(learning_container_info, dict)
        self.assertFalse(learning_container_info)

    def test_extract_learning_container_year_epc_info_with_external_id_empty(self):
        self.lbir1200.external_id = None
        self.lbir1200.save()
        learning_container_info = tutor_application_epc._extract_learning_container_year_epc_info('LBIR1200', 2017)
        self.assertIsInstance(learning_container_info, dict)
        self.assertFalse(learning_container_info)

    def test_convert_to_epc_application(self):
        person = self.tutor.person
        application = _get_application_example(self.lbir1200, '30.5', '40.5')

        epc_message = tutor_application_epc._convert_to_epc_application(application=application)

        self.assertTrue(epc_message)
        self.assertEqual(epc_message['remark'], application['remark'])
        self.assertEqual(epc_message['course_summary'], application['course_summary'])
        self.assertEqual(epc_message['lecturing_allocation'], application['charge_lecturing_asked'])
        self.assertEqual(epc_message['practical_allocation'], application['charge_practical_asked'])
        self.assertIsInstance(epc_message['learning_container_year'], dict)
        self.assertEqual(epc_message['learning_container_year']['reference'], '35654987')
        self.assertEqual(epc_message['learning_container_year']['year'], 2017)

    def test_process_message_delete_operation(self):
        person = self.tutor.person
        self.assertEqual(len(self.attribution.applications), 2)
        body = {
            'operation': tutor_application_epc.DELETE_OPERATION,
            'global_id': person.global_id,
            'learning_container_year': {
                'acronym': 'LBIR1200',
                'year': 2017
            }
        }
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_epc.process_message(body_encoded)
        # Check if the application is removed
        self.attribution.refresh_from_db()
        self.assertEqual(len(self.attribution.applications), 1)
        attribution_left = self.attribution.applications[0]
        self.assertEqual(attribution_left['acronym'], self.lagro2630.acronym)

    def test_process_message_update_operation(self):
        person = self.tutor.person
        _set_all_application_in_pending_state(self.attribution.applications)
        self.attribution.save()
        ## Check if all are in pending
        self.assertEqual(len(self.attribution.applications), 2)
        self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION)
        self.assertEqual(self.attribution.applications[1]['pending'], tutor_application_epc.UPDATE_OPERATION)

        body = {
            'operation': tutor_application_epc.UPDATE_OPERATION,
            'global_id': person.global_id,
            'learning_container_year': {
                'acronym': 'LBIR1200',
                'year': 2017
            }
        }
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_epc.process_message(body_encoded)
        # Check if the application is removed
        self.attribution.refresh_from_db()
        applications_not_pending = [application for application in self.attribution.applications if
                                    not "pending" in application]
        self.assertEqual(len(applications_not_pending), 1)


    def test_process_message_with_error_operation(self):
        person = self.tutor.person
        _set_all_application_in_pending_state(self.attribution.applications)
        self.attribution.save()
        ## Check if all are in pending
        self.assertEqual(len(self.attribution.applications), 2)
        self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION)
        self.assertEqual(self.attribution.applications[1]['pending'], tutor_application_epc.UPDATE_OPERATION)

        body = {
            'operation': tutor_application_epc.UPDATE_OPERATION,
            'global_id': person.global_id,
            'learning_container_year': {
                'acronym': 'LBIR1200',
                'year': 2017
            },
            tutor_application_epc.ERROR_EPC_FIELD: 'An error occured in EPC'
        }
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_epc.process_message(body_encoded)
        # Check if the application is removed
        self.attribution.refresh_from_db()
        applications_not_pending = [application for application in self.attribution.applications if
                                    not "pending" in application]
        self.assertEqual(len(applications_not_pending), 0) # No changed
コード例 #21
0
class TestTutorApplicationEpc(TestCase):
    def setUp(self):
        self.academic_year = AcademicYearFactory(year=2017)
        external_id = tutor_application_osis.LEARNING_CONTAINER_YEAR_PREFIX_EXTERNAL_ID + '35654987_2017'
        self.lbir1200 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LBIR1200",
                                                     external_id=external_id)
        self.lagro2630 = LearningContainerYearFactory(academic_year=self.academic_year, acronym="LAGRO2630")
        self.bio = LearningContainerYearFactory(academic_year=self.academic_year, acronym="BIO5213")

        # Creation Person/Tutor
        Group.objects.create(name="tutors")
        person = PersonFactory(global_id="98363454")
        external_id = tutor_application_osis.TUTOR_PREFIX_EXTERNAL_ID + '2089590559'
        self.tutor = TutorFactory(external_id=external_id, person=person)

        # Create two tutor applications
        applications = [_get_application_example(self.lbir1200, '30.5', '40.5'),
                        _get_application_example(self.lagro2630, '12.5', '10.5'),
                        _get_application_example(self.bio, '10.5', '9.5')]
        self.attribution_new = AttributionNewFactory(
            global_id=person.global_id,
            applications=applications
        )

    def test_process_message_update_operation(self):
        person = self.tutor.person
        _set_all_application_in_pending_state(self.attribution_new.applications)
        self.attribution_new.save()
        self.assertEqual(len(self.attribution_new.applications), 3)
        self.assertEqual(self.attribution_new.applications[0]['pending'], tutor_application_osis.UPDATE_OPERATION)
        self.assertEqual(self.attribution_new.applications[1]['pending'], tutor_application_osis.UPDATE_OPERATION)

        body = [{
            'global_id': person.global_id,
            'tutor_applications': [{
                'acronym': 'LBIR1200',
                'year': self.academic_year.year,
                'charge_lecturing_asked': '0',
                'charge_practical_asked': '0',
                'last_changed': "2020-12-08 09:58:57+00:00"
            }]
        }]
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_osis.process_message(body_encoded)
        self.attribution_new.refresh_from_db()
        self.assertEqual(self.attribution_new.applications[0]['charge_lecturing_asked'], '0')

    def test_process_message_no_update_operation(self):
        person = self.tutor.person
        _set_all_application_in_pending_state(self.attribution_new.applications)
        self.attribution_new.save()
        self.assertEqual(len(self.attribution_new.applications), 3)
        self.assertEqual(self.attribution_new.applications[0]['pending'], tutor_application_osis.UPDATE_OPERATION)
        self.assertEqual(self.attribution_new.applications[1]['pending'], tutor_application_osis.UPDATE_OPERATION)

        body = [{
            'global_id': person.global_id,
            'tutor_applications': [{
                'acronym': 'LAGRO2630',
                'year': self.academic_year.year,
                'charge_lecturing_asked': '0',
                'charge_practical_asked': '0',
                'last_changed': "2013-12-08 09:58:57+00:00"
            }]
        }]
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_osis.process_message(body_encoded)
        self.attribution_new.refresh_from_db()
        self.assertEqual(self.attribution_new.applications[0]['charge_lecturing_asked'], '12.5')

    def test_process_message_with_delete_pending(self):
        person = self.tutor.person
        _set_all_application_in_pending_delete(self.attribution_new.applications)
        self.attribution_new.save()
        self.assertEqual(len(self.attribution_new.applications), 3)

        body = [{
            'global_id': person.global_id,
            'tutor_applications': [{
                'acronym': 'LAGRO2630',
                'year': self.academic_year.year,
                'charge_lecturing_asked': '0',
                'charge_practical_asked': '0',
                'last_changed': "2016-12-08 09:58:57+00:00"
            }]
        }]
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_osis.process_message(body_encoded)
        self.attribution_new.refresh_from_db()
        self.assertEqual(len(self.attribution_new.applications), 1)
        self.assertEqual(self.attribution_new.applications[0]['charge_lecturing_asked'], '12.5')

    def test_process_when_attribution_new_not_exist(self):
        body = [{
            'global_id': "321654",
            'tutor_applications': [{
                'acronym': 'LAGRO2630',
                'year': self.academic_year.year,
                'charge_lecturing_asked': '0',
                'charge_practical_asked': '0',
                'last_changed': "2016-12-08 09:58:57+00:00"
            }]
        }]
        self.assertEqual(find_by_global_id("321654"), None)
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_osis.process_message(body_encoded)
        self.assertEqual(find_by_global_id("321654").global_id, "321654")

    def test_process_with_many_change(self):
        person = self.tutor.person
        self.assertEqual(len(self.attribution_new.applications), 3)
        self.attribution_new.applications[0]['pending'] = tutor_application_osis.UPDATE_OPERATION
        self.attribution_new.applications[1]['pending'] = tutor_application_osis.DELETE_OPERATION
        self.attribution_new.save()
        self.attribution_new.refresh_from_db()
        body = [{
            'global_id': person.global_id,
            'tutor_applications': [
                {'acronym': 'LAGRO2630',
                 'year': self.academic_year.year,
                 'charge_lecturing_asked': '0',
                 'charge_practical_asked': '0',
                 'last_changed': "2021-12-08 09:58:57+00:00"
                 },
                {'acronym': 'LBIR1200',
                 'year': self.academic_year.year,
                 'charge_lecturing_asked': '0',
                 'charge_practical_asked': '0',
                 'last_changed': "2013-12-08 09:58:57+00:00"
                 },
                {'acronym': 'BIO5213',
                 'year': self.academic_year.year,
                 'charge_lecturing_asked': '0',
                 'charge_practical_asked': '0',
                 'last_changed': "2013-12-08 09:58:57+00:00"}
            ]
        }]
        body_encoded = bytearray(json.dumps(body), "utf-8")
        tutor_application_osis.process_message(body_encoded)
        self.attribution_new.refresh_from_db()
        self.assertEqual(len(self.attribution_new.applications), 3)
        self.assertEqual(self.attribution_new.applications[0]['charge_lecturing_asked'], '12.5')
        self.assertEqual(self.attribution_new.applications[1]['charge_lecturing_asked'], '30.5')
        self.assertEqual(self.attribution_new.applications[2]['charge_lecturing_asked'], '0')
コード例 #22
0
class TestOnlineApplication(TestCase):
    def setUp(self):
        # Create Group tutor
        Group.objects.create(name="tutors")

        # Create user
        user = UserFactory(username="******")
        person = PersonFactory(global_id="578945612", user=user)
        self.tutor = TutorFactory(person=person)

        # Add permission and log into app
        add_permission(user, "can_access_attribution_application")
        self.client.force_login(user)

        # Create current academic year
        self.current_academic_year = create_current_academic_year()

        # Create application year
        # Application is always next year
        self.application_academic_year = AcademicYearFactory(

            year=self.current_academic_year.year + 1
        )

        # Create Event to allow teacher to register
        start_date = datetime.datetime.today() - datetime.timedelta(days=10)
        end_date = datetime.datetime.today() + datetime.timedelta(days=15)
        self.academic_calendar = AcademicCalendarFactory(
            academic_year=self.current_academic_year,
            reference=academic_calendar_type.TEACHING_CHARGE_APPLICATION,
            start_date=start_date,
            end_date=end_date
        )
        self.agro_entity = EntityFactory()
        self.agro_entity_version = EntityVersionFactory(entity=self.agro_entity, acronym="AGRO",
                                                        entity_type='FACULTY',
                                                        start_date=self.academic_calendar.start_date,
                                                        end_date=self.academic_calendar.end_date)

        self.drt_entity = EntityFactory()
        self.drt_entity_version = EntityVersionFactory(entity=self.drt_entity, acronym="DRT",
                                                       entity_type='FACULTY',
                                                       start_date=self.academic_calendar.start_date,
                                                       end_date=self.academic_calendar.end_date)

        # Creation context with multiple learning container year
        self._create_multiple_learning_container_year()
        self.attribution = AttributionNewFactory(
            global_id=person.global_id,
            applications=self._get_default_application_list(),
            attributions=self._get_default_attribution_list()
        )

    def test_redirection_to_outside_encoding_period(self):
        # Remove teaching charge application event
        self.academic_calendar.delete()
        url = reverse('applications_overview')
        url_outside = reverse('outside_applications_period')
        response = self.client.get(url)
        self.assertRedirects(response, "%s?next=%s" % (url_outside, url))  # Redirection

    def test_message_outside_encoding_period(self):
        # Remove teaching charge application event
        self.academic_calendar.delete()
        url = reverse('outside_applications_period')
        response = self.client.get(url)
        messages = list(response.context['messages'])
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].tags, 'warning')
        self.assertEqual(messages[0].message, _('The period of online application is closed'))

    def test_applications_overview(self):
        url = reverse('applications_overview')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[-1]
        self.assertEqual(context['a_tutor'], self.tutor)
        self.assertEqual(context['current_academic_year'], self.current_academic_year)
        self.assertEqual(context['application_year'], self.application_academic_year)
        self.assertEqual(len(context['attributions']), 1)
        self.assertEqual(context['attributions'][0]['acronym'], self.lagro2500_next.acronym)
        self.assertEqual(len(context['applications']), 1)
        self.assertEqual(context['applications'][0]['acronym'], self.lagro1600_next.acronym)
        self.assertEqual(len(context['attributions_about_to_expire']), 1)
        self.assertEqual(context['attributions_about_to_expire'][0]['acronym'], self.lbir1300_current.acronym)

    def test_applications_overview_post_method_not_allowed(self):
        url = reverse('applications_overview')
        response = self.client.post(url)
        self.assertEqual(response.status_code, 405)

    def test_search_vacant_attribution_initial(self):
        url = reverse('vacant_attributions_search')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertEqual(context['a_tutor'], self.tutor)
        self.assertTrue(context['search_form'])
        self.assertIsNone(context['attributions_vacant'])

    def test_search_vacant_attribution_post_not_allowed(self):
        url = reverse('vacant_attributions_search')
        response = self.client.post(url)
        self.assertEqual(response.status_code, 405)

    def test_search_vacant_attribution_search_list(self):
        url = reverse('vacant_attributions_search')
        response = self.client.get(url, data={'learning_container_acronym': 'LAGRO'})
        self.assertEqual(response.status_code, 200)
        context = response.context[-1]
        self.assertEqual(context['a_tutor'], self.tutor)
        self.assertTrue(context['search_form'])
        self.assertEqual(len(context['attributions_vacant']), 2)
        # Check if LAGRO1600 have the boolean already applied
        self.assertTrue((next(attrib for attrib in context['attributions_vacant']
                              if attrib.get('acronym') == self.lagro1600_next.acronym and
                              attrib.get('already_applied')), False))

    def test_search_vacant_attribution_search_list_by_faculty(self):
        url = reverse('vacant_attributions_search')
        response = self.client.get(
            url, data={
                'learning_container_acronym': 'LAGRO',
                'faculty': self.agro_entity_version.id
            }
        )
        self.assertEqual(response.status_code, 200)
        context = response.context[-1]
        self.assertEqual(len(context['attributions_vacant']), 2)

    def test_search_vacant_attribution_with_declaration_vac_not_allowed(self):
        # Create container with type_declaration_vacant not in [RESEVED_FOR_INTERNS, OPEN_FOR_EXTERNS]
        self.lagro1234_current = _create_learning_container_with_components("LAGRO1234", self.current_academic_year)
        # Creation learning container for next academic year [==> application academic year]
        self.lagro1234_next = _create_learning_container_with_components\
            ("LAGRO1234", self.application_academic_year, 70, 70,
             type_declaration_vacant=vacant_declaration_type.DO_NOT_ASSIGN)
        url = reverse('vacant_attributions_search')
        response = self.client.get(url, data={'learning_container_acronym': 'LAGRO1234'})
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertEqual(context['a_tutor'], self.tutor)
        self.assertTrue(context['search_form'])
        self.assertFalse(context['attributions_vacant'])

    def test_renew_applications(self):
        url = reverse('renew_applications')
        post_data = {'learning_container_year_' + self.lbir1300_next.acronym: 'on'}
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)  # redirection
        self.attribution.refresh_from_db()
        self.assertEqual(len(self.attribution.applications), 2)  # Now we have two applications

    def test_renew_applications_with_bad_learning_container(self):
        url = reverse('renew_applications')
        post_data = {'learning_container_year_' + self.lagro2500_next.acronym: 'on'}
        response = self.client.post(url, data=post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        messages = list(response.context['messages'])
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].tags, 'error')
        self.assertEqual(messages[0].message, _('No attribution renewed'))

    def test_renew_applications_method_not_allowed(self):
        url = reverse('renew_applications')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 405)

    def test_delete_application(self):
        url = reverse('delete_tutor_application', kwargs={'learning_container_year_id': self.lagro1600_next.id})
        response = self.client.post(url)
        self.assertEqual(response.status_code, 302)  # redirection
        self.attribution.refresh_from_db()
        # pending flag must be set to 'deleted'
        self.assertTrue((next(attrib for attrib in self.attribution.applications
                              if attrib.get('acronym') == self.lagro1600_next.acronym and
                              attrib.get('pending') == tutor_application_epc.DELETE_OPERATION), False))

    def test_delete_application_with_wrong_container(self):
        url = reverse('delete_tutor_application', kwargs={'learning_container_year_id': self.lbir1300_next.id})
        response = self.client.post(url)
        self.assertEqual(response.status_code, 404)  # Not found

    def test_delete_application_method_not_allowed(self):
        url = reverse('delete_tutor_application', kwargs={'learning_container_year_id': self.lagro1600_next.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 405)

    def test_get_edit_application_form(self):
        url = reverse('create_or_update_tutor_application',
                      kwargs={'learning_container_year_id': self.lagro1600_next.id})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertEqual(context['a_tutor'], self.tutor)
        self.assertEqual(context['learning_container_year'], self.lagro1600_next)
        self.assertTrue(context['form'])

    def test_post_edit_application_form(self):
        url = reverse('create_or_update_tutor_application',
                      kwargs={'learning_container_year_id': self.lagro1600_next.id})
        post_data = _get_application_example(self.lagro1600_next, '54', '7')
        response = self.client.post(url, data=post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.attribution.refresh_from_db()
        self.assertEqual(len(self.attribution.applications), 1)
        self.assertEqual(self.attribution.applications[0]['charge_lecturing_asked'], '54.0')
        self.assertEqual(self.attribution.applications[0]['charge_practical_asked'], '7.0')
        self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION)

    def test_post_edit_application_form_with_empty_value(self):
        url = reverse('create_or_update_tutor_application',
                      kwargs={'learning_container_year_id': self.lagro1600_next.id})
        post_data = _get_application_example(self.lagro1600_next, None, None)
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertTrue(context.get('form'))
        form = context['form']
        self.assertTrue(form.errors)  # Not valid because not number entered

    def test_post_edit_application_form_with_empty_lecturing_value(self):
        url = reverse('create_or_update_tutor_application',
                      kwargs={'learning_container_year_id': self.lagro1600_next.id})
        post_data = _get_application_example(self.lagro1600_next, "15", "")
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 302)
        self.attribution.refresh_from_db()
        self.assertEqual(len(self.attribution.applications), 1)
        self.assertEqual(self.attribution.applications[0]['charge_lecturing_asked'], '15.0')
        self.assertEqual(self.attribution.applications[0]['charge_practical_asked'], '0.0')
        self.assertEqual(self.attribution.applications[0]['pending'], tutor_application_epc.UPDATE_OPERATION)

    def test_post_edit_application_form_with_value_under_zero(self):
        url = reverse('create_or_update_tutor_application',
                      kwargs={'learning_container_year_id': self.lagro1600_next.id})
        post_data = _get_application_example(self.lagro1600_next, '-1', '5')
        response = self.client.post(url, data=post_data)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertTrue(context.get('form'))
        form = context['form']
        self.assertTrue(form.errors)  # Not valid because -1 entered

    def test_post_overview_with_lecturing_and_practical_component_partim(self):
        lbira2101a_next = _create_learning_container_with_components("LBIRA2101A", self.application_academic_year,
                                                                     volume_lecturing=20, volume_practical_exercices=20,
                                                                         subtype=learning_unit_year_subtypes.PARTIM)
        lbira2101a_current = _create_learning_container_with_components(
            "LBIRA2101A", self.current_academic_year,
            volume_lecturing=20, volume_practical_exercices=20,
            subtype=learning_unit_year_subtypes.PARTIM)
        _link_components_and_learning_unit_year_to_container(lbira2101a_current, "LBIRA2101",
                                                             subtype=learning_unit_year_subtypes.FULL)
        _link_components_and_learning_unit_year_to_container(lbira2101a_next, "LBIRA2101",
                                                             subtype=learning_unit_year_subtypes.FULL)
        self.attribution.delete()
        self.attribution = AttributionNewFactory(
            global_id=self.tutor.person.global_id,
            applications=[_get_application_example(lbira2101a_next, "10", "10")]
        )

        url = reverse('applications_overview')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        context = response.context[0]
        self.assertEqual(len(context['applications']), 1)
        self.assertEqual(context['applications'][0]['acronym'], lbira2101a_next.acronym)
        with self.assertRaises(KeyError):
            context['applications'][0]['PRACTICAL_EXERCISES']
        with self.assertRaises(KeyError):
            context['applications'][0]['LECTURING']

    def _create_multiple_learning_container_year(self):
        # Creation learning container for current academic year
        self.lbir1200_current = _create_learning_container_with_components("LBIR1200", self.current_academic_year)
        self.lbir1300_current = _create_learning_container_with_components("LBIR1300", self.current_academic_year)
        self.ldroi1500_current = _create_learning_container_with_components("LDROI1500", self.current_academic_year)

        # Creation learning container for next academic year [==> application academic year]
        self.lbir1200_next = _create_learning_container_with_components("LBIR1200", self.application_academic_year,
                                                                        70, 70)
        self.lbir1300_next = _create_learning_container_with_components("LBIR1300", self.application_academic_year,
                                                                        60, 60)
        self.lagro1600_next = _create_learning_container_with_components("LAGRO1600", self.application_academic_year,
                                                                         54, 7)
        self.lagro2500_next = _create_learning_container_with_components("LAGRO2500", self.application_academic_year,
                                                                         0, 70)
        self._create_entity_container_yrs()

    def _get_default_application_list(self):
        return [
            _get_application_example(self.lagro1600_next, '15', '0')
        ]

    def _get_default_attribution_list(self):
        return [
            # Attribution in current year
            _get_attribution_example(self.lbir1200_current, '20.0', '31.5', 2015, 2019),
            _get_attribution_example(self.lbir1300_current, '21.5', '40', 2015, self.current_academic_year.year),
            # Attribution in next year
            _get_attribution_example(self.lagro2500_next, '29', '10', 2015, 2020)
        ]

    def _create_entity_container_yrs(self):
        self.lbir1200_current.allocation_entity = self.agro_entity
        self.lbir1200_current.save()
        self.lbir1300_current.allocation_entity = self.agro_entity
        self.lbir1300_current.save()
        self.lbir1200_next.allocation_entity = self.agro_entity
        self.lbir1200_next.save()
        self.lbir1300_next.allocation_entity = self.agro_entity
        self.lbir1300_next.save()
        self.lagro1600_next.allocation_entity = self.agro_entity
        self.lagro1600_next.save()
        self.lagro2500_next.allocation_entity = self.agro_entity
        self.lagro2500_next.save()
        self.ldroi1500_current.allocation_entity = self.drt_entity
        self.ldroi1500_current.save()
コード例 #23
0
 def test_find_no_attribution(self):
     AttributionNewFactory(global_id="123456789", attributions=[])
     results = mdl_attribution.attribution_new.find_teachers(
         LCHM1111, YEAR_2017)
     self.assertEqual(len(results), 0)