コード例 #1
0
def test_non_active():
    data = {
        "id": 1,
        "activityDate": 0,
    }

    torrent = transmission_rpc.Torrent(None, data)
    assert torrent.date_active
コード例 #2
0
 def testUnicode(self):
     torrent = transmission_rpc.Torrent(None, {'id': 42, 'name': 'あみ'})
     self.assertEqual(torrent.id, 42)
     repr(torrent)
     str(torrent)
コード例 #3
0
    def testAttributes(self):
        torrent = transmission_rpc.Torrent(None, {'id': 42})
        self.assertTrue(hasattr(torrent, 'id'))
        self.assertEqual(torrent.id, 42)
        self.assertPropertyException(KeyError, torrent, 'status')
        self.assertPropertyException(KeyError, torrent, 'progress')
        self.assertPropertyException(KeyError, torrent, 'ratio')
        self.assertPropertyException(KeyError, torrent, 'eta')
        self.assertPropertyException(KeyError, torrent, 'date_active')
        self.assertPropertyException(KeyError, torrent, 'date_added')
        self.assertPropertyException(KeyError, torrent, 'date_started')
        self.assertPropertyException(KeyError, torrent, 'date_done')

        self.assertRaises(KeyError, torrent.format_eta)
        self.assertEqual(torrent.files(), {})

        data = {
            'id': 1,
            'status': 4,
            'sizeWhenDone': 1000,
            'leftUntilDone': 500,
            'uploadedEver': 1000,
            'downloadedEver': 2000,
            'uploadRatio': 0.5,
            'eta': 3600,
            'activityDate': time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
            'addedDate': time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
            'startDate': time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
            'doneDate': time.mktime((2008, 12, 11, 10, 0, 15, 0, 0, -1)),
        }

        torrent = transmission_rpc.Torrent(None, data)
        self.assertEqual(torrent.id, 1)
        self.assertEqual(torrent.leftUntilDone, 500)
        self.assertEqual(torrent.status, 'downloading')
        self.assertEqual(torrent.progress, 50.0)
        self.assertEqual(torrent.ratio, 0.5)
        self.assertEqual(torrent.eta, datetime.timedelta(seconds=3600))
        self.assertEqual(torrent.date_active,
                         datetime.datetime(2008, 12, 11, 11, 15, 30))
        self.assertEqual(torrent.date_added,
                         datetime.datetime(2008, 12, 11, 8, 5, 10))
        self.assertEqual(torrent.date_started,
                         datetime.datetime(2008, 12, 11, 9, 10, 5))
        self.assertEqual(torrent.date_done,
                         datetime.datetime(2008, 12, 11, 10, 0, 15))

        self.assertEqual(torrent.format_eta(),
                         transmission_rpc.utils.format_timedelta(torrent.eta))

        torrent = transmission_rpc.Torrent(None, {'id': 42, 'eta': -1})
        self.assertPropertyException(ValueError, torrent, 'eta')

        data = {
            'id': 1,
            'status': 4,
            'sizeWhenDone': 1000,
            'leftUntilDone': 500,
            'uploadedEver': 1000,
            'downloadedEver': 2000,
            'uploadRatio': 0.5,
            'eta': 3600,
            'activityDate': time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
            'addedDate': time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
            'startDate': time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
            'doneDate': 0,
        }

        torrent = transmission_rpc.Torrent(None, data)
        self.assertEqual(torrent.date_done, None)
コード例 #4
0
 def testConstruction(self):
     self.failUnlessRaises(ValueError, transmission_rpc.Torrent, None, {})
     transmission_rpc.Torrent(None, {'id': 42})
コード例 #5
0
def test_attributes():
    torrent = transmission_rpc.Torrent(None, {"id": 42})
    assert hasattr(torrent, "id")
    assert torrent.id == 42
    assert_property_exception(KeyError, torrent, "status")
    assert_property_exception(KeyError, torrent, "progress")
    assert_property_exception(KeyError, torrent, "ratio")
    assert_property_exception(KeyError, torrent, "eta")
    assert_property_exception(KeyError, torrent, "date_active")
    assert_property_exception(KeyError, torrent, "date_added")
    assert_property_exception(KeyError, torrent, "date_started")
    assert_property_exception(KeyError, torrent, "date_done")

    with pytest.raises(KeyError):
        torrent.format_eta()
    assert torrent.files() == []

    data = {
        "id": 1,
        "status": 4,
        "sizeWhenDone": 1000,
        "leftUntilDone": 500,
        "uploadedEver": 1000,
        "downloadedEver": 2000,
        "uploadRatio": 0.5,
        "eta": 3600,
        "activityDate": time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
        "addedDate": time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
        "startDate": time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
        "doneDate": time.mktime((2008, 12, 11, 10, 0, 15, 0, 0, -1)),
    }

    torrent = transmission_rpc.Torrent(None, data)
    assert torrent.id == 1
    assert torrent.leftUntilDone == 500
    assert torrent.status == "downloading"
    assert torrent.progress == 50.0
    assert torrent.ratio == 0.5
    assert torrent.eta == datetime.timedelta(seconds=3600)
    assert torrent.date_active == datetime.datetime(2008, 12, 11, 11, 15, 30)
    assert torrent.date_added == datetime.datetime(2008, 12, 11, 8, 5, 10)
    assert torrent.date_started == datetime.datetime(2008, 12, 11, 9, 10, 5)
    assert torrent.date_done == datetime.datetime(2008, 12, 11, 10, 0, 15)

    assert torrent.format_eta() == transmission_rpc.utils.format_timedelta(
        torrent.eta)

    torrent = transmission_rpc.Torrent(None, {"id": 42, "eta": -1})
    assert_property_exception(ValueError, torrent, "eta")

    data = {
        "id": 1,
        "status": 4,
        "sizeWhenDone": 1000,
        "leftUntilDone": 500,
        "uploadedEver": 1000,
        "downloadedEver": 2000,
        "uploadRatio": 0.5,
        "eta": 3600,
        "activityDate": time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
        "addedDate": time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
        "startDate": time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
        "doneDate": 0,
    }

    torrent = transmission_rpc.Torrent(None, data)
    assert torrent.date_done is None
コード例 #6
0
def test_get_name_string():
    torrent = transmission_rpc.Torrent(None, {"id": 42, "name": "we"})
    name = torrent._get_name_string()
    assert isinstance(name, str)
コード例 #7
0
def test_initial():
    with pytest.raises(ValueError):
        transmission_rpc.Torrent(None, {})
    transmission_rpc.Torrent(None, {"id": 42})
コード例 #8
0
def test_initial():
    with pytest.raises(ValueError, match="Torrent requires an id"):
        transmission_rpc.Torrent(None, {})
    transmission_rpc.Torrent(None, {"id": 42})
コード例 #9
0
def test_attributes():
    torrent = transmission_rpc.Torrent(None, {'id': 42})
    assert hasattr(torrent, 'id')
    assert torrent.id == 42
    assert_property_exception(KeyError, torrent, 'status')
    assert_property_exception(KeyError, torrent, 'progress')
    assert_property_exception(KeyError, torrent, 'ratio')
    assert_property_exception(KeyError, torrent, 'eta')
    assert_property_exception(KeyError, torrent, 'date_active')
    assert_property_exception(KeyError, torrent, 'date_added')
    assert_property_exception(KeyError, torrent, 'date_started')
    assert_property_exception(KeyError, torrent, 'date_done')

    with pytest.raises(KeyError):
        torrent.format_eta()
    assert torrent.files() == {}

    data = {
        'id': 1,
        'status': 4,
        'sizeWhenDone': 1000,
        'leftUntilDone': 500,
        'uploadedEver': 1000,
        'downloadedEver': 2000,
        'uploadRatio': 0.5,
        'eta': 3600,
        'activityDate': time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
        'addedDate': time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
        'startDate': time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
        'doneDate': time.mktime((2008, 12, 11, 10, 0, 15, 0, 0, -1)),
    }

    torrent = transmission_rpc.Torrent(None, data)
    assert torrent.id == 1
    assert torrent.leftUntilDone == 500
    assert torrent.status == 'downloading'
    assert torrent.progress == 50.0
    assert torrent.ratio == 0.5
    assert torrent.eta == datetime.timedelta(seconds=3600)
    assert torrent.date_active == datetime.datetime(2008, 12, 11, 11, 15, 30)
    assert torrent.date_added == datetime.datetime(2008, 12, 11, 8, 5, 10)
    assert torrent.date_started == datetime.datetime(2008, 12, 11, 9, 10, 5)
    assert torrent.date_done == datetime.datetime(2008, 12, 11, 10, 0, 15)

    assert torrent.format_eta() == transmission_rpc.utils.format_timedelta(
        torrent.eta)

    torrent = transmission_rpc.Torrent(None, {'id': 42, 'eta': -1})
    assert_property_exception(ValueError, torrent, 'eta')

    data = {
        'id': 1,
        'status': 4,
        'sizeWhenDone': 1000,
        'leftUntilDone': 500,
        'uploadedEver': 1000,
        'downloadedEver': 2000,
        'uploadRatio': 0.5,
        'eta': 3600,
        'activityDate': time.mktime((2008, 12, 11, 11, 15, 30, 0, 0, -1)),
        'addedDate': time.mktime((2008, 12, 11, 8, 5, 10, 0, 0, -1)),
        'startDate': time.mktime((2008, 12, 11, 9, 10, 5, 0, 0, -1)),
        'doneDate': 0,
    }

    torrent = transmission_rpc.Torrent(None, data)
    assert torrent.date_done is None