Skip to content

Commit

Permalink
Merge pull request #1100 from Fenn-CS/3757.refactor.web-test-introducer
Browse files Browse the repository at this point in the history
Refactor allmydata/test/web/test_introducer.py

Fixes: ticket:3757
  • Loading branch information
exarkun committed Aug 11, 2021
2 parents 22622b5 + b5c3290 commit 580af66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions newsfragments/3757.other
@@ -0,0 +1 @@
Refactored test_introducer in web tests to use custom base test cases
36 changes: 21 additions & 15 deletions src/allmydata/test/web/test_introducer.py
Expand Up @@ -15,9 +15,14 @@

from bs4 import BeautifulSoup

from twisted.trial import unittest
from twisted.internet import reactor
from twisted.internet import defer
from testtools.twistedsupport import succeeded

from ..common import (
SyncTestCase,
AsyncTestCase,
)

from foolscap.api import (
fireEventually,
Expand Down Expand Up @@ -53,6 +58,11 @@
render,
)

from testtools.matchers import (
Equals,
AfterPreprocessing,
)


@defer.inlineCallbacks
def create_introducer_webish(reactor, port_assigner, basedir):
Expand Down Expand Up @@ -86,11 +96,10 @@ def create_introducer_webish(reactor, port_assigner, basedir):

yield fireEventually(None)
intro_node.startService()

defer.returnValue((intro_node, ws))


class IntroducerWeb(unittest.TestCase):
class IntroducerWeb(AsyncTestCase):
"""
Tests for web-facing functionality of an introducer node.
"""
Expand All @@ -102,6 +111,7 @@ def setUp(self):
# Anything using Foolscap leaves some timer trash in the reactor that
# we have to arrange to have cleaned up.
self.addCleanup(lambda: flushEventualQueue(None))
return super(IntroducerWeb, self).setUp()

@defer.inlineCallbacks
def test_welcome(self):
Expand Down Expand Up @@ -187,7 +197,7 @@ def test_json_front_page(self):
self.assertEqual(data["announcement_summary"], {})


class IntroducerRootTests(unittest.TestCase):
class IntroducerRootTests(SyncTestCase):
"""
Tests for ``IntroducerRoot``.
"""
Expand Down Expand Up @@ -223,15 +233,11 @@ def test_json(self):
)

resource = IntroducerRoot(introducer_node)
response = json.loads(
self.successResultOf(
render(resource, {b"t": [b"json"]}),
),
)
self.assertEqual(
response = render(resource, {b"t": [b"json"]})
expected = {
u"subscription_summary": {"arbitrary": 2},
u"announcement_summary": {"arbitrary": 1},
}
self.assertThat(
response,
{
u"subscription_summary": {"arbitrary": 2},
u"announcement_summary": {"arbitrary": 1},
},
)
succeeded(AfterPreprocessing(json.loads, Equals(expected))))

0 comments on commit 580af66

Please sign in to comment.