diff options
Diffstat (limited to 'tests/integration/test_config.py')
| -rw-r--r-- | tests/integration/test_config.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py new file mode 100644 index 0000000..fe5cf9d --- /dev/null +++ b/tests/integration/test_config.py | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | """Settings the tracker has to accept, and still work with. | ||
| 2 | |||
| 3 | An unrecognised key only warns, so coming up proves nothing on its own and a | ||
| 4 | test that cares has to look at what the tracker said. A key that is | ||
| 5 | recognised but cannot be parsed is another matter, and for the listen | ||
| 6 | statements it stops the tracker. | ||
| 7 | """ | ||
| 8 | |||
| 9 | import unittest | ||
| 10 | |||
| 11 | from harness import Tracker, TrackerTestCase, free_port | ||
| 12 | |||
| 13 | |||
| 14 | class TcpWorkers(TrackerTestCase): | ||
| 15 | config = "listen.tcp.workers 2\n" | ||
| 16 | |||
| 17 | def test_the_tracker_serves_with_tcp_workers_asked_for(self): | ||
| 18 | self.assertEqual(self.tracker.announce(self.hash_for("tcpworkers"))[b"complete"], 1) | ||
| 19 | self.assertNotIn("Unhandled line", self.tracker.output()) | ||
| 20 | |||
| 21 | |||
| 22 | class WorkersOnAListenStatement(unittest.TestCase): | ||
| 23 | def test_a_listen_statement_may_carry_a_worker_count(self): | ||
| 24 | """The option is read off the statement rather than inherited.""" | ||
| 25 | second = free_port() | ||
| 26 | tracker = Tracker("listen.tcp 127.0.0.1:%d workers=2\n" % second) | ||
| 27 | try: | ||
| 28 | self.assertEqual(tracker.announce(b"listenopts\0\0\0\0\0\0\0\0\0\0")[b"complete"], 1) | ||
| 29 | complaints = tracker.stop() | ||
| 30 | self.assertEqual(complaints, [], "the tracker reported:\n" + "\n".join(complaints)) | ||
| 31 | finally: | ||
| 32 | tracker._cleanup() | ||
| 33 | |||
| 34 | |||
| 35 | class AListenLineThatDoesNotParse(unittest.TestCase): | ||
| 36 | """Warning and carrying on left a tracker that had been told where to | ||
| 37 | listen coming up on its default instead, which is every interface.""" | ||
| 38 | |||
| 39 | def refuses(self, line): | ||
| 40 | with self.assertRaises(AssertionError) as caught: | ||
| 41 | Tracker(line) | ||
| 42 | return str(caught.exception) | ||
| 43 | |||
| 44 | def test_an_address_that_is_not_one_stops_the_tracker(self): | ||
| 45 | self.assertIn("want an address", self.refuses("listen.tcp 10.0.0.300:7999\n")) | ||
| 46 | |||
| 47 | def test_so_does_a_port_out_of_range(self): | ||
| 48 | self.assertIn("want an address", self.refuses("listen.udp 127.0.0.1:99999\n")) | ||
| 49 | |||
| 50 | def test_so_does_an_option_it_does_not_know(self): | ||
| 51 | self.assertIn("want an address", self.refuses("listen.tcp 127.0.0.1:7999 wokers=2\n")) | ||
| 52 | |||
| 53 | |||
| 54 | class EmptyTorrentTimeout(TrackerTestCase): | ||
| 55 | config = "tracker.empty_torrent_timeout 60\n" | ||
| 56 | |||
| 57 | def test_the_tracker_accepts_the_option_and_serves(self): | ||
| 58 | self.assertEqual(self.tracker.announce(self.hash_for("emptyto"))[b"complete"], 1) | ||
| 59 | self.assertNotIn("Unhandled line", self.tracker.output()) | ||
| 60 | self.assertNotIn("Parse error", self.tracker.output()) | ||
| 61 | |||
| 62 | |||
| 63 | class EmptyTorrentTimeoutThatDoesNotParse(unittest.TestCase): | ||
| 64 | def test_a_non_numeric_value_warns_but_the_tracker_serves(self): | ||
| 65 | """A scalar that will not parse warns and is ignored, unlike a listen | ||
| 66 | line, which stops the tracker.""" | ||
| 67 | tracker = Tracker("tracker.empty_torrent_timeout later\n") | ||
| 68 | try: | ||
| 69 | self.assertEqual(tracker.announce(b"emptytobad\0\0\0\0\0\0\0\0\0\0")[b"complete"], 1) | ||
| 70 | self.assertIn("Parse error", tracker.output()) | ||
| 71 | finally: | ||
| 72 | tracker._cleanup() | ||
