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.trial import unittest
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet import defer from twisted.internet import defer
from testtools.twistedsupport import succeeded
from ..common import (
SyncTestCase,
AsyncTestCase,
)
from foolscap.api import ( from foolscap.api import (
fireEventually, fireEventually,
@ -53,6 +59,10 @@ from ..common_web import (
render, render,
) )
from testtools.matchers import (
Equals
)
@defer.inlineCallbacks @defer.inlineCallbacks
def create_introducer_webish(reactor, port_assigner, basedir): def create_introducer_webish(reactor, port_assigner, basedir):
@ -86,11 +96,10 @@ def create_introducer_webish(reactor, port_assigner, basedir):
yield fireEventually(None) yield fireEventually(None)
intro_node.startService() intro_node.startService()
defer.returnValue((intro_node, ws)) defer.returnValue((intro_node, ws))
class IntroducerWeb(unittest.TestCase): class IntroducerWeb(AsyncTestCase):
""" """
Tests for web-facing functionality of an introducer node. 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 # Anything using Foolscap leaves some timer trash in the reactor that
# we have to arrange to have cleaned up. # we have to arrange to have cleaned up.
self.addCleanup(lambda: flushEventualQueue(None)) self.addCleanup(lambda: flushEventualQueue(None))
return super(IntroducerWeb, self).setUp()
@defer.inlineCallbacks @defer.inlineCallbacks
def test_welcome(self): def test_welcome(self):
@ -187,7 +198,7 @@ class IntroducerWeb(unittest.TestCase):
self.assertEqual(data["announcement_summary"], {}) self.assertEqual(data["announcement_summary"], {})
class IntroducerRootTests(unittest.TestCase): class IntroducerRootTests(SyncTestCase):
""" """
Tests for ``IntroducerRoot``. Tests for ``IntroducerRoot``.
""" """
@ -222,16 +233,12 @@ class IntroducerRootTests(unittest.TestCase):
0, 0,
) )
resource = IntroducerRoot(introducer_node) resource = IntroducerRoot(introducer_node)
response = json.loads( response = json.loads(succeeded(
self.successResultOf(
render(resource, {b"t": [b"json"]}), render(resource, {b"t": [b"json"]}),
), )._matcher.result)
) deferred = defer.succeed({
self.assertEqual(
response,
{
u"subscription_summary": {"arbitrary": 2}, u"subscription_summary": {"arbitrary": 2},
u"announcement_summary": {"arbitrary": 1}, u"announcement_summary": {"arbitrary": 1},
}, })
) self.assertThat(deferred.result, Equals(response))