summaryrefslogtreecommitdiff
path: root/tests/integration/test_fullscrape.py
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:22:55 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 03:22:55 +0100
commit8c22d577fe1bf1f5c66c82c32854bdcd9ed1b3ee (patch)
tree6e425bf385ffb1ffa5502f56e57ea6bc09e57b97 /tests/integration/test_fullscrape.py
parent99b7b7b8716778846b08945594f4c3d984ffc6aa (diff)
Add test for the correct order of partial scrapes
Diffstat (limited to 'tests/integration/test_fullscrape.py')
-rw-r--r--tests/integration/test_fullscrape.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/integration/test_fullscrape.py b/tests/integration/test_fullscrape.py
index 4059656..be7b502 100644
--- a/tests/integration/test_fullscrape.py
+++ b/tests/integration/test_fullscrape.py
@@ -112,3 +112,35 @@ class FullScrapeChunking(TrackerTestCase):
112 112
113if __name__ == "__main__": 113if __name__ == "__main__":
114 unittest.main() 114 unittest.main()
115
116
117class PartialScrapeOrder(TrackerTestCase):
118 """A bencoded dictionary names its keys in order, once each. The full
119 scrape got that from walking the buckets; the partial scrape used to
120 echo whatever order the client asked in."""
121
122 def setUp(self):
123 TrackerTestCase.setUp(self)
124 self.hashes = [bytes([i]) + b"\0" * 19 for i in (9, 1, 5, 3, 7)]
125 for i, h in enumerate(self.hashes):
126 self.tracker.announce(h, port=6001 + i, left=0)
127
128 def scrape_many(self, hashes):
129 import urllib.parse
130
131 query = "&".join("info_hash=" + urllib.parse.quote_from_bytes(h, safe="") for h in hashes)
132 return bdecode(self.tracker.get("/scrape?" + query))
133
134 def test_the_keys_come_back_in_order(self):
135 answer = self.scrape_many(self.hashes)
136 self.assertEqual(list(answer[b"files"]), sorted(self.hashes))
137
138 def test_reversing_the_question_does_not_reverse_the_answer(self):
139 self.assertEqual(
140 list(self.scrape_many(self.hashes[::-1])[b"files"]), list(self.scrape_many(self.hashes)[b"files"])
141 )
142
143 def test_a_hash_asked_for_twice_is_named_once(self):
144 asked = [self.hashes[0], self.hashes[1], self.hashes[0]]
145 answer = self.scrape_many(asked)
146 self.assertEqual(list(answer[b"files"]), sorted({self.hashes[0], self.hashes[1]}))