Example #1
0
    def test_update_binding_error_put(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 500
        rsp.text = "my error"

        nginx = NginxDAV()
        with self.assertRaises(NginxError) as context:
            nginx.update_binding('myhost', '/', 'mydestination')
        self.assertEqual(
            str(context.exception),
            "Error trying to update file in nginx: PUT http://myhost:8089/dav/location_:.conf: my error")
Example #2
0
    def test_update_binding_error_put(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 500
        rsp.text = "my error"

        nginx = NginxDAV()
        with self.assertRaises(NginxError) as context:
            nginx.update_binding('myhost', '/', 'mydestination')
        self.assertEqual(
            str(context.exception),
            "Error trying to update file in nginx: PUT http://myhost:8089/dav/location_:.conf: my error")
Example #3
0
    def test_update_binding_custom_content(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 200

        nginx = NginxDAV()

        nginx.update_binding('myhost', '/', content='location @rad {}')
        requests.request.assert_called_once_with(
            'PUT', 'http://*****:*****@rad {}")
        requests.get.assert_called_once_with('http://myhost:8089/reload')
Example #4
0
    def test_update_binding_custom_content(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 200

        nginx = NginxDAV()

        nginx.update_binding('myhost', '/', content='location @rad {}')
        requests.request.assert_called_once_with(
            'PUT', 'http://*****:*****@rad {}")
        requests.get.assert_called_once_with('http://myhost:8089/reload')
Example #5
0
    def test_update_binding_other_path(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 200

        nginx = NginxDAV()

        nginx.update_binding('myhost', '/app/route', 'mydestination')
        requests.request.assert_called_once_with('PUT', 'http://myhost:8089/dav/location_:app:route.conf', data="""
location /app/route/ {
    proxy_set_header Host mydestination;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass http://mydestination:80/;
    proxy_redirect ~^http://mydestination(:\d+)?/(.*)$ /app/route/$2;
}
""")
        requests.get.assert_called_once_with('http://myhost:8089/reload')
Example #6
0
    def test_update_binding_other_path(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 200

        nginx = NginxDAV()

        nginx.update_binding('myhost', '/app/route', 'mydestination')
        requests.request.assert_called_once_with('PUT', 'http://myhost:8089/dav/location_:app:route.conf', data="""
location /app/route/ {
    proxy_set_header Host mydestination;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass http://mydestination:80/;
    proxy_redirect ~^http://mydestination(:\d+)?/(.*)$ /app/route/$2;
}
""")
        requests.get.assert_called_once_with('http://myhost:8089/reload')
Example #7
0
    def test_update_binding_error_reload(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 500
        rsp_get.text = "my error"

        nginx = NginxDAV()
        with self.assertRaises(NginxError) as context:
            nginx.update_binding('myhost', '/', 'mydestination')
        self.assertEqual(
            str(context.exception),
            "Error trying to reload config in nginx: http://myhost:8089/reload: my error")
        requests.request.assert_called_once_with('PUT', 'http://myhost:8089/dav/location_:.conf', data="""
location / {
    proxy_set_header Host mydestination;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass http://mydestination:80/;
    proxy_redirect ~^http://mydestination(:\d+)?/(.*)$ /$2;
}
""")
Example #8
0
    def test_update_binding_error_reload(self, requests):
        rsp = requests.request.return_value
        rsp.status_code = 200
        rsp_get = requests.get.return_value
        rsp_get.status_code = 500
        rsp_get.text = "my error"

        nginx = NginxDAV()
        with self.assertRaises(NginxError) as context:
            nginx.update_binding('myhost', '/', 'mydestination')
        self.assertEqual(
            str(context.exception),
            "Error trying to reload config in nginx: http://myhost:8089/reload: my error")
        requests.request.assert_called_once_with('PUT', 'http://myhost:8089/dav/location_:.conf', data="""
location / {
    proxy_set_header Host mydestination;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_pass http://mydestination:80/;
    proxy_redirect ~^http://mydestination(:\d+)?/(.*)$ /$2;
}
""")