Fixes 3757 : Refactored test_introducer in web tests to use custom base test cases

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
This commit is contained in:
fenn-cs 2021-08-08 21:49:02 +01:00
parent 93fbfb61a8
commit 90e84730e5
2 changed files with 20 additions and 13 deletions

0
newsfragments/3757.other Normal file
View File

View File

@ -18,6 +18,12 @@ 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,
@ -53,6 +59,10 @@ from ..common_web import (
render,
)
from testtools.matchers import (
Equals
)
@defer.inlineCallbacks
def create_introducer_webish(reactor, port_assigner, basedir):
@ -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.
"""
@ -102,6 +111,8 @@ class IntroducerWeb(unittest.TestCase):
# 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):
@ -187,7 +198,7 @@ class IntroducerWeb(unittest.TestCase):
self.assertEqual(data["announcement_summary"], {})
class IntroducerRootTests(unittest.TestCase):
class IntroducerRootTests(SyncTestCase):
"""
Tests for ``IntroducerRoot``.
"""
@ -222,16 +233,12 @@ class IntroducerRootTests(unittest.TestCase):
0,
)
resource = IntroducerRoot(introducer_node)
response = json.loads(
self.successResultOf(
resource = IntroducerRoot(introducer_node)
response = json.loads(succeeded(
render(resource, {b"t": [b"json"]}),
),
)
self.assertEqual(
response,
{
)._matcher.result)
deferred = defer.succeed({
u"subscription_summary": {"arbitrary": 2},
u"announcement_summary": {"arbitrary": 1},
},
)
})
self.assertThat(deferred.result, Equals(response))