File: test_http.py

package info (click to toggle)
graphite-api 1.1.3-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 752 kB
  • sloc: python: 7,757; sh: 215; makefile: 150
file content (33 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (2)
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
from . import TestCase


class HttpTestCase(TestCase):
    def test_cors(self):
        response = self.app.options('/render')
        self.assertFalse(
            'Access-Control-Allow-Origin' in response.headers.keys())

        response = self.app.options('/render', headers=(
            ('Origin', 'https://example.com'),
        ))
        self.assertEqual(response.headers['Access-Control-Allow-Origin'],
                         'https://example.com')

        response = self.app.options('/render', headers=(
            ('Origin', 'http://foo.example.com:8888'),
        ))
        self.assertEqual(response.headers['Access-Control-Allow-Origin'],
                         'http://foo.example.com:8888')

        response = self.app.options('/', headers=(
            ('Origin', 'http://foo.example.com'),
        ))
        self.assertFalse(
            'Access-Control-Allow-Origin' in response.headers.keys())

    def test_trailing_slash(self):
        response = self.app.get('/render?target=foo')
        self.assertEqual(response.status_code, 200)

        response = self.app.get('/render/?target=foo')
        self.assertEqual(response.status_code, 200)