Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unused code. #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions swampdragon/pubsub_providers/mock_publisher.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import json


subscribers = {}


class MockPublisher(object):
def __init__(self):
self.subscribers = subscribers
self.subscribers = {}

def publish(self, channel, message):
subs = subscribers.get(channel)
subs = self.subscribers.get(channel)
if not subs:
return
for subscriber in subs:
Expand All @@ -26,20 +23,20 @@ def get_channels(self, base_channel):

def subscribe(self, channels, subscriber):
for c in channels:
if c not in subscribers.keys():
subscribers[c] = []
subscribers[c].append(subscriber)
if c not in self.subscribers.keys():
self.subscribers[c] = []
self.subscribers[c].append(subscriber)

def unsubscribe(self, channels, subscriber):
if not isinstance(channels, list):
return self.unsubscribe([channels], subscriber)
for channel in channels:
subscribers[channel].remove(subscriber)
self.subscribers[channel].remove(subscriber)

empty_channels = [k for (k, v) in subscribers.items() if not v]
empty_channels = [k for (k, v) in self.subscribers.items() if not v]
for k in empty_channels:
del subscribers[k]
del self.subscribers[k]

def remove_subscriber(self, subscriber):
channels = [c for c in subscribers if subscriber in subscribers[c]]
channels = [c for c in self.subscribers if subscriber in self.subscribers[c]]
self.unsubscribe(channels, subscriber)
5 changes: 0 additions & 5 deletions swampdragon/pubsub_providers/mock_sub_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from swampdragon.pubsub_providers.publisher_factory import get_publisher


_channels = []
publisher = get_publisher()


Expand All @@ -17,10 +16,6 @@ def publish(self, channel, data):

def subscribe(self, channels, connection):
publisher.subscribe(channels, connection)
# for c in channels:
# if not c in publisher.subscribers.keys():
# publisher.subscribers[c] = []
# publisher.subscribers[c].append(connection)

def unsubscribe(self, channels, connection):
for c in channels:
Expand Down
34 changes: 0 additions & 34 deletions swampdragon/testing/dragon_testcase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from tornado.testing import AsyncHTTPTestCase
from swampdragon import discover_routes
from swampdragon import route_handler
from swampdragon.pubsub_providers.subscriber_factory import get_subscription_provider
from swampdragon.connections.mock_connection import TestConnection
from django.test import TestCase
from django.conf import settings
Expand All @@ -11,58 +10,25 @@
from swampdragon.settings_provider import SettingsHandler


pub_sub = get_subscription_provider()


class DragonTestCase(TestCase):
def __init__(self, methodName='runTest'):
super(DragonTestCase, self).__init__(methodName)

pub_sub._channels = []
pub_sub._subscribers = {}
self.connection = TestConnection()
self.urls = discover_routes()

def tearDown(self):
route_handler.registered_handlers = {}
pub_sub._channels = []
pub_sub._subscribers = {}

def _load_app(self):
routers = []
module_name, cls_name = settings.SWAMP_DRAGON_CONNECTION[0].rsplit('.', 1)
module = import_module(module_name)
cls = getattr(module, cls_name)
channel = settings.SWAMP_DRAGON_CONNECTION[1]
routers.append(SockJSRouter(cls, channel))
print('Channel {}'.format(channel))

app_settings = {
'debug': settings.DEBUG,
}

urls = discover_routes()
for router in routers:
urls += router.urls

app = web.Application(urls, **app_settings)
return app


class DragonTestCaseAsync(AsyncHTTPTestCase):
def __init__(self, methodName='runTest'):
super(DragonTestCaseAsync, self).__init__(methodName)

pub_sub._channels = []
pub_sub._subscribers = {}
self.connection = TestConnection()
self.urls = discover_routes()
self.app = self._load_app()

def tearDown(self):
route_handler.registered_handlers = {}
pub_sub._channels = []
pub_sub._subscribers = {}

def _load_app(self):
routers = []
Expand Down
3 changes: 0 additions & 3 deletions swampdragon/testing/test_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
from django.conf import settings


_pub_sub = None


def set_test_mode():
os.environ.setdefault('SWAMPDRAGON_TESTMODE', 'True')

Expand Down