Beispiel #1
0
    def test_collectionize(self):
        testdict = {
            'DATABASE': {
                'ENGINE': confy.lazyimport('tests.fake.backend.FakeBackend'),
                'NAME': 'testdb',
                'USER': '******',
                'PASSWORD': '******',
                'HOST': 'test.db.com',
                'PORT': '9000',

                'testdata': confy.collection({
                    'fixtures': confy.rootpath('..', 'fixtures', 'testdata.json')
                }),
            },
            'HELLO': 'world',
        }

        private = {
            '__rootpath__': '/path/to/project/settings/__init__.py',
        }
        result = confy.Collection.collectionize(testdict, private=private)

        assert isinstance(result.DATABASE, confy.Collection)
        assert isinstance(result.DATABASE.testdata, confy.Collection)

        private_name = confy.utils.private_attribute_name(confy.Collection, 'private')
        assert getattr(result.DATABASE, private_name) == private
        assert getattr(result.DATABASE.testdata, private_name) == private

        assert result.DATABASE.testdata.fixtures == '/path/to/project/fixtures/testdata.json'
Beispiel #2
0
 def setUp(self):
     self.settings = confy.collection._new(dict(
         API = confy.collection(
             root = 'http://fancy.com/api',
             GET_OBJECT = '{root}/get',
             ADD_OBJECT = '{root}/add',
             REMOVE_OBJECT = '{root}/remove',
             UNEXISTED_VARIABLE = '{unexisted}/hello!'
         ),
         FAKE_BACKEND_CLASS = confy.lazyimport('tests.fake.backend.FakeBackend'),
         FAKE_BACKEND_MODULE = confy.lazyimport('tests.fake.backend'),
         RAW_VALUE = confy.raw('{with "raw" I can put {} as many special things as I want}'),
         URLS = confy.lazy(lambda self: "%s %s" % (self.API.GET_OBJECT, self.API.ADD_OBJECT)),
         PROJECT_ROOT = confy.rootpath('..'),
     ), private={
         # confy.rootpath stuff won't work without __rootpath__ private variable
         '__rootpath__': '/path/to/project/settings/__init__.py',
     })
Beispiel #3
0
 def setUp(self):
     self.settings = confy.collection._new(
         dict(
             API=confy.collection(root='http://fancy.com/api',
                                  GET_OBJECT='{root}/get',
                                  ADD_OBJECT='{root}/add',
                                  REMOVE_OBJECT='{root}/remove',
                                  UNEXISTED_VARIABLE='{unexisted}/hello!'),
             FAKE_BACKEND_CLASS=confy.lazyimport(
                 'tests.fake.backend.FakeBackend'),
             FAKE_BACKEND_MODULE=confy.lazyimport('tests.fake.backend'),
             RAW_VALUE=confy.raw(
                 '{with "raw" I can put {} as many special things as I want}'
             ),
             URLS=confy.lazy(lambda self: "%s %s" %
                             (self.API.GET_OBJECT, self.API.ADD_OBJECT)),
             PROJECT_ROOT=confy.rootpath('..'),
         ),
         private={
             # confy.rootpath stuff won't work without __rootpath__ private variable
             '__rootpath__': '/path/to/project/settings/__init__.py',
         })
Beispiel #4
0
    def test_collectionize(self):
        testdict = {
            'DATABASE': {
                'ENGINE':
                confy.lazyimport('tests.fake.backend.FakeBackend'),
                'NAME':
                'testdb',
                'USER':
                '******',
                'PASSWORD':
                '******',
                'HOST':
                'test.db.com',
                'PORT':
                '9000',
                'testdata':
                confy.collection({
                    'fixtures':
                    confy.rootpath('..', 'fixtures', 'testdata.json')
                }),
            },
            'HELLO': 'world',
        }

        private = {
            '__rootpath__': '/path/to/project/settings/__init__.py',
        }
        result = confy.Collection.collectionize(testdict, private=private)

        assert isinstance(result.DATABASE, confy.Collection)
        assert isinstance(result.DATABASE.testdata, confy.Collection)

        private_name = confy.utils.private_attribute_name(
            confy.Collection, 'private')
        assert getattr(result.DATABASE, private_name) == private
        assert getattr(result.DATABASE.testdata, private_name) == private

        assert result.DATABASE.testdata.fixtures == '/path/to/project/fixtures/testdata.json'