From b604d08463982362dcaed698c75bd592bba97a6f Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 12 Jun 2019 16:47:25 -0400 Subject: [PATCH] Add a test for the success case --- src/allmydata/client.py | 5 ++- src/allmydata/test/test_client.py | 59 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 2333a35b7..8f426b312 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -8,7 +8,6 @@ from twisted.internet import reactor, defer from twisted.application import service from twisted.application.internet import TimerService from twisted.python.filepath import FilePath -from twisted.python.failure import Failure from pycryptopp.publickey import rsa import allmydata @@ -207,7 +206,7 @@ def create_client(basedir=u".", _client_factory=None): _client_factory=_client_factory, ) except Exception: - return Failure() + return defer.fail() def create_client_from_config(config, _client_factory=None): @@ -261,7 +260,7 @@ def create_client_from_config(config, _client_factory=None): storage_broker.setServiceParent(client) return defer.succeed(client) except Exception: - return Failure() + return defer.fail() def _sequencer(config): diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index 1d0fa085c..0fd35353e 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -1,9 +1,22 @@ import os, sys import mock import twisted +from yaml import ( + safe_dump, +) from twisted.trial import unittest from twisted.application import service from twisted.internet import defer +from twisted.python.filepath import ( + FilePath, +) +from testtools.matchers import ( + Equals, + AfterPreprocessing, +) +from testtools.twistedsupport import ( + succeeded, +) import allmydata import allmydata.frontends.magic_folder @@ -20,6 +33,9 @@ from allmydata.interfaces import IFilesystemNode, IFileNode, \ IImmutableFileNode, IMutableFileNode, IDirectoryNode from foolscap.api import flushEventualQueue import allmydata.test.common_util as testutil +from allmydata.test.common import ( + SyncTestCase, +) BASECONFIG = ("[client]\n" @@ -666,6 +682,49 @@ class IntroducerClients(unittest.TestCase): ) +class StorageClients(SyncTestCase): + """ + Tests for storage-related behavior of ``_Client``. + """ + def test_static_servers(self): + """ + Storage servers defined in ``private/servers.yaml`` are loaded into the + storage broker. + """ + serverid = u"v0-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + announcement = { + u"nickname": 'some-storage-server', + u"anonymous-storage-FURL": u"pb://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@tcp:storage.example:100/swissnum", + } + basedir = FilePath(self.mktemp()) + private = basedir.child(u"private") + private.makedirs() + servers = private.child(u"servers.yaml") + servers.setContent(safe_dump({ + u"storage": { + serverid: { + u"ann": announcement, + }, + }, + })) + def get_known_server_details(a_client): + return list( + (s.get_serverid(), s.get_announcement()) + for s + in a_client.storage_broker.get_known_servers() + ) + self.assertThat( + client.create_client(basedir.asTextMode().path), + succeeded( + AfterPreprocessing( + get_known_server_details, + Equals([(serverid, announcement)]), + ), + ), + ) + + + class Run(unittest.TestCase, testutil.StallMixin): def setUp(self):