Changeset 451d79a in trunk


Ignore:
Timestamp:
2022-01-07T18:49:04Z (3 years ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
3a6f0c0a, db5c65e
Parents:
4cdbf7fb (diff), 96445329 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
meejah <meejah@…> (2022-01-07 18:49:04)
git-committer:
GitHub <noreply@…> (2022-01-07 18:49:04)
Message:

Merge pull request #1167 from meejah/3852.json-welcome-page

3852.json welcome page

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/test/web/test_root.py

    r4cdbf7fb r451d79a  
    1212
    1313import time
     14import json
    1415
    1516from urllib.parse import (
     
    2526from twisted.application import service
    2627from testtools.twistedsupport import succeeded
    27 from twisted.internet.defer import inlineCallbacks
     28from twisted.internet.defer import (
     29    inlineCallbacks,
     30    succeed,
     31)
    2832
    2933from ...storage_client import (
     
    3135    StorageFarmBroker,
    3236)
    33 from ...web.root import RootElement
     37from ...web.root import (
     38    RootElement,
     39    Root,
     40)
    3441from ...util.connection_status import ConnectionStatus
     42from ...crypto.ed25519 import (
     43    create_signing_keypair,
     44)
    3545from allmydata.web.root import URIHandler
    3646from allmydata.client import _Client
     
    4858from ..common import (
    4959    SyncTestCase,
     60    AsyncTestCase,
    5061)
    5162
     
    139150        self.assertThat(item.slotData.get("version"), Equals(""))
    140151        self.assertThat(item.slotData.get("nickname"), Equals(""))
     152
     153
     154class RenderRoot(AsyncTestCase):
     155
     156    @inlineCallbacks
     157    def test_root_json(self):
     158        """
     159        The 'welcome' / root page renders properly with ?t=json when some
     160        servers show None for available_space while others show a
     161        valid int
     162
     163        See also https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3852
     164        """
     165        ann = {
     166            "anonymous-storage-FURL": "pb://w2hqnbaa25yw4qgcvghl5psa3srpfgw3@tcp:127.0.0.1:51309/vucto2z4fxment3vfxbqecblbf6zyp6x",
     167            "permutation-seed-base32": "w2hqnbaa25yw4qgcvghl5psa3srpfgw3",
     168        }
     169        srv0 = NativeStorageServer(b"server_id0", ann, None, {}, EMPTY_CLIENT_CONFIG)
     170        srv0.get_connection_status = lambda: ConnectionStatus(False, "summary0", {}, 0, 0)
     171
     172        srv1 = NativeStorageServer(b"server_id1", ann, None, {}, EMPTY_CLIENT_CONFIG)
     173        srv1.get_connection_status = lambda: ConnectionStatus(False, "summary1", {}, 0, 0)
     174        # arrange for this server to have some valid available space
     175        srv1.get_available_space = lambda: 12345
     176
     177        class FakeClient(_Client):
     178            history = []
     179            stats_provider = object()
     180            nickname = ""
     181            nodeid = b"asdf"
     182            _node_public_key = create_signing_keypair()[1]
     183            introducer_clients = []
     184            helper = None
     185
     186            def __init__(self):
     187                service.MultiService.__init__(self)
     188                self.storage_broker = StorageFarmBroker(
     189                    permute_peers=True,
     190                    tub_maker=None,
     191                    node_config=EMPTY_CLIENT_CONFIG,
     192                )
     193                self.storage_broker.test_add_server(b"test-srv0", srv0)
     194                self.storage_broker.test_add_server(b"test-srv1", srv1)
     195
     196        root = Root(FakeClient(), now_fn=time.time)
     197
     198        lines = []
     199
     200        req = DummyRequest(b"")
     201        req.fields = {}
     202        req.args = {
     203            b"t": [b"json"],
     204        }
     205
     206        # for some reason, DummyRequest is already finished when we
     207        # try to add a notifyFinish handler, so override that
     208        # behavior.
     209
     210        def nop():
     211            return succeed(None)
     212        req.notifyFinish = nop
     213        req.write = lines.append
     214
     215        yield root.render(req)
     216
     217        raw_js = b"".join(lines).decode("utf8")
     218        js = json.loads(raw_js)
     219        servers = js["servers"]
     220        self.assertEquals(len(servers), 2)
     221        self.assertIn(
     222            {
     223                "connection_status": "summary0",
     224                "nodeid": "server_id0",
     225                "last_received_data": 0,
     226                "version": None,
     227                "available_space": None,
     228                "nickname": ""
     229            },
     230            servers
     231        )
     232        self.assertIn(
     233            {
     234                "connection_status": "summary1",
     235                "nodeid": "server_id1",
     236                "last_received_data": 0,
     237                "version": None,
     238                "available_space": 12345,
     239                "nickname": ""
     240            },
     241            servers
     242        )
  • TabularUnified src/allmydata/test/web/test_web.py

    r4cdbf7fb r451d79a  
    821821        d = self.GET("/?t=json")
    822822        def _check(res):
     823            """
     824            Check that the results are correct.
     825            We can't depend on the order of servers in the output
     826            """
    823827            decoded = json.loads(res)
    824             expected = {
    825                 u'introducers': {
    826                     u'statuses': [],
     828            self.assertEqual(decoded['introducers'], {u'statuses': []})
     829            actual_servers = decoded[u"servers"]
     830            self.assertEquals(len(actual_servers), 2)
     831            self.assertIn(
     832                {
     833                    u"nodeid": u'other_nodeid',
     834                    u'available_space': 123456,
     835                    u'connection_status': u'summary',
     836                    u'last_received_data': 30,
     837                    u'nickname': u'other_nickname \u263b',
     838                    u'version': u'1.0',
    827839                },
    828                 u'servers': sorted([
    829                     {u"nodeid": u'other_nodeid',
    830                      u'available_space': 123456,
    831                      u'connection_status': u'summary',
    832                      u'last_received_data': 30,
    833                      u'nickname': u'other_nickname \u263b',
    834                      u'version': u'1.0',
    835                     },
    836                     {u"nodeid": u'disconnected_nodeid',
    837                      u'available_space': 123456,
    838                      u'connection_status': u'summary',
    839                      u'last_received_data': 35,
    840                      u'nickname': u'disconnected_nickname \u263b',
    841                      u'version': u'1.0',
    842                     },
    843                 ], key=lambda o: sorted(o.items())),
    844             }
    845             self.assertEqual(expected, decoded)
     840                actual_servers
     841            )
     842            self.assertIn(
     843                {
     844                    u"nodeid": u'disconnected_nodeid',
     845                    u'available_space': 123456,
     846                    u'connection_status': u'summary',
     847                    u'last_received_data': 35,
     848                    u'nickname': u'disconnected_nickname \u263b',
     849                    u'version': u'1.0',
     850                },
     851                actual_servers
     852            )
     853
    846854        d.addCallback(_check)
    847855        return d
  • TabularUnified src/allmydata/web/root.py

    r4cdbf7fb r451d79a  
    298298        return json.dumps(result, indent=1) + "\n"
    299299
    300 
    301300    def _describe_known_servers(self, broker):
    302         return sorted(list(
     301        return list(
    303302            self._describe_server(server)
    304303            for server
    305304            in broker.get_known_servers()
    306         ), key=lambda o: sorted(o.items()))
    307 
     305        )
    308306
    309307    def _describe_server(self, server):
Note: See TracChangeset for help on using the changeset viewer.