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