Пример #1
0
    def test_index_plaintext(self, urlopen_mock):
        urlopen_mock.return_value = io.BytesIO(EXAMPLE_INDEX_JSON)

        collector = CollecTor()
        self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.PLAINTEXT))
        urlopen_mock.assert_called_with(
            'https://collector.torproject.org/index/index.json', timeout=None)
Пример #2
0
    def _test_index(self, compression):
        if compression and not compression.available:
            self.skipTest('(%s unavailable)' % compression)

        collector = stem.descriptor.collector.CollecTor()
        index = collector.index(compression=compression)

        self.assertEqual('https://collector.torproject.org', index['path'])
        self.assertEqual(['archive', 'recent'],
                         [entry['path'] for entry in index['directories']])
Пример #3
0
    def test_index_bz2(self, urlopen_mock):
        if not Compression.BZ2.available:
            self.skipTest('(bz2 compression unavailable)')

        import bz2
        urlopen_mock.return_value = io.BytesIO(
            bz2.compress(EXAMPLE_INDEX_JSON))

        collector = CollecTor()
        self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.BZ2))
        urlopen_mock.assert_called_with(
            'https://collector.torproject.org/index/index.json.bz2',
            timeout=None)
Пример #4
0
    def test_index_gzip(self, urlopen_mock):
        if not Compression.GZIP.available:
            self.skipTest('(gzip compression unavailable)')

        import zlib
        urlopen_mock.return_value = io.BytesIO(
            zlib.compress(EXAMPLE_INDEX_JSON))

        collector = CollecTor()
        self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.GZIP))
        urlopen_mock.assert_called_with(
            'https://collector.torproject.org/index/index.json.gz',
            timeout=None)