mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 20:22:45 +01:00
Fediverse: Lower timeout of networkless tests.
There are many calls to assertSnarfNoResponse, so there's a lot of time wasted sleeping, while these commands are fast enough to answer in less than 0.1s
This commit is contained in:
parent
dc2fe4d5f3
commit
27edb4f6c9
@ -58,7 +58,7 @@ from .test_data import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class FediverseTestCase(ChannelPluginTestCase):
|
class BaseFediverseTestCase(ChannelPluginTestCase):
|
||||||
config = {
|
config = {
|
||||||
# Allow snarfing the same URL twice in a row
|
# Allow snarfing the same URL twice in a row
|
||||||
"supybot.snarfThrottle": 0.0
|
"supybot.snarfThrottle": 0.0
|
||||||
@ -74,6 +74,25 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
with open(path, "wb") as fd:
|
with open(path, "wb") as fd:
|
||||||
fd.write(PRIVATE_KEY)
|
fd.write(PRIVATE_KEY)
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkedFediverseTestCase(BaseFediverseTestCase):
|
||||||
|
if network:
|
||||||
|
|
||||||
|
def testNetworkProfile(self):
|
||||||
|
self.assertRegexp("profile @val@oc.todon.fr", "0E082B40E4376B1E")
|
||||||
|
# TODO: add a test with an instance which only allows fetches
|
||||||
|
# with valid signatures.
|
||||||
|
|
||||||
|
def testNetworkProfileUnknown(self):
|
||||||
|
self.assertResponse(
|
||||||
|
"profile @nonexistinguser@oc.todon.fr",
|
||||||
|
"Error: Unknown user @nonexistinguser@oc.todon.fr.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
||||||
|
timeout = 0.1
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def mockRequests(self, expected_requests):
|
def mockRequests(self, expected_requests):
|
||||||
with Manager() as m:
|
with Manager() as m:
|
||||||
@ -105,19 +124,6 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
list(expected_requests), [], "Less requests than expected."
|
list(expected_requests), [], "Less requests than expected."
|
||||||
)
|
)
|
||||||
|
|
||||||
if network:
|
|
||||||
|
|
||||||
def testNetworkProfile(self):
|
|
||||||
self.assertRegexp("profile @val@oc.todon.fr", "0E082B40E4376B1E")
|
|
||||||
# TODO: add a test with an instance which only allows fetches
|
|
||||||
# with valid signatures.
|
|
||||||
|
|
||||||
def testNetworkProfileUnknown(self):
|
|
||||||
self.assertResponse(
|
|
||||||
"profile @nonexistinguser@oc.todon.fr",
|
|
||||||
"Error: Unknown user @nonexistinguser@oc.todon.fr.",
|
|
||||||
)
|
|
||||||
|
|
||||||
def testFeaturedNone(self):
|
def testFeaturedNone(self):
|
||||||
featured = {
|
featured = {
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
@ -220,9 +226,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
def testProfileSnarfer(self):
|
def testProfileSnarfer(self):
|
||||||
with self.mockRequests([]):
|
with self.mockRequests([]):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse("aaa @nonexistinguser@example.org bbb")
|
||||||
"aaa @nonexistinguser@example.org bbb", timeout=1
|
|
||||||
)
|
|
||||||
|
|
||||||
with conf.supybot.plugins.Fediverse.snarfers.username.context(True):
|
with conf.supybot.plugins.Fediverse.snarfers.username.context(True):
|
||||||
expected_requests = [
|
expected_requests = [
|
||||||
@ -244,13 +248,13 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
with self.mockRequests(expected_requests):
|
with self.mockRequests(expected_requests):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa @nonexistinguser@example.org bbb", timeout=1
|
"aaa @nonexistinguser@example.org bbb"
|
||||||
)
|
)
|
||||||
|
|
||||||
def testProfileUrlSnarfer(self):
|
def testProfileUrlSnarfer(self):
|
||||||
with self.mockRequests([]):
|
with self.mockRequests([]):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser bbb", timeout=1
|
"aaa https://example.org/users/someuser bbb"
|
||||||
)
|
)
|
||||||
|
|
||||||
with conf.supybot.plugins.Fediverse.snarfers.profile.context(True):
|
with conf.supybot.plugins.Fediverse.snarfers.profile.context(True):
|
||||||
@ -258,7 +262,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
with self.mockRequests(expected_requests):
|
with self.mockRequests(expected_requests):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser bbb", timeout=1
|
"aaa https://example.org/users/someuser bbb"
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_requests = [(ACTOR_URL, ACTOR_DATA)]
|
expected_requests = [(ACTOR_URL, ACTOR_DATA)]
|
||||||
@ -361,8 +365,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
def testStatusUrlSnarferDisabled(self):
|
def testStatusUrlSnarferDisabled(self):
|
||||||
with self.mockRequests([]):
|
with self.mockRequests([]):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser/statuses/1234 bbb",
|
"aaa https://example.org/users/someuser/statuses/1234 bbb"
|
||||||
timeout=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def testStatusUrlSnarfer(self):
|
def testStatusUrlSnarfer(self):
|
||||||
@ -385,8 +388,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
with self.mockRequests(expected_requests):
|
with self.mockRequests(expected_requests):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser/statuses/1234 bbb",
|
"aaa https://example.org/users/someuser/statuses/1234 bbb"
|
||||||
timeout=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expected_requests = [
|
expected_requests = [
|
||||||
@ -407,8 +409,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
with self.mockRequests(expected_requests):
|
with self.mockRequests(expected_requests):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser/statuses/1234 bbb",
|
"aaa https://example.org/users/someuser/statuses/1234 bbb"
|
||||||
timeout=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Sends a request, notices it's a profile, gives up
|
# Sends a request, notices it's a profile, gives up
|
||||||
@ -417,7 +418,7 @@ class FediverseTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
with self.mockRequests(expected_requests):
|
with self.mockRequests(expected_requests):
|
||||||
self.assertSnarfNoResponse(
|
self.assertSnarfNoResponse(
|
||||||
"aaa https://example.org/users/someuser/ bbb", timeout=1
|
"aaa https://example.org/users/someuser/ bbb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user