-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_server.py
More file actions
40 lines (29 loc) · 1.27 KB
/
Copy pathtest_server.py
File metadata and controls
40 lines (29 loc) · 1.27 KB
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
"""Tests for server startup configuration."""
import os
import unittest
from unittest.mock import patch
from server import app
class ServerStartupTests(unittest.TestCase):
@patch("uvicorn.run")
@patch("copilot.auth.load_auth")
def test_uses_default_address(self, _load_auth, run):
with patch.dict(os.environ, {}, clear=True):
app()
self.assertEqual(run.call_args.kwargs["host"], "127.0.0.1")
self.assertEqual(run.call_args.kwargs["port"], 8000)
@patch("uvicorn.run")
@patch("copilot.auth.load_auth")
def test_uses_address_from_environment(self, _load_auth, run):
with patch.dict(os.environ, {"HOST": "0.0.0.0", "PORT": "8080"}, clear=True):
app()
self.assertEqual(run.call_args.kwargs["host"], "0.0.0.0")
self.assertEqual(run.call_args.kwargs["port"], 8080)
@patch("uvicorn.run")
@patch("copilot.auth.load_auth")
def test_explicit_address_takes_precedence(self, _load_auth, run):
with patch.dict(os.environ, {"HOST": "0.0.0.0", "PORT": "8080"}, clear=True):
app(host="localhost", port=0)
self.assertEqual(run.call_args.kwargs["host"], "localhost")
self.assertEqual(run.call_args.kwargs["port"], 0)
if __name__ == "__main__":
unittest.main()