def test_build_raw_external_reference(self):
        # given:
        external_raw_spec = {
            # 'value_type': 'string',
            'identifiable': True,
            'external_reference': True
        }

        # and:
        non_external_raw_spec = copy.deepcopy(external_raw_spec)
        non_external_raw_spec['external_reference'] = False

        # when:
        external_spec = ColumnSpecification.build_raw('profile.uuid',
                                                      'profile',
                                                      'personal_info',
                                                      external_raw_spec)
        non_external_spec = ColumnSpecification.build_raw(
            'user.id', 'user', 'personal_info', non_external_raw_spec)

        # then:
        self.assertEqual('profile.uuid', external_spec.field_name)
        self.assertEqual('profile', external_spec.object_type)
        self.assertEqual('personal_info', external_spec.main_category)
        # self.assertEqual(DataType.STRING, external_spec.data_type)
        self.assertTrue(external_spec.is_external_reference())

        # then:
        self.assertEqual('user.id', non_external_spec.field_name)
        self.assertFalse(non_external_spec.is_external_reference())
    def test_build_raw_spec_with_parent_spec(self):
        # given:
        raw_spec = {'value_type': 'boolean', 'multivalue': True}

        # and:
        raw_single_value_parent_spec = {'multivalue': False}

        # and:
        raw_multi_value_parent_spec = {'multivalue': True}

        # when:
        single_column_spec = ColumnSpecification.build_raw(
            '', '', '', raw_spec, parent=raw_single_value_parent_spec)
        multi_column_spec = ColumnSpecification.build_raw(
            '', '', '', raw_spec, parent=raw_multi_value_parent_spec)

        # then:
        self.assertFalse(single_column_spec.is_field_of_list_element())
        self.assertTrue(multi_column_spec.is_field_of_list_element())
    def test_build_raw_multivalue(self):
        # given:
        raw_int_array_spec = {'value_type': 'integer', 'multivalue': True}

        # when:
        int_array_column_spec = ColumnSpecification.build_raw(
            'sample.numbers', 'user', 'profile_entry', raw_int_array_spec)

        # then:
        self.assertEqual('sample.numbers', int_array_column_spec.field_name)
        self.assertEqual('profile_entry', int_array_column_spec.main_category)
        self.assertEqual(DataType.INTEGER, int_array_column_spec.data_type)
        self.assertTrue(int_array_column_spec.is_multivalue())
        self.assertFalse(int_array_column_spec.is_identity())
Ejemplo n.º 4
0
 def _define_column_spec(self, header, object_type, order_of_occurence=1):
     if header is not None:
         parent_path, __ = utils.split_field_chain(header)
         raw_spec = self.lookup(header)
         raw_parent_spec = self.lookup(parent_path)
         concrete_type = utils.extract_root_field(header)
         main_category = self.get_domain_entity(concrete_type)
         column_spec = ColumnSpecification.build_raw(
             header,
             object_type,
             main_category,
             raw_spec,
             parent=raw_parent_spec,
             order_of_occurence=order_of_occurence)
     else:
         column_spec = None
     return column_spec
    def test_build_raw_single_type(self):
        # given:
        raw_string_spec = {
            'value_type': 'string',
            'multivalue': False,
            'identifiable': True
        }

        # when:
        string_column_spec = ColumnSpecification.build_raw(
            'user.name', 'user', 'profile_entry', raw_string_spec)

        # then:
        self.assertEqual('user.name', string_column_spec.field_name)
        self.assertEqual('profile_entry', string_column_spec.main_category)
        self.assertEqual(DataType.STRING, string_column_spec.data_type)
        self.assertFalse(string_column_spec.is_multivalue())
        self.assertTrue(string_column_spec.is_identity())