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 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import os
import plaster
import pytest
here = os.path.dirname(__file__)
basic_app_relpath = 'sample_configs/basic_app.ini'
basic_app_path = os.path.abspath(os.path.join(here, basic_app_relpath))
class TestSimpleURI(object):
config_uri = basic_app_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_app_with_relative(self):
import fakeapp.apps
app = self.loader.get_wsgi_app()
assert app is fakeapp.apps.basic_app
def test_get_wsgi_app_main(self):
import fakeapp.apps
app = self.loader.get_wsgi_app('main')
assert app is fakeapp.apps.basic_app
same_app = self.loader.get_wsgi_app()
assert same_app is fakeapp.apps.basic_app
def test_invalid_name(self):
with pytest.raises(LookupError):
self.loader.get_wsgi_app('invalid')
class TestSectionedURI(TestSimpleURI):
config_uri = basic_app_path + '#main'
class TestSchemeAndSectionedURI(TestSimpleURI):
config_uri = 'pastedeploy+ini:' + basic_app_path + '#main'
class TestRelativeURI(TestSimpleURI):
config_uri = basic_app_relpath
class TestRelativeSectionedURI(TestSectionedURI, TestRelativeURI):
config_uri = basic_app_relpath + '#main'
class TestRelativeSchemeAndSectionedURI(TestSchemeAndSectionedURI,
TestRelativeURI):
config_uri = 'pastedeploy+ini:' + basic_app_relpath + '#main'
class TestEggURI(object):
config_uri = 'egg:FakeApp#basic_app'
@pytest.fixture(autouse=True)
def loader(self, fake_packages):
self.loader = plaster.get_loader(self.config_uri, protocols=['wsgi'])
def test_it(self):
import fakeapp.apps
app = self.loader.get_wsgi_app()
assert app is fakeapp.apps.basic_app
def test_it_override_name(self):
import fakeapp.configapps
app = self.loader.get_wsgi_app('configed')
assert isinstance(app, fakeapp.configapps.SimpleApp)
def test_invalid_name(self):
with pytest.raises(LookupError):
self.loader.get_wsgi_app('invalid')
|