File: test_get_wsgi_filter.py

package info (click to toggle)
python-plaster-pastedeploy 0.5-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 316 kB
  • sloc: python: 639; makefile: 12
file content (79 lines) | stat: -rw-r--r-- 2,494 bytes parent folder | download | duplicates (5)
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
78
79
import os
import plaster
import pytest

here = os.path.dirname(__file__)

test_filter_path = 'sample_configs/test_filter.ini'


class TestSimpleURI(object):
    config_uri = test_filter_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_filter(self):
        import fakeapp.apps
        app_filter_factory = self.loader.get_wsgi_filter('filt')

        other_loader = plaster.get_loader(
            'sample_configs/basic_app.ini', protocols=['wsgi'])
        app = other_loader.get_wsgi_app()
        app_filter = app_filter_factory(app)

        assert isinstance(app_filter, fakeapp.apps.CapFilter)
        assert app_filter.method_to_call == 'lower'
        assert app_filter.app is fakeapp.apps.basic_app

    def test_invalid_name(self):
        with pytest.raises(LookupError):
            self.loader.get_wsgi_filter('invalid')


class TestSectionedURI(TestSimpleURI):
    config_uri = test_filter_path + '#filt'

    def test_get_wsgi_filter(self):
        import fakeapp.apps
        app_filter_factory = self.loader.get_wsgi_filter()

        other_loader = plaster.get_loader(
            'pastedeploy+ini:sample_configs/basic_app.ini#main',
            protocols=['wsgi'])
        app = other_loader.get_wsgi_app()
        app_filter = app_filter_factory(app)

        assert isinstance(app_filter, fakeapp.apps.CapFilter)
        assert app_filter.method_to_call == 'lower'
        assert app_filter.app is fakeapp.apps.basic_app


class TestSchemeAndSectionedURI(TestSectionedURI):
    config_uri = 'pastedeploy+ini:' + test_filter_path + '#filt'


class TestEggURI(object):
    config_uri = 'egg:FakeApp#caps'

    @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
        filter = self.loader.get_wsgi_filter()
        filtered_app = filter('foo')
        assert isinstance(filtered_app, fakeapp.apps.CapFilter)

    def test_it_override_name(self):
        import fakeapp.apps
        filter = self.loader.get_wsgi_filter('caps')
        filtered_app = filter('foo')
        assert isinstance(filtered_app, fakeapp.apps.CapFilter)

    def test_invalid_name(self):
        with pytest.raises(LookupError):
            self.loader.get_wsgi_filter('invalid')