def test_integration_object_all_of_ref(): """ GIVEN schema with allOf that references another object schema and schemas WHEN column_factory is called with the schema and schemas THEN foreign key reference and relationship is returned. """ spec = {"allOf": [{"$ref": "#/components/schemas/RefSchema"}]} schemas = { "RefSchema": { "type": "object", "x-tablename": "table 1", "properties": { "id": { "type": "integer" } }, } } [ # pylint: disable=unbalanced-tuple-unpacking (fk_logical_name, fk_column), (tbl_logical_name, relationship), ] = column_factory.column_factory(spec=spec, schemas=schemas, logical_name="column_1") assert fk_logical_name == "column_1_id" assert isinstance(fk_column.type, sqlalchemy.Integer) assert len(fk_column.foreign_keys) == 1 assert tbl_logical_name == "column_1" assert relationship.argument == "RefSchema" assert relationship.backref is None
def test_integration_all_of(): """ GIVEN schema with allOf statement WHEN column_factory is called with the schema and schemas THEN SQLAlchemy boolean column is returned in a dictionary with logical name. """ spec = {"allOf": [{"type": "boolean"}]} schemas = {} [(logical_name, column) ] = column_factory.column_factory(spec=spec, schemas=schemas, logical_name="column_1") assert logical_name == "column_1" assert isinstance(column.type, sqlalchemy.Boolean)
def test_integration_ref(): """ GIVEN schema that references another schema and schemas WHEN column_factory is called with the schema and schemas THEN SQLAlchemy boolean column is returned in a dictionary with logical name. """ spec = {"$ref": "#/components/schemas/RefSchema"} schemas = {"RefSchema": {"type": "boolean"}} [(logical_name, column) ] = column_factory.column_factory(spec=spec, schemas=schemas, logical_name="column_1") assert logical_name == "column_1" assert isinstance(column.type, sqlalchemy.Boolean)