|
5 | 5 |
|
6 | 6 |
|
7 | 7 | class TestServerConstruction(TestCase):
|
8 |
| - def test_host_and_port_from_env_1(self): |
9 |
| - fake_host = "fake_host" |
10 |
| - fake_port = 1234 |
| 8 | + """ |
| 9 | + Tests to make sure that the underlying server is configured correctly when constructing |
| 10 | + the Server object. |
| 11 | + """ |
11 | 12 |
|
12 |
| - with mock.patch.dict(os.environ, {"HOST": fake_host, "PORT": str(fake_port)}): |
| 13 | + def test_host_and_port_defaults(self): |
| 14 | + """ |
| 15 | + Tests that a Server object takes on the default host and port when |
| 16 | + a) no host and port are passed in, and |
| 17 | + b) no HOST and PORT are set. |
| 18 | + """ |
| 19 | + with mock.patch.dict(os.environ, {}): |
13 | 20 | s = Server(AsyncInterpreter())
|
14 |
| - self.assertEqual(s.host, fake_host) |
15 |
| - self.assertEqual(s.port, fake_port) |
| 21 | + self.assertEqual(s.host, Server.DEFAULT_HOST) |
| 22 | + self.assertEqual(s.port, Server.DEFAULT_PORT) |
| 23 | + |
| 24 | + def test_host_and_port_passed_in(self): |
| 25 | + """ |
| 26 | + Tests that a Server object takes on the passed-in host and port when they are passed-in, |
| 27 | + ignoring the surrounding HOST and PORT env vars. |
| 28 | + """ |
| 29 | + host = "the-really-real-host" |
| 30 | + port = 2222 |
16 | 31 |
|
17 |
| - def test_host_and_port_from_env_2(self): |
18 |
| - fake_host = "some-other-fake-host" |
19 |
| - fake_port = 4321 |
| 32 | + with mock.patch.dict(os.environ, {"HOST": "this-is-supes-fake", "PORT": "9876"}): |
| 33 | + sboth = Server(AsyncInterpreter(), host, port) |
| 34 | + self.assertEqual(sboth.host, host) |
| 35 | + self.assertEqual(sboth.port, port) |
| 36 | + |
| 37 | + def test_host_and_port_from_env_1(self): |
| 38 | + """ |
| 39 | + Tests that the Server object takes on the HOST and PORT env vars as host and port when |
| 40 | + nothing has been passed in. |
| 41 | + """ |
| 42 | + fake_host = "fake_host" |
| 43 | + fake_port = 1234 |
20 | 44 |
|
21 | 45 | with mock.patch.dict(os.environ, {"HOST": fake_host, "PORT": str(fake_port)}):
|
22 | 46 | s = Server(AsyncInterpreter())
|
|
0 commit comments