aboutsummaryrefslogtreecommitdiffstats
path: root/test/pathod/test_test.py
blob: d51a2c7a3149c2f46d166467403b8cb96e5becf6 (plain)
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
import os
import requests
import pytest

from pathod import test
from pathod.pathod import SSLOptions, CA_CERT_NAME


class TestDaemonManual:

    def test_simple(self):
        with test.Daemon() as d:
            rsp = requests.get("http://localhost:%s/p/202:da" % d.port)
            assert rsp.ok
            assert rsp.status_code == 202
        with pytest.raises(requests.ConnectionError):
            requests.get("http://localhost:%s/p/202:da" % d.port)

    @pytest.mark.parametrize('not_after_connect', [True, False])
    def test_startstop_ssl(self, not_after_connect):
        ssloptions = SSLOptions(
            cn=b'localhost',
            sans=[b'localhost', b'127.0.0.1'],
            not_after_connect=not_after_connect,
        )
        d = test.Daemon(ssl=True, ssloptions=ssloptions)
        rsp = requests.get(
            "https://localhost:%s/p/202:da" % d.port,
            verify=os.path.expanduser(os.path.join(d.thread.server.ssloptions.confdir, CA_CERT_NAME)))
        assert rsp.ok
        assert rsp.status_code == 202
        d.shutdown()
        with pytest.raises(requests.ConnectionError):
            requests.get("http://localhost:%s/p/202:da" % d.port)