示例#1
0
    def test___init__(self):
        class Mom(relations.Model):
            id = int
            name = str

        class Son(relations.Model):
            id = int
            mom_id = int
            name = str

        relation = relations.OneToMany(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, "mom_id")
示例#2
0
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 TestRestful(relations_restful.unittest.TestCase):
    def setUp(self):

        self.source = relations.unittest.MockSource("TestRestfulResource")
示例#3
0
    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
示例#4
0
class SourceModel(relations.Model):
    SOURCE = "TestRestfulSource"


class Simple(SourceModel):
    id = int
    name = str


class Plain(SourceModel):
    ID = None
    simple_id = int
    name = str


relations.OneToMany(Simple, Plain)


class Meta(SourceModel):
    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):
示例#5
0
class TitlesModel(relations.Model):
    SOURCE = "TestTitles"


class Unit(TitlesModel):
    id = int
    name = str, {"format": "fancy"}


class Test(TitlesModel):
    id = int
    unit_id = int
    name = str, {"format": "shmancy"}


relations.OneToMany(Unit, Test)


class Meta(TitlesModel):
    id = int
    name = str
    flag = bool
    stuff = list
    things = dict

    TITLES = "things__a__b__0____1"
    UNIQUE = False


def subnet_attr(values, value):
示例#6
0
class UnitTest(ModelTest):
    id = int
    name = relations.Field(str, default="unittest")
    nope = False
    deffer = unit

class Unit(ModelTest):
    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)
    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