def test___init__(self): class Mom(relations.Model): id = int name = str class Son(relations.Model): id = int name = str relation = relations.OneToOne(Mom, Son) self.assertEqual(relation.Parent, Mom) self.assertEqual(relation.Child, Son) self.assertEqual(relation.parent_child, "son") self.assertEqual(relation.child_parent, "mom") self.assertEqual(relation.parent_field, "id") self.assertEqual(relation.child_field, "id")
def setUp(self): class ResourceModel(relations.Model): SOURCE = "TestRestfulResource" class Simple(ResourceModel): id = int name = str class Plain(ResourceModel): ID = None simple_id = int name = str relations.OneToMany(Simple, Plain) class SimpleResource(relations_restful.Resource): MODEL = Simple class PlainResource(relations_restful.Resource): MODEL = Plain class Meta(ResourceModel): id = int name = str flag = bool spend = float people = set stuff = list things = dict, {"extract": "for__0____1"} push = str, {"inject": "stuff___1__relations.io____1"} def subnet_attr(values, value): values["address"] = str(value) min_ip = value[0] max_ip = value[-1] values["min_address"] = str(min_ip) values["min_value"] = int(min_ip) values["max_address"] = str(max_ip) values["max_value"] = int(max_ip) class Net(ResourceModel): id = int ip = ipaddress.IPv4Address, { "attr": { "compressed": "address", "__int__": "value" }, "init": "address", "titles": "address", "extract": { "address": str, "value": int } } subnet = ipaddress.IPv4Network, { "attr": subnet_attr, "init": "address", "titles": "address" } TITLES = "ip__address" INDEX = "ip__value" class MetaResource(relations_restful.Resource): MODEL = Meta class NetResource(relations_restful.Resource): MODEL = Net class Unit(ResourceModel): id = int name = str class Test(ResourceModel): id = int unit_id = int name = str class Case(ResourceModel): id = int test_id = int name = str relations.OneToMany(Unit, Test) relations.OneToOne(Test, Case) class UnitResource(relations_restful.Resource): MODEL = Unit class TestResource(relations_restful.Resource): MODEL = Test class CaseResource(relations_restful.Resource): MODEL = Case self.resource = relations.unittest.MockSource("TestRestfulResource") self.app = flask.Flask("source-api") restful = flask_restful.Api(self.app) restful.add_resource(SimpleResource, '/simple', '/simple/<id>') restful.add_resource(PlainResource, '/plain') restful.add_resource(MetaResource, '/meta', '/meta/<id>') restful.add_resource(NetResource, '/net', '/net/<id>') restful.add_resource(UnitResource, '/unit', '/unit/<id>') restful.add_resource(TestResource, '/test', '/test/<id>') restful.add_resource(CaseResource, '/case', '/case/<id>') self.source = relations_restful.Source("TestRestfulSource", "", self.app.test_client()) def result(model, key, response): if key in response.json: return response.json[key] print(response.json) self.source.result = result
class Test(SourceModel): id = int unit_id = int name = str, {"format": "shmancy"} class Case(SourceModel): id = int test_id = int name = str relations.OneToMany(Unit, Test) relations.OneToOne(Test, Case) class TestSource(unittest.TestCase): maxDiff = None def setUp(self): class ResourceModel(relations.Model): SOURCE = "TestRestfulResource" class Simple(ResourceModel): id = int name = str class Plain(ResourceModel):
id = int name = str class Test(ModelTest): id = int unit_id = int name = str relations.OneToMany(Unit, Test) class Case(ModelTest): id = int test_id = int name = str relations.OneToOne(Test, Case) class Run(ModelTest): id = int test_id = int name = str status = ["pass", "fail"] relations.OneToOne(Test, Run) class Meta(ModelTest): id = int name = str flag = bool spend = float people = set
def setUp(self): class ResourceModel(relations.Model): SOURCE = "TestRestfulResource" class Simple(ResourceModel): id = int name = str class Plain(ResourceModel): ID = None simple_id = int name = str relations.OneToMany(Simple, Plain) class SimpleResource(relations_restful.Resource): MODEL = Simple class PlainResource(relations_restful.Resource): MODEL = Plain class Unit(ResourceModel): id = int name = str class Test(ResourceModel): id = int unit_id = int name = str class Case(ResourceModel): id = int test_id = int name = str relations.OneToMany(Unit, Test) relations.OneToOne(Test, Case) class UnitResource(relations_restful.Resource): MODEL = Unit class TestResource(relations_restful.Resource): MODEL = Test class CaseResource(relations_restful.Resource): MODEL = Case self.resource = relations.unittest.MockSource("TestRestfulResource") self.app = flask.Flask("source-api") restful = flask_restful.Api(self.app) restful.add_resource(SimpleResource, '/simple', '/simple/<id>') restful.add_resource(PlainResource, '/plain') restful.add_resource(UnitResource, '/unit', '/unit/<id>') restful.add_resource(TestResource, '/test', '/test/<id>') restful.add_resource(CaseResource, '/case', '/case/<id>') self.source = relations_restful.Source("TestRestfulSource", "", self.app.test_client()) def result(model, key, response): return response.json[key] self.source.result = result