1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import os
import plaster
import pytest
here = os.path.dirname(__file__)
test_config_path = 'sample_configs/test_config.ini'
class TestSimpleURI(object):
config_uri = test_config_path
@pytest.fixture(autouse=True)
def loader(self, fake_packages, monkeypatch):
monkeypatch.chdir(here)
self.loader = plaster.get_loader(self.config_uri, protocols=['wsgi'])
def test_get_wsgi_server_default(self):
server = self.loader.get_wsgi_server()
dummy_app = object()
result = server(dummy_app)
assert result is dummy_app
assert server.settings['foo'] == 'main'
def test_invalid_name(self):
with pytest.raises(LookupError):
self.loader.get_wsgi_server('invalid')
class TestSectionedURI(TestSimpleURI):
config_uri = test_config_path + '#other'
def test_get_wsgi_server_default(self):
server = self.loader.get_wsgi_server()
dummy_app = object()
result = server(dummy_app)
assert result is dummy_app
assert server.settings['foo'] == 'other'
class TestSchemeAndSectionedURI(TestSectionedURI):
config_uri = 'pastedeploy+ini:' + test_config_path + '#other'
class TestEggURI(object):
config_uri = 'egg:FakeApp#fake'
@pytest.fixture(autouse=True)
def loader(self, fake_packages):
self.loader = plaster.get_loader(self.config_uri, protocols=['wsgi'])
def test_it(self):
server = self.loader.get_wsgi_server()
result = server('foo')
assert result == 'foo'
def test_it_override_name(self):
server = self.loader.get_wsgi_server('fake')
result = server('foo')
assert result == 'foo'
def test_invalid_name(self):
with pytest.raises(LookupError):
self.loader.get_wsgi_server('invalid')
|