summaryrefslogtreecommitdiffhomepage
path: root/test/test_configuration.py
blob: b9aad8a46658fc7eae3326e01ce8efd3a71090e6 (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import unittest
import unit

class TestUnitConfiguration(unit.TestUnitControl):

    def setUpClass():
        unit.TestUnit().check_modules('python')

    def test_json_applications(self):
        self.assertIn('error', self.put('/applications', '"{}"'),
            'applications string')
        self.assertIn('error', self.put('/applications', '{'),
            'applications miss brace')

        self.assertIn('error', self.put('/applications', """
            {
                app": {
                    "type": "python",
                    "workers": 1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'applications miss quote')

        self.assertIn('error', self.put('/applications', """
            {
                "app" {
                    "type": "python",
                    "workers": 1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'applications miss colon')

        self.assertIn('error', self.put('/applications', """
            {
                "app": {
                    "type": "python"
                    "workers": 1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'applications miss comma')

        self.assertIn('success', self.put('/applications', b'{ \n\r\t}'),
            'skip space')

        self.assertIn('success', self.put('/applications', """
            {
                "app": {
                    "type": "python",
                    "workers": 1,
                    "path": "../app",
                    "module": "wsgi"
                }
            }
            """), 'relative path')

        self.assertIn('success', self.put('/applications', b"""
            {
                "ap\u0070": {
                    "type": "\u0070ython",
                    "workers": 1,
                    "path": "\u002Fapp",
                    "module": "wsgi"
                }
            }
            """), 'unicode')

        self.assertIn('success', self.put('/applications', """
            {
                "приложение": {
                    "type": "python",
                    "workers": 1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'unicode 2')

        self.assertIn('error', self.put('/applications', b"""
            {
                "app": {
                    "type": "python",
                    "workers": \u0031,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'unicode number')

    def test_json_listeners(self):
        self.assertIn('error', self.put('/listeners',
            '{"*:7080":{"application":"app"}}'), 'listeners no app')

        self.put('/applications', """
            {
                "app": {
                    "type": "python",
                    "workers": 1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """)

        self.assertIn('success', self.put('/listeners',
            '{"*:7080":{"application":"app"}}'), 'listeners wildcard')
        self.assertIn('success', self.put('/listeners',
            '{"127.0.0.1:7081":{"application":"app"}}'), 'listeners explicit')
        self.assertIn('success', self.put('/listeners',
            '{"[::1]:7082":{"application":"app"}}'), 'listeners explicit ipv6')
        self.assertIn('error', self.put('/listeners',
            '{"127.0.0.1":{"application":"app"}}'), 'listeners no port')

    @unittest.skip("TODO")
    def test_broken(self):
        self.assertIn('error', self.put('/', '00'), 'leading zero')
        self.assertIn('error', self.put('/listeners', '{"*:7080":{}}'),
            'listener empty')
        self.assertIn('error', self.put('/applications', '"type":"python"'),
            'application type only')

        self.assertIn('error', self.put('/applications', """
            {
                "app": {
                    "type": "python",
                    "workers": -1,
                    "path": "/app",
                    "module": "wsgi"
                }
            }
            """), 'negative workers')

if __name__ == '__main__':
    unittest.main()