Skip to content

Commit

Permalink
Isolate plugin tests from SAM session code
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Dec 19, 2016
1 parent 0335680 commit 94e4270
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions txi2p/test/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) str4d <str4d@mail.i2p>
# See COPYING for details.

import mock
from twisted.internet import interfaces
from twisted.python.versions import Version
from twisted.test.proto_helpers import MemoryReactor
Expand All @@ -19,6 +20,10 @@
skip = None


def fakeSession(nickname, **kwargs):
return mock.Mock()


class I2PPluginTestMixin(object):
def test_pluginDiscovery(self):
from twisted.internet.endpoints import getPlugins
Expand Down Expand Up @@ -61,8 +66,9 @@ def test_apiEndpointWithNoAPI(self):

def test_stringDescription_default(self):
from twisted.internet.endpoints import clientFromString
ep = clientFromString(
MemoryReactor(), "i2p:stats.i2p")
with mock.patch('txi2p.sam.endpoints.getSession', fakeSession):
ep = clientFromString(
MemoryReactor(), "i2p:stats.i2p")
self.assertIsInstance(ep, SAMI2PStreamClientEndpoint)

def test_stringDescription_BOB(self):
Expand All @@ -77,8 +83,9 @@ def test_stringDescription_BOB(self):

def test_stringDescription_SAM(self):
from twisted.internet.endpoints import clientFromString
ep = clientFromString(
MemoryReactor(), "i2p:stats.i2p:81:api=SAM:localPort=34444")
with mock.patch('txi2p.sam.endpoints.getSession', fakeSession):
ep = clientFromString(
MemoryReactor(), "i2p:stats.i2p:81:api=SAM:localPort=34444")
self.assertIsInstance(ep, SAMI2PStreamClientEndpoint)
self.assertEqual(ep._host, "stats.i2p")
self.assertEqual(ep._port, 81)
Expand Down Expand Up @@ -111,8 +118,9 @@ def test_apiEndpointWithNoAPI(self):

def test_stringDescription_default(self):
from twisted.internet.endpoints import serverFromString
ep = serverFromString(
MemoryReactor(), "i2p:/tmp/testkeys.foo")
with mock.patch('txi2p.sam.endpoints.getSession', fakeSession):
ep = serverFromString(
MemoryReactor(), "i2p:/tmp/testkeys.foo")
self.assertIsInstance(ep, SAMI2PStreamServerEndpoint)

def test_stringDescription_BOB(self):
Expand All @@ -127,6 +135,7 @@ def test_stringDescription_BOB(self):

def test_stringDescription_SAM(self):
from twisted.internet.endpoints import serverFromString
ep = serverFromString(
MemoryReactor(), "i2p:/tmp/testkeys.foo:81:api=SAM")
with mock.patch('txi2p.sam.endpoints.getSession', fakeSession):
ep = serverFromString(
MemoryReactor(), "i2p:/tmp/testkeys.foo:81:api=SAM")
self.assertIsInstance(ep, SAMI2PStreamServerEndpoint)

0 comments on commit 94e4270

Please sign in to comment.