xref: /unit/test/test_python_targets.py (revision 1873:d0cc4fd78d43)
1import pytest
2
3from unit.applications.lang.python import TestApplicationPython
4from unit.option import option
5
6
7class TestPythonTargets(TestApplicationPython):
8    prerequisites = {'modules': {'python': 'all'}}
9
10    def test_python_targets(self):
11        assert 'success' in self.conf(
12            {
13                "listeners": {"*:7080": {"pass": "routes"}},
14                "routes": [
15                    {
16                        "match": {"uri": "/1"},
17                        "action": {"pass": "applications/targets/1"},
18                    },
19                    {
20                        "match": {"uri": "/2"},
21                        "action": {"pass": "applications/targets/2"},
22                    },
23                ],
24                "applications": {
25                    "targets": {
26                        "type": "python",
27                        "working_directory": option.test_dir
28                        + "/python/targets/",
29                        "path": option.test_dir + '/python/targets/',
30                        "targets": {
31                            "1": {
32                                "module": "wsgi",
33                                "callable": "wsgi_target_a",
34                            },
35                            "2": {
36                                "module": "wsgi",
37                                "callable": "wsgi_target_b",
38                            },
39                        },
40                    }
41                },
42            }
43        )
44
45        resp = self.get(url='/1')
46        assert resp['status'] == 200
47        assert resp['body'] == '1'
48
49        resp = self.get(url='/2')
50        assert resp['status'] == 200
51        assert resp['body'] == '2'
52