Beispiel #1
0
    def test_string_ref(self):
        modname = testdata.get_module_name()
        d = testdata.create_modules(
            {
                "foo": [
                    "import prom", "class Foo(prom.Orm):",
                    "    interface = None",
                    "    bar_id = prom.Field('{}.bar.Bar')".format(modname), ""
                ],
                "bar": [
                    "import prom", "class Bar(prom.Orm):",
                    "    interface = None",
                    "    foo_id = prom.Field('{}.foo.Foo')".format(modname), ""
                ],
            }, modname)

        Foo = d.module("{}.foo".format(modname)).Foo
        Bar = d.module("{}.bar".format(modname)).Bar

        self.assertTrue(isinstance(Foo.schema.fields['bar_id'].schema, Schema))
        self.assertTrue(
            issubclass(Foo.schema.fields['bar_id'].interface_type, long))
        self.assertTrue(isinstance(Bar.schema.fields['foo_id'].schema, Schema))
        self.assertTrue(
            issubclass(Bar.schema.fields['foo_id'].interface_type, long))
Beispiel #2
0
    def __init__(self, controller_prefix="", contents=""):
        if not controller_prefix:
            controller_prefix = testdata.get_module_name()

        super(Server, self).__init__(controller_prefixes=[controller_prefix])

        if isinstance(contents, dict):
            d = {}
            for k, v in contents.items():
                if k:
                    d[".".join([controller_prefix, k])] = v
                else:
                    d[controller_prefix] = v
            self.controllers = testdata.create_modules(d)

        else:
            self.controller = testdata.create_module(controller_prefix,
                                                     contents=contents)
Beispiel #3
0
    def create_server(self, contents, config_contents='', **kwargs):
        tdm = testdata.create_module(kwargs.get("controller_prefix", ""),
                                     contents)

        kwargs["controller_prefix"] = tdm
        kwargs["host"] = self.get_host()
        kwargs["cwd"] = tdm.basedir

        if config_contents:
            config_path = testdata.create_file(
                "{}.py".format(testdata.get_module_name()), config_contents)
            kwargs["config_path"] = config_path

        server = self.server_class(**kwargs)
        server.stop()
        server.start()
        self.server = server
        return server