signalrcore 0.9.5__py3-none-any.whl → 0.9.6a2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of signalrcore might be problematic. Click here for more details.

test/send_test.py CHANGED
@@ -1,15 +1,13 @@
1
- import os
2
- import re
3
- import unittest
4
- import logging
5
1
  import time
6
2
  import uuid
7
3
  import threading
8
4
 
9
- from signalrcore.hub_connection_builder import HubConnectionBuilder
10
- from signalrcore.hub.errors import HubError, HubConnectionError
5
+ from signalrcore.hub.errors import HubConnectionError
11
6
  from test.base_test_case import BaseTestCase, Urls
12
7
 
8
+ LOCKS = {}
9
+
10
+
13
11
  class TestSendException(BaseTestCase):
14
12
  def receive_message(self, _):
15
13
  raise Exception()
@@ -19,46 +17,61 @@ class TestSendException(BaseTestCase):
19
17
  self.connection.start()
20
18
  while not self.connected:
21
19
  time.sleep(0.1)
22
-
20
+
23
21
  def test_send_exception(self):
24
- _lock = threading.Lock()
25
- _lock.acquire()
22
+ identifier = str(uuid.uuid4())
23
+ LOCKS[identifier] = threading.Lock()
24
+ LOCKS[identifier].acquire()
26
25
  self.connection.send("SendMessage", ["user", "msg"])
27
- del _lock
26
+ del LOCKS[identifier]
28
27
 
29
28
  def test_hub_error(self):
30
- _lock = threading.Lock()
29
+ identifier = str(uuid.uuid4())
30
+ LOCKS[identifier] = threading.Lock()
31
+
32
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
31
33
 
32
- self.assertTrue(_lock.acquire(timeout=10))
33
- self.connection.on_error(lambda _: _lock.release())
34
+ def on_error(err=None):
35
+ LOCKS[identifier].release()
36
+
37
+ self.connection.on_error(on_error)
34
38
 
35
39
  def on_message(_):
36
- _lock.release()
37
- self.assertTrue(_lock.acquire(timeout=10))
40
+ LOCKS[identifier].release()
41
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
38
42
 
39
43
  self.connection.on("ThrowExceptionCall", on_message)
40
44
  self.connection.send("ThrowException", ["msg"])
41
45
 
46
+
42
47
  class TestSendExceptionMsgPack(TestSendException):
43
48
  def setUp(self):
44
49
  self.connection = self.get_connection(msgpack=True)
45
50
  self.connection.start()
46
51
  while not self.connected:
47
52
  time.sleep(0.1)
48
-
53
+
54
+
49
55
  class TestSendWarning(BaseTestCase):
50
56
  def setUp(self):
51
57
  self.connection = self.get_connection()
52
58
  self.connection.start()
53
59
  while not self.connected:
54
60
  time.sleep(0.1)
55
-
61
+
56
62
  def test_send_warning(self):
57
- _lock = threading.Lock()
58
- _lock.acquire()
59
- self.connection.send("SendMessage", ["user", "msg"], lambda m: _lock.release())
60
- self.assertTrue(_lock.acquire(timeout=10))
61
- del _lock
63
+ identifier = str(uuid.uuid4())
64
+ LOCKS[identifier] = threading.Lock()
65
+ LOCKS[identifier].acquire()
66
+
67
+ def release(msg=None):
68
+ global LOCKS
69
+ LOCKS[identifier].release()
70
+
71
+ self.connection.send("SendMessage", ["user", "msg"], release)
72
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
73
+ del LOCKS[identifier]
74
+
62
75
 
63
76
  class TestSendWarningMsgPack(TestSendWarning):
64
77
  def setUp(self):
@@ -66,11 +79,12 @@ class TestSendWarningMsgPack(TestSendWarning):
66
79
  self.connection.start()
67
80
  while not self.connected:
68
81
  time.sleep(0.1)
69
-
82
+
70
83
 
71
84
  class TestSendMethod(BaseTestCase):
72
85
  received = False
73
86
  message = None
87
+
74
88
  def setUp(self):
75
89
  self.connection = self.get_connection()
76
90
  self.connection.on("ReceiveMessage", self.receive_message)
@@ -82,12 +96,13 @@ class TestSendMethod(BaseTestCase):
82
96
  self.assertEqual(args[1], self.message)
83
97
  self.received = True
84
98
 
85
-
86
99
  def test_send_bad_args(self):
87
100
  class A():
88
101
  pass
89
102
 
90
- self.assertRaises(TypeError, lambda : self.connection.send("SendMessage", A()))
103
+ self.assertRaises(
104
+ TypeError,
105
+ lambda: self.connection.send("SendMessage", A()))
91
106
 
92
107
  def test_send(self):
93
108
  self.message = "new message {0}".format(uuid.uuid4())
@@ -102,13 +117,16 @@ class TestSendMethod(BaseTestCase):
102
117
  self.message = "new message {0}".format(uuid.uuid4())
103
118
  self.username = "mandrewcito"
104
119
  self.received = False
105
- _lock = threading.Lock()
106
- _lock.acquire()
120
+ identifier = str(uuid.uuid4())
121
+ LOCKS[identifier] = threading.Lock()
122
+
123
+ LOCKS[identifier].acquire()
107
124
  uid = str(uuid.uuid4())
108
125
 
109
126
  def release(m):
127
+ global LOCKS
110
128
  self.assertTrue(m.invocation_id, uid)
111
- _lock.release()
129
+ LOCKS[identifier].release()
112
130
 
113
131
  self.connection.send(
114
132
  "SendMessage",
@@ -116,12 +134,14 @@ class TestSendMethod(BaseTestCase):
116
134
  release,
117
135
  invocation_id=uid)
118
136
 
119
- self.assertTrue(_lock.acquire(timeout=10))
120
- del _lock
137
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
138
+ del LOCKS[identifier]
139
+
121
140
 
122
141
  class TestSendNoSslMethod(TestSendMethod):
123
142
  server_url = Urls.server_url_no_ssl
124
143
 
144
+
125
145
  class TestSendMethodMsgPack(TestSendMethod):
126
146
  def setUp(self):
127
147
  self.connection = super().get_connection(msgpack=True)
@@ -130,12 +150,15 @@ class TestSendMethodMsgPack(TestSendMethod):
130
150
  while not self.connected:
131
151
  time.sleep(0.1)
132
152
 
153
+
133
154
  class TestSendNoSslMethodMsgPack(TestSendMethodMsgPack):
134
- server_url = Urls.server_url_no_ssl
155
+ server_url = Urls.server_url_no_ssl
156
+
135
157
 
136
158
  class TestSendErrorMethod(BaseTestCase):
137
159
  received = False
138
160
  message = None
161
+
139
162
  def setUp(self):
140
163
  self.connection = self.get_connection()
141
164
  self.connection.on("ReceiveMessage", self.receive_message)
@@ -144,20 +167,21 @@ class TestSendErrorMethod(BaseTestCase):
144
167
  self.assertEqual(args[1], self.message)
145
168
  self.received = True
146
169
 
147
-
148
170
  def test_send_with_error(self):
149
171
  self.message = "new message {0}".format(uuid.uuid4())
150
172
  self.username = "mandrewcito"
151
173
 
152
- self.assertRaises(HubConnectionError,lambda : self.connection.send("SendMessage", [self.username, self.message]))
153
-
174
+ self.assertRaises(
175
+ HubConnectionError,
176
+ lambda: self.connection.send(
177
+ "SendMessage", [self.username, self.message]))
178
+
154
179
  self.connection.start()
155
180
  while not self.connected:
156
181
  time.sleep(0.1)
157
182
 
158
183
  self.received = False
159
- self.connection.send("SendMessage", [self.username, self.message])
160
- t0 = time.time()
184
+ self.connection.send("SendMessage", [self.username, self.message])
161
185
  while not self.received:
162
186
  time.sleep(0.1)
163
187
  self.assertTrue(self.received)
@@ -171,6 +195,7 @@ class TestSendErrorMethodMsgPack(TestSendErrorMethod):
171
195
  def get_connection(self):
172
196
  return super().get_connection(msgpack=True)
173
197
 
198
+
174
199
  class TestSendErrorNoSslMethodMsgPack(TestSendErrorNoSslMethod):
175
200
  def get_connection(self):
176
201
  return super().get_connection(msgpack=True)
test/streaming_test.py CHANGED
@@ -1,17 +1,11 @@
1
- import os
2
- import unittest
3
- import logging
4
1
  import time
5
- import uuid
6
-
7
- from subprocess import Popen, PIPE
8
- from signalrcore.hub_connection_builder import HubConnectionBuilder
9
2
  from test.base_test_case import BaseTestCase, Urls
10
3
 
4
+
11
5
  class TestSendMethod(BaseTestCase):
12
6
  server_url = Urls.server_url_ssl
13
7
  received = False
14
- items = list(range(0,10))
8
+ items = list(range(0, 10))
15
9
 
16
10
  def on_complete(self, x):
17
11
  self.complete = True
@@ -23,46 +17,51 @@ class TestSendMethod(BaseTestCase):
23
17
 
24
18
  def test_stream(self):
25
19
  self.complete = False
26
- self.items = list(range(0,10))
20
+ self.items = list(range(0, 10))
27
21
  self.connection.stream(
28
22
  "Counter",
29
23
  [len(self.items), 500]).subscribe({
30
24
  "next": self.on_next,
31
25
  "complete": self.on_complete,
32
- "error": self.fail # TestcaseFail
26
+ "error": self.fail # TestcaseFail
33
27
  })
34
28
  while not self.complete:
35
29
  time.sleep(0.1)
36
-
30
+
37
31
  def test_stream_error(self):
38
32
  self.complete = False
39
- self.items = list(range(0,10))
33
+ self.items = list(range(0, 10))
40
34
 
41
- my_stream = self.connection.stream(
35
+ my_stream = self.connection.stream(
42
36
  "Counter",
43
37
  [len(self.items), 500])
44
38
 
45
39
  self.assertRaises(TypeError, lambda: my_stream.subscribe(None))
46
40
 
47
- self.assertRaises(TypeError, lambda:my_stream.subscribe([self.on_next]))
41
+ self.assertRaises(
42
+ TypeError,
43
+ lambda: my_stream.subscribe([self.on_next]))
48
44
 
49
45
  self.assertRaises(KeyError, lambda: my_stream.subscribe({
50
- "key":self.on_next
51
- }))
46
+ "key": self.on_next
47
+ }))
52
48
 
53
49
  self.assertRaises(ValueError, lambda: my_stream.subscribe({
54
50
  "next": "",
55
51
  "complete": 1,
56
- "error": [] # TestcaseFail
52
+ "error": [] # TestcaseFail
57
53
  }))
58
54
 
55
+
59
56
  class TestSendNoSslMethod(TestSendMethod):
60
57
  server_url = Urls.server_url_no_ssl
61
58
 
59
+
62
60
  class TestSendMethodMsgPack(TestSendMethod):
63
61
  def get_connection(self):
64
62
  return super().get_connection(msgpack=True)
65
63
 
64
+
66
65
  class TestSendMethodNoSslMsgPack(TestSendNoSslMethod):
67
66
  def get_connection(self):
68
- return super().get_connection(msgpack=True)
67
+ return super().get_connection(msgpack=True)
test/subscribe_test.py ADDED
@@ -0,0 +1,18 @@
1
+ from test.base_test_case import BaseTestCase, Urls
2
+
3
+
4
+ class TestSendMethod(BaseTestCase):
5
+ server_url = Urls.server_url_ssl
6
+
7
+ def test_unsubscribe(self):
8
+ def fake_callback(_):
9
+ pass
10
+
11
+ self.connection = self.get_connection()
12
+ self.connection.on("ReceiveMessage", fake_callback)
13
+
14
+ self.assertEqual(len(self.connection.handlers), 1)
15
+
16
+ self.connection.unsubscribe("ReceiveMessage", fake_callback)
17
+
18
+ self.assertEqual(len(self.connection.handlers), 0)