mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-01 00:45:52 +00:00
move some testing helpers into the common module
This commit is contained in:
parent
3b6e1e344b
commit
e8b38d8cd6
@ -26,6 +26,8 @@ from errno import (
|
||||
EADDRINUSE,
|
||||
)
|
||||
|
||||
import attr
|
||||
|
||||
import treq
|
||||
|
||||
from zope.interface import implementer
|
||||
@ -73,6 +75,9 @@ from allmydata.util.consumer import download_to_data
|
||||
import allmydata.test.common_util as testutil
|
||||
from allmydata.immutable.upload import Uploader
|
||||
|
||||
from ..crypto import (
|
||||
ed25519,
|
||||
)
|
||||
from .eliotutil import (
|
||||
EliotLoggedRunTest,
|
||||
)
|
||||
@ -81,6 +86,83 @@ from .eliotutil import (
|
||||
TEST_RSA_KEY_SIZE = 522
|
||||
|
||||
|
||||
@attr.s
|
||||
class MemoryIntroducerClient(object):
|
||||
"""
|
||||
A model-only (no behavior) stand-in for ``IntroducerClient``.
|
||||
"""
|
||||
tub = attr.ib()
|
||||
introducer_furl = attr.ib()
|
||||
nickname = attr.ib()
|
||||
my_version = attr.ib()
|
||||
oldest_supported = attr.ib()
|
||||
app_versions = attr.ib()
|
||||
sequencer = attr.ib()
|
||||
cache_filepath = attr.ib()
|
||||
|
||||
subscribed_to = attr.ib(default=attr.Factory(list))
|
||||
published_announcements = attr.ib(default=attr.Factory(list))
|
||||
|
||||
|
||||
def setServiceParent(self, parent):
|
||||
pass
|
||||
|
||||
|
||||
def subscribe_to(self, service_name, cb, *args, **kwargs):
|
||||
self.subscribed_to.append(Subscription(service_name, cb, args, kwargs))
|
||||
|
||||
|
||||
def publish(self, service_name, ann, signing_key):
|
||||
self.published_announcements.append(Announcement(
|
||||
service_name,
|
||||
ann,
|
||||
ed25519.string_from_signing_key(signing_key),
|
||||
))
|
||||
|
||||
|
||||
|
||||
@attr.s
|
||||
class Subscription(object):
|
||||
"""
|
||||
A model of an introducer subscription.
|
||||
"""
|
||||
service_name = attr.ib()
|
||||
cb = attr.ib()
|
||||
args = attr.ib()
|
||||
kwargs = attr.ib()
|
||||
|
||||
|
||||
|
||||
@attr.s
|
||||
class Announcement(object):
|
||||
"""
|
||||
A model of an introducer announcement.
|
||||
"""
|
||||
service_name = attr.ib()
|
||||
ann = attr.ib()
|
||||
signing_key_bytes = attr.ib(type=bytes)
|
||||
|
||||
@property
|
||||
def signing_key(self):
|
||||
return ed25519.signing_keypair_from_string(self.signing_key_bytes)[0]
|
||||
|
||||
|
||||
|
||||
def get_published_announcements(client):
|
||||
"""
|
||||
Get a flattened list of all announcements sent using all introducer
|
||||
clients.
|
||||
"""
|
||||
return list(
|
||||
announcement
|
||||
for introducer_client
|
||||
in client.introducer_clients
|
||||
for announcement
|
||||
in introducer_client.published_announcements
|
||||
)
|
||||
|
||||
|
||||
|
||||
class UseTestPlugins(object):
|
||||
"""
|
||||
A fixture which enables loading Twisted plugins from the Tahoe-LAFS test
|
||||
|
@ -3,7 +3,6 @@ import mock
|
||||
from functools import (
|
||||
partial,
|
||||
)
|
||||
import attr
|
||||
|
||||
import twisted
|
||||
from yaml import (
|
||||
@ -56,6 +55,8 @@ import allmydata.test.common_util as testutil
|
||||
from .common import (
|
||||
SyncTestCase,
|
||||
UseTestPlugins,
|
||||
MemoryIntroducerClient,
|
||||
get_published_announcements,
|
||||
)
|
||||
from .matchers import (
|
||||
MatchesSameElements,
|
||||
@ -1000,80 +1001,6 @@ class NodeMaker(testutil.ReallyEqualMixin, unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
@attr.s
|
||||
class MemoryIntroducerClient(object):
|
||||
"""
|
||||
A model-only (no behavior) stand-in for ``IntroducerClient``.
|
||||
"""
|
||||
tub = attr.ib()
|
||||
introducer_furl = attr.ib()
|
||||
nickname = attr.ib()
|
||||
my_version = attr.ib()
|
||||
oldest_supported = attr.ib()
|
||||
app_versions = attr.ib()
|
||||
sequencer = attr.ib()
|
||||
cache_filepath = attr.ib()
|
||||
|
||||
subscribed_to = attr.ib(default=attr.Factory(list))
|
||||
published_announcements = attr.ib(default=attr.Factory(list))
|
||||
|
||||
|
||||
def setServiceParent(self, parent):
|
||||
pass
|
||||
|
||||
|
||||
def subscribe_to(self, service_name, cb, *args, **kwargs):
|
||||
self.subscribed_to.append(Subscription(service_name, cb, args, kwargs))
|
||||
|
||||
|
||||
def publish(self, service_name, ann, signing_key):
|
||||
self.published_announcements.append(Announcement(service_name, ann, signing_key))
|
||||
|
||||
|
||||
|
||||
@attr.s
|
||||
class Subscription(object):
|
||||
"""
|
||||
A model of an introducer subscription.
|
||||
"""
|
||||
service_name = attr.ib()
|
||||
cb = attr.ib()
|
||||
args = attr.ib()
|
||||
kwargs = attr.ib()
|
||||
|
||||
|
||||
|
||||
@attr.s
|
||||
class Announcement(object):
|
||||
"""
|
||||
A model of an introducer announcement.
|
||||
"""
|
||||
service_name = attr.ib()
|
||||
ann = attr.ib()
|
||||
signing_key = attr.ib()
|
||||
|
||||
|
||||
|
||||
def get_published_announcements(client):
|
||||
"""
|
||||
Get a flattened list of the latest announcements sent using all introducer
|
||||
clients.
|
||||
|
||||
Only the most recent announcement for any particular service name is acted
|
||||
on so these are the only announcements returned.
|
||||
"""
|
||||
return {
|
||||
announcement.service_name: announcement
|
||||
for introducer_client
|
||||
in client.introducer_clients
|
||||
# Visit the announcements in the order they were sent. The last one
|
||||
# will win in the dictionary we construct.
|
||||
for announcement
|
||||
in introducer_client.published_announcements
|
||||
}.values()
|
||||
|
||||
|
||||
|
||||
def matches_dummy_announcement(name, value):
|
||||
"""
|
||||
Matches the portion of an announcement for the ``DummyStorage`` storage
|
||||
|
Loading…
x
Reference in New Issue
Block a user