class RelationSourceRelation(Relation): name = Column(primary=True) val_1 = Column() rel = Column(related_name='rel_source') records = ( ('STATE_1', 'value_1', 1), # just any type without .set_related_name ('STATE_2', 'value_2', RelationDestinationRelation.STATE_2))
class RelationSourceRelation(Relation): name = Column(primary=True) val_1 = Column() rel = Column(related_name='rel_source') # "name" duplicate primary attribute of RelationDestinationRelation records = (('name', 'value_1', RelationDestinationRelation.STATE_1), ('STATE_2', 'value_2', RelationDestinationRelation.STATE_2))
class IndexesRelation(Relation): name = Column(primary=True, no_index=False, primary_checks=True) val_1 = Column(no_index=False) val_2 = Column(unique=False, no_index=False) val_3 = Column(index_name='val_3_index', no_index=False) records = ( ('rec_1', 'val_1_1', 'val_2_1', 'val_3_1'), ('rec_2', 'val_1_2', 'val_2_2', 'val_3_2'), ('rec_3', 'val_1_3', 'val_2_2', 'val_3_3'), ('rec_4', 'val_1_4', 'val_2_4', 'val_3_4'), )
def test_check_single_type_restriction_success(self): column_1 = Column() column_1.initialize('column_1') records = (Record([column_1], ['str_1']), Record([column_1], ['str_2'])) column_1.check_single_type_restriction(records)
def test_check_single_type_restriction_exception(self): column_1 = Column() column_1.initialize('column_1') records = (Record([column_1], [1]), Record([column_1], ['str_2'])) self.assertRaises(exceptions.SingleTypeError, column_1.check_single_type_restriction, records)
def test_check_uniqueness_restriction_success(self): column_1 = Column() column_1.initialize('column_1') records = (Record([column_1], ['uuid_1']), Record([column_1], ['uuid_2'])) column_1.check_uniqueness_restriction(records)
def test_check_uniqueness_restriction_exception(self): column_1 = Column() column_1.initialize('column_1') records = (Record([column_1], ['uuid_1']), Record([column_1], ['uuid_1'])) self.assertRaises(exceptions.DuplicateValueError, column_1.check_uniqueness_restriction, records)
def test_get_index_not_unique(self): column_1 = Column(unique=False) column_1.initialize('column_1') records = (Record([column_1], ['str_1']), Record([column_1], ['str_2'])) self.assertEqual(column_1.get_index(records), { 'str_1': (records[0], ), 'str_2': (records[1], ) })
class BaseRelation(Relation): name = Column(primary=True, no_index=False) value = Column(no_index=False) records = (('id_0', 0), )
class EnumWith2Primaries(Relation): name = Column(primary=True, no_index=False, primary_checks=True) value = Column(primary=True, no_index=False, primary_checks=True) records = (('STATE_1', 'value_1'), ('STATE_2', 'value_2'))
class BaseRelation(Relation): name = Column(primary=True, no_index=False) value = Column(no_index=False)
class BaseRelation(Relation): name = Column(primary=True) value = Column()
def test_external_without_unique(self): column = Column(external=True, unique=False) self.assertRaises(exceptions.ExternalWithoutUniqueError, column.initialize, name='column')
def test_custom_index_name(self): column = Column(index_name='my_index') column.initialize(name='test') self.assertEqual(column.index_name, 'my_index')
def test_primary_without_unique(self): column = Column(primary=True, unique=False) self.assertRaises(exceptions.PrimaryWithoutUniqueError, column.initialize, name='column')
class EmptyRecordsRelation(Relation): name = Column(no_index=False) value = Column(no_index=False)
class RelationDestinationRelation(Relation): name = Column(primary=True, no_index=False, primary_checks=True) val_1 = Column(no_index=False) records = (('STATE_1', 'value_1'), ('STATE_2', 'value_2'))
class SimplestRelation(Relation): name = Column(primary=True, unique=False) value = Column() records = (('name_a', 1), ('name_b', 1))
class SimplestRelation(Relation): name = Column() value = Column(unique=True) records = (('name_a', 1), ('name_b', 1))
def test_columns_values(self): columns = (Column(name='col_1'), Column(name='col_2')) data = (1, 2) r = Record(columns=columns, data=data) self.assertEqual(r.col_1, 1) self.assertEqual(r.col_2, 2)
class ChildRelation(BaseRelation): value = Column(unique=False, no_index=False) records = (('id_1', 1), ('id_2', 2))
class SimplestEnum(Relation): name = Column(primary=True, no_index=False, primary_checks=True) value = Column(external=True, no_index=False) records = (('state_1', 'val_1'), ('state_2', 'val_2'))
class SimplestRelation(Relation): name = Column(external=True) value = Column(external=True) records = (('name_a', 'name_c'), ('name_b', 'name_d'))
class EnumWithText(Relation): name = Column(primary=True, no_index=False, primary_checks=True) value = Column(external=True, no_index=False) text = Column(no_index=False)
def test_default_index_name(self): column = Column() column.initialize(name='test') self.assertEqual(column.index_name, 'index_test')
class SimplestRelation(Relation): name = Column(no_index=False) value = Column(no_index=False) records = (('name_a', 1), ('name_b', 2))
class Enum(Relation): name = Column(primary=True, no_index=True, primary_checks=True) value = Column(external=True, no_index=True)
class SimplestRelation(Relation): name = Column(primary=True) value = Column(primary=True) records = (('name_a', 'name_c'), ('name_b', 'name_a'))