Ejemplo n.º 1
0
    def test_source_with_invalid_type_hint(self):
        src = build_source('foo')  # build_source doesnt do parse
        src.hints = {'type': 'other'}

        asrc = analyze(src, mp=False)[0]

        self.assertTrue(isinstance(asrc.entity, Movie))
Ejemplo n.º 2
0
    def test_add(self):
        s1 = build_source('foo')

        self.downloads.add(s1)
        self.wait()

        self.assertEqual(self.downloads.get_active(), [s1])
Ejemplo n.º 3
0
 def test_id_b64_normalization(self):
     src = build_source(
         "foo",
         uri="magnet:?dn=foo&xt=urn:btih:BPXMPNPKH4H5XSK5BXKH6PC3YJ25VCRT",  # noqa
     )
     self.assertEqual(
         src.id, "urn:btih:0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"  # noqa
     )
Ejemplo n.º 4
0
 def test_id_case_normalization(self):
     src = build_source(
         "foo",
         uri="magnet:?dn=foo&xt=urn:btih:0BEEC7B5EA3F0FDBC95D0DD47F3C5BC275DA8A33",  # noqa
     )
     self.assertEqual(
         src.id, "urn:btih:0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"  # noqa
     )
Ejemplo n.º 5
0
    def test_unexpected_download_from_plugin(self):
        src1 = build_source('foo')
        src2 = build_source('bar')

        self.downloads.add(src1)
        self.wait()

        fake_dump = [{
            'id': self.srvs.db.downloads.external_for_source(src1),
            'state': State.DOWNLOADING
        }, {
            'id': 'external-added-id',
            'state': State.DOWNLOADING
        }]
        with mock.patch.object(self.downloads.downloader.__class__,
                               'dump',
                               return_value=fake_dump):
            self.assertEqual(self.downloads.get_active(), [src1])
Ejemplo n.º 6
0
    def test_archive(self):
        src1 = build_source('foo')

        self.downloads.add(src1)
        self.wait()

        self.downloads.archive(src1)
        self.wait()

        self.assertEqual(self.downloads.get_state(src1), State.ARCHIVED)

        self.assertEqual(self.downloads.get_active(), [])
Ejemplo n.º 7
0
    def test_add_duplicated(self):
        src1 = build_source('foo')

        self.downloads.add(src1)
        self.wait()

        self.downloads.add(src1)
        self.wait()

        self.assertNotEqual(self.downloads.get_state(src1), None)

        self.assertEqual(self.downloads.get_active(), [src1])
Ejemplo n.º 8
0
    def test_handle_unexpected_remove_from_plugin_as_archive(self):
        src1 = build_source('foo')
        src2 = build_source('bar')

        self.downloads.add(src1)
        self.downloads.add(src2)
        self.wait()

        # Manually update state of src2
        self.srvs.db.downloads.set_state(src2, State.SHARING)

        # Mock plugin list to not list src2
        fake_dump = [{
            'id': self.srvs.db.downloads.external_for_source(src1),
            'state': State.DOWNLOADING
        }]

        with mock.patch.object(self.downloads.downloader.__class__,
                               'dump',
                               return_value=fake_dump):
            self.assertEqual(self.downloads.get_state(src2), State.ARCHIVED)
Ejemplo n.º 9
0
    def test_cancel(self):
        src1 = build_source('foo')

        self.downloads.add(src1)
        self.wait()

        self.downloads.cancel(src1)
        self.wait()

        with self.assertRaises(NotFoundError):
            self.downloads.get_state(src1)

        self.assertEqual(self.downloads.get_active(), [])
Ejemplo n.º 10
0
    def test_handle_unexpected_remove_from_plugin_as_cancel(self):
        src1 = build_source('foo')
        src2 = build_source('bar')

        self.downloads.add(src1)
        self.downloads.add(src2)
        self.wait()

        fake_dump = [
            {
                'id': self.srvs.db.downloads.external_for_source(src1),
                'state': State.DOWNLOADING
            },
        ]
        with mock.patch.object(self.downloads.downloader.__class__,
                               'dump',
                               return_value=fake_dump):

            self.assertEqual(self.downloads.get_active(), [src1])

            with self.assertRaises(NotFoundError):
                self.downloads.get_state(src2)
Ejemplo n.º 11
0
 def test_urn_as_id(self):
     src = build_source("foo")
     self.assertEqual(
         src.id, "urn:btih:0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"   # noqa
     )
Ejemplo n.º 12
0
 def test_invalid_urn(self):
     with self.assertRaises(ValueError):
         build_source("foo", uri="magnet:?dn=foo&xt=urn:btih:invalid")
Ejemplo n.º 13
0
    def test_archive_unknown_source(self):
        # This test fails if the name is foo. ¿?
        src1 = build_source('foo')

        with self.assertRaises(NotFoundError):
            self.downloads.archive(src1)
Ejemplo n.º 14
0
    def test_remove_unknown_source(self):
        src1 = build_source('foo')

        with self.assertRaises(NotFoundError):
            self.downloads.cancel(src1)