File: test_https_support.py

package info (click to toggle)
pytest-tornado 0.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 168 kB
  • sloc: python: 502; makefile: 19; sh: 1
file content (50 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download | duplicates (3)
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
import os
import ssl
import pytest
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


@pytest.fixture
def ssl_options():
    cert_file = os.path.join(os.path.dirname(__file__), 'testcert.pem')
    if not os.path.exists(cert_file):
        pytest.skip("Missing cert file {!r}")
    key_file = os.path.join(os.path.dirname(__file__), 'testcert.pem')
    if not os.path.exists(key_file):
        pytest.skip("Missing key file {!r}")

    ssl_context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH, cafile=None, capath=None, cadata=None)
    ssl_context.load_cert_chain(cert_file, keyfile=key_file)
    return ssl_context


@pytest.fixture
def app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])


@pytest.mark.gen_test
def test_hello_world(https_client, base_url):
    response = yield https_client.fetch(base_url, validate_cert=False)
    assert response.code == 200


def test_base_url_is_https_with_https_client(https_client, base_url):
    assert base_url.startswith('https://')



def test_base_url_is_https_with_https_port(https_port, base_url):
    assert base_url.startswith('https://')



def test_base_url_is_https_with_https_server(https_server, base_url):
    assert base_url.startswith('https://')