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'
def setUp(self): self.collection = confy.collection( protocol="http", URL="{protocol}://something.com", ) self.module = confy.Module('settings', 'unexisted/settings/__init__.pyc', self.collection)
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', })
def test_update_with_collection_populates_collection_with_properties_not_values(self): col = confy.collection( name="confy", version="0.3.7", fullversion="{name}-{version}", ) props = col.properties() # returns regular dict, not collection assert props['name'].__class__ == confy.ValueProperty assert props['version'].__class__ == confy.ValueProperty assert props['fullversion'].__class__ == confy.InterpolationProperty existing_properties = self.collection.properties() assert set(existing_properties.keys()) == set(['URL', 'protocol']) self.collection.update(col) updated_properties = self.collection.properties() assert set(updated_properties.keys()) == set([ 'URL', 'protocol', 'name', 'version', 'fullversion' ])
def test_update_with_collection_populates_collection_with_properties_not_values( self): col = confy.collection( name="confy", version="0.3.7", fullversion="{name}-{version}", ) props = col.properties() # returns regular dict, not collection assert props['name'].__class__ == confy.ValueProperty assert props['version'].__class__ == confy.ValueProperty assert props['fullversion'].__class__ == confy.InterpolationProperty existing_properties = self.collection.properties() assert set(existing_properties.keys()) == set(['URL', 'protocol']) self.collection.update(col) updated_properties = self.collection.properties() assert set(updated_properties.keys()) == set( ['URL', 'protocol', 'name', 'version', 'fullversion'])
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', })
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'
def setUp(self): self.collection = confy.collection( protocol = "http", URL = "{protocol}://something.com", ) self.module = confy.Module('settings', 'unexisted/settings/__init__.pyc', self.collection)
def setUp(self): self.collection = confy.collection( protocol = "http", URL = "{protocol}://something.com", )
def setUp(self): self.collection = confy.collection( protocol="http", URL="{protocol}://something.com", )