Esempio n. 1
0
def _update_or_delete_entity_container(entity_version, learning_container_year,
                                       type_entity):
    if not entity_version:
        _delete_entity(learning_container_year, type_entity)
    else:
        update_or_create_entity_container_year_with_components(
            entity_version.entity, learning_container_year, type_entity)
Esempio n. 2
0
def _reinitialize_entities_before_proposal(learning_container_year,
                                           initial_entities_by_type):
    for type_entity, id_entity in initial_entities_by_type.items():
        initial_entity = entity.get_by_internal_id(id_entity)
        if initial_entity:
            update_or_create_entity_container_year_with_components(
                initial_entity, learning_container_year, type_entity)
        else:
            current_entity_container_year = entity_container_year.find_by_learning_container_year_and_linktype(
                learning_container_year, type_entity)
            if current_entity_container_year is not None:
                current_entity_container_year.delete()
Esempio n. 3
0
    def test_update_or_create_entity_container_year_with_components_type_requirement(self):
        """In this test, we ensure that when we create an entity_container type requirement,
           we have an entity_component created"""
        an_entity = EntityFactory()
        a_learning_container_year = LearningContainerYearFactory(academic_year=self.academic_year)
        LearningComponentYearFactory(acronym="CM", learning_container_year=a_learning_container_year)
        LearningComponentYearFactory(acronym="TP", learning_container_year=a_learning_container_year)
        link_type = random.choice(ENTITY_TYPES_VOLUME)

        update_or_create_entity_container_year_with_components(an_entity, a_learning_container_year, link_type)
        self.assertEqual(EntityContainerYear.objects.all().count(), 1)
        self.assertEqual(EntityComponentYear.objects.all().count(), 2)
Esempio n. 4
0
    def test_update_or_create_entity_container_year_with_components_type_allocation(self):
        """In this test, we ensure that when we create an entity_container type allocation,
           we have NO entity_component created"""
        an_entity = EntityFactory()
        a_learning_container_year = LearningContainerYearFactory(academic_year=self.academic_year)
        LearningComponentYearFactory(acronym="CM", learning_container_year=a_learning_container_year)
        LearningComponentYearFactory(acronym="TP", learning_container_year=a_learning_container_year)
        link_type = entity_container_year_link_type.ALLOCATION_ENTITY

        update_or_create_entity_container_year_with_components(an_entity, a_learning_container_year, link_type)
        self.assertEqual(EntityContainerYear.objects.all().count(), 1)
        self.assertEqual(EntityComponentYear.objects.all().count(), 0)
Esempio n. 5
0
    def test_update_or_create_entity_container_year_with_components_type_requirement(self):
        """In this test, we ensure that when we create an entity_container type requirement,
           we have an entity_component created"""
        an_entity = EntityFactory()
        a_learning_container_year = LearningContainerYearFactory(academic_year=self.academic_year)
        LearningComponentYearFactory(acronym="PM", learning_container_year=a_learning_container_year)
        LearningComponentYearFactory(acronym="PP", learning_container_year=a_learning_container_year)
        link_type = random.choice(REQUIREMENT_ENTITIES)

        business_edition.update_or_create_entity_container_year_with_components(
            an_entity, a_learning_container_year, link_type
        )
        self.assertEqual(EntityContainerYear.objects.filter(
            learning_container_year=a_learning_container_year).count(), 1)
        self.assertEqual(EntityComponentYear.objects.filter(
            entity_container_year__learning_container_year=a_learning_container_year
        ).count(), 2)