Exemplo n.º 1
0
    def __init__(self, ctx: 'CdmCorpusContext') -> None:
        super().__init__(ctx)

        # Property of a projection that holds the condition expression string
        self.condition = None  # type: str

        # Property of a projection that holds a collection of operations
        self.operations = CdmOperationCollection(ctx, self)  # type: CdmOperationCollection

        self.run_sequentially = None  # type: Optional[bool]

        # --- internal ---

        # Property of a projection that holds the source of the operation
        self._source = None  # type: Optional[CdmEntityReference]

        self._TAG = CdmProjection.__name__
Exemplo n.º 2
0
    def __init__(self, ctx: 'CdmCorpusContext') -> None:
        super().__init__(ctx)

        # Property of a projection that holds the condition expression string
        self.condition = None  # type: str

        # Property of a projection that holds a collection of operations
        self.operations = CdmOperationCollection(ctx, self)  # type: CdmOperationCollection

        # --- internal ---

        # Condition expression tree that is built out of a condition expression string
        self._condition_expression_tree_root = None  # type: Node

        # Property of a projection that holds the source of the operation
        self._source = None  # type: Optional[CdmEntityReference]

        self._TAG = CdmProjection.__name__
    def test_get_default_condition_expression(self):
        """Unit test for ConditionExpression._get_default_condition_expression"""
        corpus = TestHelper.get_local_corpus(
            self.tests_subpath, 'test_get_default_condition_expression')
        corpus.storage.mount(
            'local',
            LocalAdapter(
                TestHelper.get_actual_output_folder_path(
                    self.tests_subpath,
                    'test_get_default_condition_expression')))
        local_root = corpus.storage.fetch_root_folder('local')
        manifest_default = self._create_default_manifest(corpus, local_root)

        entity_test_source = self._create_entity_test_source(
            corpus, manifest_default, local_root)

        # projection for a non entity attribute
        op_coll = CdmOperationCollection(corpus.ctx, entity_test_source)

        # add 1st FK
        op_coll.append(CdmOperationReplaceAsForeignKey(corpus.ctx))
        self.assertEqual(
            ' (referenceOnly || noMaxDepth || (depth > maxDepth)) ',
            ConditionExpression._get_default_condition_expression(
                op_coll, entity_test_source))

        # add 2nd FK
        op_coll.append(CdmOperationReplaceAsForeignKey(corpus.ctx))
        self.assertEqual(
            ' (referenceOnly || noMaxDepth || (depth > maxDepth)) ',
            ConditionExpression._get_default_condition_expression(
                op_coll, entity_test_source))

        op_coll.clear()

        # add AddCount
        op_coll.append(CdmOperationAddCountAttribute(corpus.ctx))
        self.assertEqual(
            ' (!structured) ',
            ConditionExpression._get_default_condition_expression(
                op_coll, entity_test_source))

        # add ArrayExpansion
        op_coll.append(CdmOperationArrayExpansion(corpus.ctx))
        self.assertEqual(
            ' (!structured) ',
            ConditionExpression._get_default_condition_expression(
                op_coll, entity_test_source))

        op_coll.clear()

        # add AddSupporting
        op_coll.append(CdmOperationAddSupportingAttribute(corpus.ctx))
        self.assertEqual(
            ' (true) ',
            ConditionExpression._get_default_condition_expression(
                op_coll, entity_test_source))

        entity_test_entity_attribute = corpus.make_object(
            CdmObjectType.ENTITY_ATTRIBUTE_DEF, 'TestEntityAttribute', False)

        # projection for a non entity attribute
        op_coll_EA = CdmOperationCollection(corpus.ctx,
                                            entity_test_entity_attribute)

        # add 1st FK
        op_coll_EA.append(CdmOperationReplaceAsForeignKey(corpus.ctx))
        self.assertEqual(
            ' ( (!normalized) || (cardinality.maximum <= 1) )  &&  (referenceOnly || noMaxDepth || (depth > maxDepth)) ',
            ConditionExpression._get_default_condition_expression(
                op_coll_EA, entity_test_entity_attribute))

        # add 2nd FK
        op_coll_EA.append(CdmOperationReplaceAsForeignKey(corpus.ctx))
        self.assertEqual(
            ' ( (!normalized) || (cardinality.maximum <= 1) )  &&  (referenceOnly || noMaxDepth || (depth > maxDepth)) ',
            ConditionExpression._get_default_condition_expression(
                op_coll_EA, entity_test_entity_attribute))

        op_coll_EA.clear()

        # add AddCount
        op_coll_EA.append(CdmOperationAddCountAttribute(corpus.ctx))
        self.assertEqual(
            ' ( (!normalized) || (cardinality.maximum <= 1) )  &&  (!structured) ',
            ConditionExpression._get_default_condition_expression(
                op_coll_EA, entity_test_entity_attribute))

        # add ArrayExpansion
        op_coll_EA.append(CdmOperationArrayExpansion(corpus.ctx))
        self.assertEqual(
            ' ( (!normalized) || (cardinality.maximum <= 1) )  &&  (!structured) ',
            ConditionExpression._get_default_condition_expression(
                op_coll_EA, entity_test_entity_attribute))

        op_coll_EA.clear()

        # add AddSupporting
        op_coll_EA.append(CdmOperationAddSupportingAttribute(corpus.ctx))
        self.assertEqual(
            ' ( (!normalized) || (cardinality.maximum <= 1) )  &&  (true) ',
            ConditionExpression._get_default_condition_expression(
                op_coll_EA, entity_test_entity_attribute))