From 90e84730e57e8cba179889c4242a34452d6a064e Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Sun, 8 Aug 2021 21:49:02 +0100 Subject: [PATCH 1/4] Fixes 3757 : Refactored test_introducer in web tests to use custom base test cases Signed-off-by: fenn-cs --- newsfragments/3757.other | 0 src/allmydata/test/web/test_introducer.py | 33 ++++++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 newsfragments/3757.other diff --git a/newsfragments/3757.other b/newsfragments/3757.other new file mode 100644 index 000000000..e69de29bb diff --git a/src/allmydata/test/web/test_introducer.py b/src/allmydata/test/web/test_introducer.py index 08d95bda9..34b1088e3 100644 --- a/src/allmydata/test/web/test_introducer.py +++ b/src/allmydata/test/web/test_introducer.py @@ -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)) From 7ad3fa9e25975eb749345af7ea9745dfe166f7e7 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Mon, 9 Aug 2021 23:46:30 +0100 Subject: [PATCH 2/4] correct use of succeeded, remove trailing spaces and unused import Signed-off-by: fenn-cs --- src/allmydata/test/web/test_introducer.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/allmydata/test/web/test_introducer.py b/src/allmydata/test/web/test_introducer.py index 34b1088e3..b1bc69f17 100644 --- a/src/allmydata/test/web/test_introducer.py +++ b/src/allmydata/test/web/test_introducer.py @@ -15,7 +15,6 @@ from os.path import join from bs4 import BeautifulSoup -from twisted.trial import unittest from twisted.internet import reactor from twisted.internet import defer from testtools.twistedsupport import succeeded @@ -60,7 +59,8 @@ from ..common_web import ( ) from testtools.matchers import ( - Equals + Equals, + AfterPreprocessing, ) @@ -112,7 +112,6 @@ class IntroducerWeb(AsyncTestCase): # we have to arrange to have cleaned up. self.addCleanup(lambda: flushEventualQueue(None)) return super(IntroducerWeb, self).setUp() - @defer.inlineCallbacks def test_welcome(self): @@ -233,12 +232,10 @@ class IntroducerRootTests(SyncTestCase): 0, ) - resource = IntroducerRoot(introducer_node) - response = json.loads(succeeded( - render(resource, {b"t": [b"json"]}), - )._matcher.result) - deferred = defer.succeed({ - u"subscription_summary": {"arbitrary": 2}, - u"announcement_summary": {"arbitrary": 1}, - }) - self.assertThat(deferred.result, Equals(response)) + resource = IntroducerRoot(introducer_node) + response = render(resource, {b"t": [b"json"]}) + expected = { + u"subscription_summary": {"arbitrary": 2}, + u"announcement_summary": {"arbitrary": 1}, + } + self.assertThat(response, succeeded(AfterPreprocessing(json.loads, Equals(expected))) From a6b7c07e1cbbfbc6f1aa00a33dd64e1c10159d97 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Tue, 10 Aug 2021 10:13:00 +0100 Subject: [PATCH 3/4] added missing parathensis, ran yapf Signed-off-by: fenn-cs --- src/allmydata/test/web/test_introducer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/web/test_introducer.py b/src/allmydata/test/web/test_introducer.py index b1bc69f17..ba0a5beb9 100644 --- a/src/allmydata/test/web/test_introducer.py +++ b/src/allmydata/test/web/test_introducer.py @@ -238,4 +238,6 @@ class IntroducerRootTests(SyncTestCase): u"subscription_summary": {"arbitrary": 2}, u"announcement_summary": {"arbitrary": 1}, } - self.assertThat(response, succeeded(AfterPreprocessing(json.loads, Equals(expected))) + self.assertThat( + response, + succeeded(AfterPreprocessing(json.loads, Equals(expected)))) From 78a3ca52c4b2eb0e891b4c50d7461eee46214486 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Tue, 10 Aug 2021 19:00:05 +0100 Subject: [PATCH 4/4] DUMMY COMMIT TO TRIGGER CI : added commit text to fragments Signed-off-by: fenn-cs --- newsfragments/3757.other | 1 + 1 file changed, 1 insertion(+) diff --git a/newsfragments/3757.other b/newsfragments/3757.other index e69de29bb..3d2d3f272 100644 --- a/newsfragments/3757.other +++ b/newsfragments/3757.other @@ -0,0 +1 @@ +Refactored test_introducer in web tests to use custom base test cases \ No newline at end of file