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
|
# -*- coding: utf-8 -*-
import pytest
from os.path import join
from django_extensions.management.commands.runserver_plus import (
Command as RunServerCommand,
)
from unittest import mock
location = join("some", "strange", "path")
different_path = join("some", "other", "path")
@pytest.mark.parametrize(
"cert_option, key_file_option, expected_cert_path, expected_key_path",
[
["hello", None, join(location, "hello.crt"), join(location, "hello.key")],
["hello.crt", None, join(location, "hello.crt"), join(location, "hello.key")],
[None, "hello", join(location, "hello.crt"), join(location, "hello.key")],
[None, "hello.key", join(location, "hello.crt"), join(location, "hello.key")],
["first", "second", join(location, "first.crt"), join(location, "second.key")],
[
"first.pem",
"second.pem",
join(location, "first.pem"),
join(location, "second.pem"),
],
["cert.pem", "key.pem", join(location, "cert.pem"), join(location, "key.pem")],
[
join(location, "hello"),
None,
join(location, "hello.crt"),
join(location, "hello.key"),
],
[
None,
join(location, "hello"),
join(location, "hello.crt"),
join(location, "hello.key"),
],
[
join(location, "hello"),
join(location, "hello"),
join(location, "hello.crt"),
join(location, "hello.key"),
],
[
join(location, "hello.crt"),
join(location, "hello.key"),
join(location, "hello.crt"),
join(location, "hello.key"),
],
[
join(location, "hello.key"),
join(location, "hello.crt"),
join(location, "hello.key"),
join(location, "hello.crt"),
],
[
join(location, "cert.pem"),
join(location, "key.pem"),
join(location, "cert.pem"),
join(location, "key.pem"),
],
[
join(location, "hello.crt"),
join(location, "hello.key"),
join(location, "hello.crt"),
join(location, "hello.key"),
],
[
join(location, "other"),
join(location, "hello.key"),
join(location, "other.crt"),
join(location, "hello.key"),
],
[
join(location, "hello.key"),
join(location, "hello.crt"),
join(location, "hello.key"),
join(location, "hello.crt"),
],
[
join(different_path, "hello"),
None,
join(different_path, "hello.crt"),
join(different_path, "hello.key"),
],
[
None,
join(different_path, "hello"),
join(different_path, "hello.crt"),
join(different_path, "hello.key"),
],
[
join(location, "hello.crt"),
join(different_path, "hello.key"),
join(location, "hello.crt"),
join(different_path, "hello.key"),
],
[
join(different_path, "hello.crt"),
join(location, "hello.key"),
join(different_path, "hello.crt"),
join(location, "hello.key"),
],
],
)
def test_determining_paths(
cert_option, key_file_option, expected_cert_path, expected_key_path
):
with mock.patch(
"django_extensions.management.commands.runserver_plus.os.getcwd",
return_value=location,
):
options = {"cert_path": cert_option, "key_file_path": key_file_option}
result_cert_path, result_key_path = RunServerCommand.determine_ssl_files_paths(
options
)
assert expected_cert_path == result_cert_path
assert expected_key_path == result_key_path
|