class SimplestRelation(Relation): name = Column(primary=True, index_name='name_a', no_index=False) value = Column(no_index=False) records = (('name_a', 1), ('name_b', 2))
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)
class RelationSourceRelation(Relation): name = Column(primary=True, no_index=False, primary_checks=True) val_1 = Column(no_index=False) rel = Column(related_name='rel_source', no_index=False) records = (('STATE_1', 'value_1', RelationDestinationRelation.STATE_1), ('STATE_2', 'value_2', RelationDestinationRelation.STATE_2))
def test_equality(self): columns = (Column(name='col_1'), Column(name='col_2')) data = (1, 2) r_1 = Record(columns=columns, data=data) r_2 = Record(columns=columns, data=data) self.assertNotEqual(r_1, r_2) self.assertEqual(r_1, r_1)
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_wrong_data_length(self): columns = (Column(name='col_1'), Column(name='col_2')) data = (1, 2, 3) self.assertRaises(exceptions.ColumnsNumberError, Record, columns=columns, data=data)
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_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],)})
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_get_index__no_index(self): column_1 = Column(no_index=True) column_1.initialize('column_1') records = ( Record([column_1], ['str_1']), Record([column_1], ['str_2'])) self.assertEqual(column_1.get_index(records), None)
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], )})
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)
class SimplestRelation(Relation): name = Column(primary=True, no_index=False, primary_checks=True) is_name = Column(primary=True, no_index=False, primary_checks=True) records = (('name_a', 'name_c'), ('name_b', 'name'))
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 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))
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 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_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)
class SimplestRelation(Relation): name = Column(no_index=False) value = Column(no_index=False) records = (('name_a', 1), ('name_b', 2))
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() 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 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, unique=False) value = Column() records = (('name_a', 1), ('name_b', 1))
def test_default_index_name(self): column = Column() column.initialize(name='test') self.assertEqual(column.index_name, 'index_test')
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_custom_index_name(self): column = Column(index_name="my_index") column.initialize(name="test") self.assertEqual(column.index_name, "my_index")
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 ChildRelation(BaseRelation): value = Column(unique=False, no_index=False) records = (('id_1', 1), ('id_2', 2))
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 SimplestRelation(Relation): name = Column(external=True) value = Column(external=True) records = (('name_a', 'name_c'), ('name_b', 'name_d'))
class EmptyRecordsRelation(Relation): name = Column(no_index=False) value = Column(no_index=False)
class SimplestRelation(Relation): name = Column(primary=True) value = Column(primary=True) records = (('name_a', 'name_c'), ('name_b', 'name_a'))
def test_repr(self): column = Column(related_name='rel_name') column.initialize(name='col_name') column._creation_order += 1 # enshure, that creation order will be equal self.assertEqual(eval(repr(column)).__dict__, column.__dict__)
class BaseRelation(Relation): name = Column(primary=True) value = Column()
class BaseRelation(Relation): name = Column(primary=True, no_index=False) value = Column(no_index=False)