Skip to content

Commit

Permalink
Added a method to “clean” the list of rpc_method for one class. Prven…
Browse files Browse the repository at this point in the history
…t random test failures based on class id
  • Loading branch information
millerf committed Feb 13, 2017
1 parent 4de00c8 commit 16225fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions channels_jsonrpc/jsonrpcwebsocketconsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,12 @@ def __process(cls, data, original_msg):
class JsonRpcWebsocketConsumerTest(JsonRpcWebsocketConsumer):

TEST_MODE = True

@classmethod
def clean(cls):
"""
Clean the class method name for tests
:return: None
"""
if id(cls) in cls.available_rpc_methods:
del cls.available_rpc_methods[id(cls)]
19 changes: 19 additions & 0 deletions example/django_example/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ def ping_with_error_data():
self.assertEqual(msg['error']['code'], JsonRpcWebsocketConsumerTest.GENERIC_APPLICATION_ERROR)
self.assertEqual(msg['error']['data'], ['test_data', True])


def test_JsonRpcWebsocketConsumerTest_clean(self):

class TestNamesakeJsonRpcConsumer(JsonRpcWebsocketConsumerTest):
pass

@TestNamesakeJsonRpcConsumer.rpc_method()
def method_34():
pass

self.assertIn("method_34", TestNamesakeJsonRpcConsumer.get_rpc_methods())

TestNamesakeJsonRpcConsumer.clean()

self.assertEquals(TestNamesakeJsonRpcConsumer.get_rpc_methods(), [])

def test_namesake_consumers(self):

# Changed name to TestNamesakeJsonRpcConsumer2 to prevent overlapping with "previous" TestMyJsonRpcConsumer
Expand All @@ -244,6 +260,9 @@ class Context2():
class TestNamesakeJsonRpcConsumer2(JsonRpcWebsocketConsumerTest):
pass

Context1.TestNamesakeJsonRpcConsumer2.clean()
Context2.TestNamesakeJsonRpcConsumer2.clean()

@Context1.TestNamesakeJsonRpcConsumer2.rpc_method()
def method1():
pass
Expand Down

0 comments on commit 16225fa

Please sign in to comment.