コード例 #1
0
    def test_server_config_04(self):
        storage = immutables.Map()

        op = ops.Operation(ops.OpCode.CONFIG_SET, config.ConfigScope.SESSION,
                           'int', 11)
        storage1 = op.apply(testspec1, storage)
        self.assertEqual(config.lookup('int', storage1, spec=testspec1), 11)

        op = ops.Operation(ops.OpCode.CONFIG_SET, config.ConfigScope.SESSION,
                           'int', '42')
        with self.assertRaisesRegex(errors.ConfigurationError,
                                    "invalid value type for the 'int'"):
            op.apply(testspec1, storage1)

        op = ops.Operation(ops.OpCode.CONFIG_SET, config.ConfigScope.SESSION,
                           'int', 42)
        storage2 = op.apply(testspec1, storage1)

        op = ops.Operation(ops.OpCode.CONFIG_SET, config.ConfigScope.SESSION,
                           'ints', {42})
        storage2 = op.apply(testspec1, storage2)

        op = ops.Operation(ops.OpCode.CONFIG_SET, config.ConfigScope.SESSION,
                           'ints', {42, 43})
        storage2 = op.apply(testspec1, storage2)

        self.assertEqual(config.lookup('int', storage1, spec=testspec1), 11)
        self.assertEqual(config.lookup('int', storage2, spec=testspec1), 42)
        self.assertEqual(config.lookup('ints', storage2, spec=testspec1),
                         {42, 43})
コード例 #2
0
    def test_server_config_02(self):
        storage = immutables.Map()

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(database='f1'))
        storage1 = op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(database='f2'))
        storage2 = op.apply(testspec1, storage1)

        self.assertEqual(
            config.lookup('ports', storage2, spec=testspec1), {
                Port.from_pyvalue(make_port_value(database='f1')),
                Port.from_pyvalue(make_port_value(database='f2')),
            })

        j = ops.to_json(testspec1, storage2)
        storage3 = ops.from_json(testspec1, j)
        self.assertEqual(storage3, storage2)

        op = ops.Operation(ops.OpCode.CONFIG_REM, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(database='f1'))
        storage3 = op.apply(testspec1, storage2)

        self.assertEqual(config.lookup('ports', storage3, spec=testspec1), {
            Port.from_pyvalue(make_port_value(database='f2')),
        })

        op = ops.Operation(ops.OpCode.CONFIG_REM, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(database='f1'))
        storage4 = op.apply(testspec1, storage3)
        self.assertEqual(storage3, storage4)
コード例 #3
0
ファイル: test_server_config.py プロジェクト: syyunn/edgedb
    def test_server_config_02(self):
        storage = immutables.Map()

        op = ops.Operation(ops.OpCode.CONFIG_ADD, ops.OpLevel.SYSTEM, 'ports',
                           make_port_value(database='f1'))
        storage1 = op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, ops.OpLevel.SYSTEM, 'ports',
                           make_port_value(database='f2'))
        storage2 = op.apply(testspec1, storage1)

        self.assertEqual(
            storage2['ports'], {
                Port.from_pyvalue(make_port_value(database='f1')),
                Port.from_pyvalue(make_port_value(database='f2')),
            })

        j = ops.to_json(testspec1, storage2)
        storage3 = ops.from_json(testspec1, j)
        self.assertEqual(storage3, storage2)

        op = ops.Operation(ops.OpCode.CONFIG_REM, ops.OpLevel.SYSTEM, 'ports',
                           make_port_value(database='f1'))
        storage3 = op.apply(testspec1, storage2)

        self.assertEqual(storage3['ports'], {
            Port.from_pyvalue(make_port_value(database='f2')),
        })

        op = ops.Operation(ops.OpCode.CONFIG_REM, ops.OpLevel.SYSTEM, 'ports',
                           make_port_value(database='f1'))
        storage4 = op.apply(testspec1, storage3)
        self.assertEqual(storage3, storage4)
コード例 #4
0
    def test_server_config_03(self):
        storage = immutables.Map()

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(zzzzzzz='zzzzz'))
        with self.assertRaisesRegex(errors.ConfigurationError,
                                    "unknown fields: 'zzz"):
            op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(concurrency='a'))
        with self.assertRaisesRegex(errors.ConfigurationError,
                                    "invalid 'concurrency'.*expecting int"):
            op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'por', make_port_value(concurrency='a'))
        with self.assertRaisesRegex(errors.ConfigurationError,
                                    "unknown setting"):
            op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(address=["aaa", 123]))
        with self.assertRaisesRegex(errors.ConfigurationError,
                                    "str or a list"):
            op.apply(testspec1, storage)

        op = ops.Operation(ops.OpCode.CONFIG_ADD, config.ConfigScope.INSTANCE,
                           'ports', make_port_value(address="aaa"))
        op.apply(testspec1, storage)

        self.assertEqual(Port.from_pyvalue(make_port_value(address='aaa')),
                         Port.from_pyvalue(make_port_value(address=['aaa'])))

        self.assertEqual(
            Port.from_pyvalue(make_port_value(address=['aaa', 'bbb'])),
            Port.from_pyvalue(make_port_value(address=['bbb', 'aaa'])))

        self.assertNotEqual(
            Port.from_pyvalue(make_port_value(address=['aaa', 'bbb'])),
            Port.from_pyvalue(make_port_value(address=['bbb', 'aa1'])))