Пример #1
0
    def test_simple_replace(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)
        c.load("""
            foo: 3
            qux: 1
            """)

        self.failUnlessEqual(c.get()['foo'], 3)
        self.failUnlessEqual(c.get()['bar'], 2)
        self.failUnlessEqual(c.get()['qux'], 1)
Пример #2
0
    def test_simple_replace(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)
        c.load("""
            foo: 3
            qux: 1
            """)

        self.failUnlessEqual(c.get()['foo'], 3)
        self.failUnlessEqual(c.get()['bar'], 2)
        self.failUnlessEqual(c.get()['qux'], 1)
Пример #3
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Пример #4
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Пример #5
0
    def test_nested_map_update(self):
        c = Config()
        c.load("""
            foo:
                foo: 1
                bar: 2
            bar: 2
            """)
        c.load("""
            foo:
                foo: 2
                baz: 3
            baz: 3
            """)

        self.failUnlessEqual(c.get()['foo']['foo'], 2)
        self.failUnlessEqual(c.get()['foo']['bar'], 2)
        self.failUnlessEqual(c.get()['foo']['baz'], 3)
        self.failUnlessEqual(c.get()['baz'], 3)
Пример #6
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Пример #7
0
    def test_nested_map_update(self):
        c = Config()
        c.load("""
            foo:
                foo: 1
                bar: 2
            bar: 2
            """)
        c.load("""
            foo:
                foo: 2
                baz: 3
            baz: 3
            """)

        self.failUnlessEqual(c.get()['foo']['foo'], 2)
        self.failUnlessEqual(c.get()['foo']['bar'], 2)
        self.failUnlessEqual(c.get()['foo']['baz'], 3)
        self.failUnlessEqual(c.get()['baz'], 3)
Пример #8
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Пример #9
0
    def test_list_append(self):
        c = Config()

        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.append:
                - 4
                - 5
                - 6
            """)
        self.failUnlessEqual(c.get()['foo'], [1, 2, 3, 4, 5, 6])
Пример #10
0
    def test_list_append(self):
        c = Config()

        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.append:
                - 4
                - 5
                - 6
            """)
        self.failUnlessEqual(c.get()['foo'], [1,2,3,4,5,6])
Пример #11
0
    def test_list_remove(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.remove:
                - 1
                - 2
                - 3
                - 5
            """)

        self.failUnlessEqual(c.get()['foo'], [])
Пример #12
0
    def test_list_remove(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.remove:
                - 1
                - 2
                - 3
                - 5
            """)

        self.failUnlessEqual(c.get()['foo'], [])
Пример #13
0
    def test_override_literal(self):
        config = Config()
        config.load(test_yay)
        config.add(dict(injected_data="xyz"))

        self.failUnlessEqual(config.get()["result"], "xyz")
Пример #14
0
class TestDjangoYay(TestDjangoBase):
    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)

    def test_all_cars(self):
        self.config.load("""test: ${metadata.Car}""")
        l = self.config.get()["test"]

        self.failUnless(isinstance(l[0], dict))
        self.failUnlessEqual(l[0]["name"], "fred")

    def test_foreach_car(self):
        self.config.load("""
            test.foreach c in metadata.Car: ${c.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["fred", "bobby"])

    def test_foreach_car_parts(self):
        self.config.load("""
            test.foreach c in metadata.Car:
              .foreach p in c.parts: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])

    def test_foreach_car_parts_if(self):
        self.config.load("""
            x: badger
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["badger"])

    def test_foreach_car_parts_if_failing(self):
        self.config.load("""
            x: badge
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_model_callable(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_callable: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])

    def test_model_callable_generator(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_generator: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])
Пример #15
0
class TestDb(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        Base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()

    def tearDown(self):
        Base.metadata.drop_all(self.t.backend.engine)

    def test_foreach_host(self):
        self.config.load("""
            test.foreach h in metadata.host: ${h.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["wonderflonium"])

    def test_foreach_host_service(self):
        self.config.load("""
            test.foreach h in metadata.host:
              .foreach s in h.services: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if(self):
        self.config.load("""
            branch: /trunk
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if_failing(self):
        self.config.load("""
            branch: /trun
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])
Пример #16
0
def load_config(uri):
    basedir = os.path.dirname(uri)
    c = Config(searchpath=[basedir])
    c.load_uri(uri)
    return ProxyConfig(c.get())
Пример #17
0
class TestDjangoYay(TestDjangoBase):

    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)

    def test_all_cars(self):
        self.config.load("""test: ${metadata.Car}""")
        l = self.config.get()["test"]

        self.failUnless(isinstance(l[0], dict))
        self.failUnlessEqual(l[0]["name"], "fred")

    def test_foreach_car(self):
        self.config.load("""
            test.foreach c in metadata.Car: ${c.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["fred", "bobby"])

    def test_foreach_car_parts(self):
        self.config.load("""
            test.foreach c in metadata.Car:
              .foreach p in c.parts: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel', 'brake', 'badger'])

    def test_foreach_car_parts_if(self):
        self.config.load("""
            x: badger
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["badger"])

    def test_foreach_car_parts_if_failing(self):
        self.config.load("""
            x: badge
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_model_callable(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_callable: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel','brake','badger'])

    def test_model_callable_generator(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_generator: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel','brake','badger'])
Пример #18
0
class TestDb(unittest.TestCase):

    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        t.backend.base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()

    def tearDown(self):
        self.t.backend.base.metadata.drop_all(self.t.backend.engine)

    def test_foreach_host(self):
        self.config.load("""
            test.foreach h in metadata.host: ${h.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["wonderflonium"])

    def test_foreach_host_service(self):
        self.config.load("""
            test.foreach h in metadata.host:
              .foreach s in h.services: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if(self):
        self.config.load("""
            branch: /trunk
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if_failing(self):
        self.config.load("""
            branch: /trun
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_list_all(self):
        self.config.get()
Пример #19
0
    def test_override_literal(self):
        config = Config()
        config.load(test_yay)
        config.add(dict(injected_data="xyz"))

        self.failUnlessEqual(config.get()["result"], "xyz")