xref: /unit/test/test_php_targets.py (revision 2055:84cb1ec94bae)
11479Szelenkov@nginx.comfrom unit.applications.lang.php import TestApplicationPHP
21730Szelenkov@nginx.comfrom unit.option import option
31596Szelenkov@nginx.com
41479Szelenkov@nginx.com
51479Szelenkov@nginx.comclass TestPHPTargets(TestApplicationPHP):
61479Szelenkov@nginx.com    prerequisites = {'modules': {'php': 'any'}}
71479Szelenkov@nginx.com
81479Szelenkov@nginx.com    def test_php_application_targets(self):
91596Szelenkov@nginx.com        assert 'success' in self.conf(
101596Szelenkov@nginx.com            {
111596Szelenkov@nginx.com                "listeners": {"*:7080": {"pass": "routes"}},
121596Szelenkov@nginx.com                "routes": [
131596Szelenkov@nginx.com                    {
141596Szelenkov@nginx.com                        "match": {"uri": "/1"},
151596Szelenkov@nginx.com                        "action": {"pass": "applications/targets/1"},
161596Szelenkov@nginx.com                    },
171596Szelenkov@nginx.com                    {
181596Szelenkov@nginx.com                        "match": {"uri": "/2"},
191596Szelenkov@nginx.com                        "action": {"pass": "applications/targets/2"},
201596Szelenkov@nginx.com                    },
211596Szelenkov@nginx.com                    {"action": {"pass": "applications/targets/default"}},
221596Szelenkov@nginx.com                ],
231596Szelenkov@nginx.com                "applications": {
241596Szelenkov@nginx.com                    "targets": {
25*2055Szelenkov@nginx.com                        "type": self.get_application_type(),
261596Szelenkov@nginx.com                        "processes": {"spare": 0},
271479Szelenkov@nginx.com                        "targets": {
281596Szelenkov@nginx.com                            "1": {
291596Szelenkov@nginx.com                                "script": "1.php",
301596Szelenkov@nginx.com                                "root": option.test_dir + "/php/targets",
311596Szelenkov@nginx.com                            },
321596Szelenkov@nginx.com                            "2": {
331596Szelenkov@nginx.com                                "script": "2.php",
341596Szelenkov@nginx.com                                "root": option.test_dir + "/php/targets/2",
351479Szelenkov@nginx.com                            },
361596Szelenkov@nginx.com                            "default": {
371596Szelenkov@nginx.com                                "index": "index.php",
381596Szelenkov@nginx.com                                "root": option.test_dir + "/php/targets",
391596Szelenkov@nginx.com                            },
401596Szelenkov@nginx.com                        },
411596Szelenkov@nginx.com                    }
421596Szelenkov@nginx.com                },
431596Szelenkov@nginx.com            }
441479Szelenkov@nginx.com        )
451479Szelenkov@nginx.com
461596Szelenkov@nginx.com        assert self.get(url='/1')['body'] == '1'
471596Szelenkov@nginx.com        assert self.get(url='/2')['body'] == '2'
481596Szelenkov@nginx.com        assert self.get(url='/blah')['status'] == 503  # TODO 404
491596Szelenkov@nginx.com        assert self.get(url='/')['body'] == 'index'
501479Szelenkov@nginx.com
511596Szelenkov@nginx.com        assert 'success' in self.conf(
521596Szelenkov@nginx.com            "\"1.php\"", 'applications/targets/targets/default/index'
531596Szelenkov@nginx.com        ), 'change targets index'
541596Szelenkov@nginx.com        assert self.get(url='/')['body'] == '1'
551479Szelenkov@nginx.com
561596Szelenkov@nginx.com        assert 'success' in self.conf_delete(
571596Szelenkov@nginx.com            'applications/targets/targets/default/index'
581596Szelenkov@nginx.com        ), 'remove targets index'
591596Szelenkov@nginx.com        assert self.get(url='/')['body'] == 'index'
601479Szelenkov@nginx.com
611479Szelenkov@nginx.com    def test_php_application_targets_error(self):
621596Szelenkov@nginx.com        assert 'success' in self.conf(
631596Szelenkov@nginx.com            {
641596Szelenkov@nginx.com                "listeners": {
651596Szelenkov@nginx.com                    "*:7080": {"pass": "applications/targets/default"}
661596Szelenkov@nginx.com                },
671596Szelenkov@nginx.com                "applications": {
681596Szelenkov@nginx.com                    "targets": {
69*2055Szelenkov@nginx.com                        "type": self.get_application_type(),
701596Szelenkov@nginx.com                        "processes": {"spare": 0},
711479Szelenkov@nginx.com                        "targets": {
721596Szelenkov@nginx.com                            "default": {
731596Szelenkov@nginx.com                                "index": "index.php",
741596Szelenkov@nginx.com                                "root": option.test_dir + "/php/targets",
751479Szelenkov@nginx.com                            },
761596Szelenkov@nginx.com                        },
771596Szelenkov@nginx.com                    }
781596Szelenkov@nginx.com                },
791596Szelenkov@nginx.com            }
801596Szelenkov@nginx.com        ), 'initial configuration'
811596Szelenkov@nginx.com        assert self.get()['status'] == 200
821479Szelenkov@nginx.com
831596Szelenkov@nginx.com        assert 'error' in self.conf(
841596Szelenkov@nginx.com            {"pass": "applications/targets/blah"}, 'listeners/*:7080'
851596Szelenkov@nginx.com        ), 'invalid targets pass'
861596Szelenkov@nginx.com        assert 'error' in self.conf(
871596Szelenkov@nginx.com            '"' + option.test_dir + '/php/targets\"',
881596Szelenkov@nginx.com            'applications/targets/root',
891596Szelenkov@nginx.com        ), 'invalid root'
901596Szelenkov@nginx.com        assert 'error' in self.conf(
911596Szelenkov@nginx.com            '"index.php"', 'applications/targets/index'
921596Szelenkov@nginx.com        ), 'invalid index'
931596Szelenkov@nginx.com        assert 'error' in self.conf(
941596Szelenkov@nginx.com            '"index.php"', 'applications/targets/script'
951596Szelenkov@nginx.com        ), 'invalid script'
961596Szelenkov@nginx.com        assert 'error' in self.conf_delete(
971596Szelenkov@nginx.com            'applications/targets/default/root'
981596Szelenkov@nginx.com        ), 'root remove'
99