mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-25 23:51:07 +00:00
Tests for rrefutil.
This commit is contained in:
parent
062740dc23
commit
6127fc8cc7
@ -17,12 +17,15 @@ import yaml
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
from twisted.internet import defer
|
||||||
|
from foolscap.api import Violation, RemoteException
|
||||||
|
|
||||||
from allmydata.util import idlib, mathutil
|
from allmydata.util import idlib, mathutil
|
||||||
from allmydata.util import fileutil
|
from allmydata.util import fileutil
|
||||||
from allmydata.util import jsonbytes
|
from allmydata.util import jsonbytes
|
||||||
from allmydata.util import pollmixin
|
from allmydata.util import pollmixin
|
||||||
from allmydata.util import yamlutil
|
from allmydata.util import yamlutil
|
||||||
|
from allmydata.util import rrefutil
|
||||||
from allmydata.util.fileutil import EncryptedTemporaryFile
|
from allmydata.util.fileutil import EncryptedTemporaryFile
|
||||||
from allmydata.test.common_util import ReallyEqualMixin
|
from allmydata.test.common_util import ReallyEqualMixin
|
||||||
|
|
||||||
@ -526,3 +529,39 @@ class JSONBytes(unittest.TestCase):
|
|||||||
encoded = jsonbytes.dumps_bytes(x)
|
encoded = jsonbytes.dumps_bytes(x)
|
||||||
self.assertIsInstance(encoded, bytes)
|
self.assertIsInstance(encoded, bytes)
|
||||||
self.assertEqual(json.loads(encoded, encoding="utf-8"), x)
|
self.assertEqual(json.loads(encoded, encoding="utf-8"), x)
|
||||||
|
|
||||||
|
|
||||||
|
class FakeRemoteRef(object):
|
||||||
|
"""Emulate a RemoteRef."""
|
||||||
|
|
||||||
|
def __init__(self, result):
|
||||||
|
self.result = result
|
||||||
|
|
||||||
|
def callRemote(self, method):
|
||||||
|
assert method == "get_version"
|
||||||
|
if isinstance(self.result, Exception):
|
||||||
|
return defer.fail(self.result)
|
||||||
|
return defer.succeed(self.result)
|
||||||
|
|
||||||
|
|
||||||
|
class RrefUtilTests(unittest.TestCase):
|
||||||
|
"""Tests for rrefutil."""
|
||||||
|
|
||||||
|
def test_version_returned(self):
|
||||||
|
"""If get_version() succeeded, it is set on the rref."""
|
||||||
|
rref = FakeRemoteRef(12345)
|
||||||
|
result = self.successResultOf(
|
||||||
|
rrefutil.add_version_to_remote_reference(rref, "default")
|
||||||
|
)
|
||||||
|
self.assertEqual(result.version, 12345)
|
||||||
|
self.assertIdentical(result, rref)
|
||||||
|
|
||||||
|
def test_exceptions(self):
|
||||||
|
"""If get_version() failed, default version is set on the rref."""
|
||||||
|
for exception in (Violation(), RemoteException(ValueError())):
|
||||||
|
rref = FakeRemoteRef(exception)
|
||||||
|
result = self.successResultOf(
|
||||||
|
rrefutil.add_version_to_remote_reference(rref, "Default")
|
||||||
|
)
|
||||||
|
self.assertEqual(result.version, "Default")
|
||||||
|
self.assertIdentical(result, rref)
|
||||||
|
Loading…
Reference in New Issue
Block a user