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/base_test_case.py CHANGED
@@ -3,17 +3,21 @@ import logging
3
3
  import time
4
4
  from signalrcore.hub_connection_builder import HubConnectionBuilder
5
5
  from signalrcore.protocol.messagepack_protocol import MessagePackHubProtocol
6
+
7
+
6
8
  class Urls:
7
9
  server_url_no_ssl = "ws://localhost:5000/chatHub"
8
10
  server_url_ssl = "wss://localhost:5001/chatHub"
9
11
  server_url_no_ssl_auth = "ws://localhost:5000/authHub"
10
12
  server_url_ssl_auth = "wss://localhost:5001/authHub"
11
- login_url_ssl = "https://localhost:5001/users/authenticate"
12
- login_url_no_ssl = "http://localhost:5000/users/authenticate"
13
+ login_url_ssl = "https://localhost:5001/users/authenticate"
14
+ login_url_no_ssl = "http://localhost:5000/users/authenticate"
15
+
13
16
 
14
17
  class InternalTestCase(unittest.TestCase):
15
18
  connection = None
16
19
  connected = False
20
+
17
21
  def get_connection(self):
18
22
  raise NotImplementedError()
19
23
 
@@ -35,12 +39,13 @@ class InternalTestCase(unittest.TestCase):
35
39
  def on_close(self):
36
40
  self.connected = False
37
41
 
42
+
38
43
  class BaseTestCase(InternalTestCase):
39
44
  server_url = Urls.server_url_ssl
40
45
 
41
46
  def get_connection(self, msgpack=False):
42
47
  builder = HubConnectionBuilder()\
43
- .with_url(self.server_url, options={"verify_ssl":False})\
48
+ .with_url(self.server_url, options={"verify_ssl": False})\
44
49
  .configure_logging(logging.ERROR)\
45
50
  .with_automatic_reconnect({
46
51
  "type": "raw",
@@ -55,4 +60,4 @@ class BaseTestCase(InternalTestCase):
55
60
  hub = builder.build()
56
61
  hub.on_open(self.on_open)
57
62
  hub.on_close(self.on_close)
58
- return hub
63
+ return hub
@@ -1,32 +1,28 @@
1
- import os
2
- import unittest
3
- import logging
4
- import time
5
- import uuid
6
-
7
- from subprocess import Popen, PIPE
8
- from signalrcore.hub_connection_builder import HubConnectionBuilder
9
1
  from signalrcore.subject import Subject
10
2
  from test.base_test_case import BaseTestCase, Urls
11
3
 
4
+
12
5
  class TestClientStreamMethod(BaseTestCase):
13
6
 
14
7
  def test_stream(self):
15
8
  self.complete = False
16
- self.items = list(range(0,10))
9
+ self.items = list(range(0, 10))
17
10
  subject = Subject()
18
11
  self.connection.send("UploadStream", subject)
19
- while(len(self.items) > 0):
12
+ while (len(self.items) > 0):
20
13
  subject.next(str(self.items.pop()))
21
14
  subject.complete()
22
15
  self.assertTrue(len(self.items) == 0)
23
16
 
17
+
24
18
  class TestClientStreamMethodMsgPack(TestClientStreamMethod):
25
19
  def get_connection(self):
26
- return super().get_connection(msgpack=True)
20
+ return super().get_connection(msgpack=True)
21
+
27
22
 
28
- class TestClientNosslStreamMethodMsgPack(TestClientStreamMethodMsgPack):
23
+ class TestClientNoSslStreamMethodMsgPack(TestClientStreamMethodMsgPack):
29
24
  server_url = Urls.server_url_no_ssl
30
25
 
31
- class TestClientNosslStreamMethod(TestClientStreamMethod):
32
- server_url = Urls.server_url_no_ssl
26
+
27
+ class TestClientNoSslStreamMethod(TestClientStreamMethod):
28
+ server_url = Urls.server_url_no_ssl
@@ -1,22 +1,23 @@
1
- import websocket
2
1
  import logging
3
2
  from signalrcore.hub_connection_builder import HubConnectionBuilder
4
3
 
5
- from test.base_test_case import BaseTestCase, Urls
4
+ from test.base_test_case import BaseTestCase
5
+
6
6
 
7
7
  class TestConfiguration(BaseTestCase):
8
-
8
+
9
9
  def test_bad_auth_function(self):
10
10
  with self.assertRaises(TypeError):
11
11
  self.connection = HubConnectionBuilder()\
12
- .with_url(self.server_url,
13
- options={
14
- "verify_ssl": False,
15
- "access_token_factory": 1234,
16
- "headers": {
17
- "mycustomheader": "mycustomheadervalue"
18
- }
19
- })
12
+ .with_url(
13
+ self.server_url,
14
+ options={
15
+ "verify_ssl": False,
16
+ "access_token_factory": 1234,
17
+ "headers": {
18
+ "mycustomheader": "mycustomheadervalue"
19
+ }
20
+ })
20
21
 
21
22
  def test_bad_url(self):
22
23
  with self.assertRaises(ValueError):
@@ -26,26 +27,28 @@ class TestConfiguration(BaseTestCase):
26
27
  def test_bad_options(self):
27
28
  with self.assertRaises(TypeError):
28
29
  self.connection = HubConnectionBuilder()\
29
- .with_url(self.server_url,
30
- options=["ssl", True])
31
-
30
+ .with_url(
31
+ self.server_url,
32
+ options=["ssl", True])
33
+
32
34
  def test_auth_configured(self):
33
35
  with self.assertRaises(TypeError):
34
36
  hub = HubConnectionBuilder()\
35
- .with_url(self.server_url,
36
- options={
37
- "verify_ssl": False,
38
- "headers": {
39
- "mycustomheader": "mycustomheadervalue"
40
- }
41
- })
37
+ .with_url(
38
+ self.server_url,
39
+ options={
40
+ "verify_ssl": False,
41
+ "headers": {
42
+ "mycustomheader": "mycustomheadervalue"
43
+ }
44
+ })
42
45
  hub.has_auth_configured = True
43
46
  hub.options["access_token_factory"] = ""
44
- conn = hub.build()
47
+ _ = hub.build()
45
48
 
46
49
  def test_enable_trace(self):
47
50
  hub = HubConnectionBuilder()\
48
- .with_url(self.server_url, options={"verify_ssl":False})\
51
+ .with_url(self.server_url, options={"verify_ssl": False})\
49
52
  .configure_logging(logging.WARNING, socket_trace=True)\
50
53
  .with_automatic_reconnect({
51
54
  "type": "raw",
@@ -57,6 +60,5 @@ class TestConfiguration(BaseTestCase):
57
60
  hub.on_open(self.on_open)
58
61
  hub.on_close(self.on_close)
59
62
  hub.start()
60
- self.assertTrue(websocket.isEnabledForDebug())
61
- websocket.enableTrace(False)
62
- hub.stop()
63
+ self.assertTrue(hub.transport.is_trace_enabled())
64
+ hub.stop()
test/open_close_test.py CHANGED
@@ -1,16 +1,14 @@
1
- import os
2
- import unittest
3
1
  import logging
4
- import time
5
2
  import threading
6
3
  import uuid
7
4
 
8
- from subprocess import Popen, PIPE
9
5
  from signalrcore.hub_connection_builder import HubConnectionBuilder
10
- from signalrcore.subject import Subject
11
- from test.base_test_case import BaseTestCase, Urls
6
+ from test.base_test_case import BaseTestCase
12
7
 
13
- class TestClientStreamMethod(BaseTestCase):
8
+ LOCKS = {}
9
+
10
+
11
+ class TestClientStreamMethod(BaseTestCase):
14
12
  def setUp(self):
15
13
  pass
16
14
 
@@ -22,43 +20,54 @@ class TestClientStreamMethod(BaseTestCase):
22
20
  .with_url(self.server_url, options={"verify_ssl": False})\
23
21
  .configure_logging(logging.ERROR)\
24
22
  .build()
25
-
26
- _lock = threading.Lock()
27
- self.assertTrue(_lock.acquire(timeout=30))
28
-
29
-
30
- connection.on_open(lambda: _lock.release())
31
- connection.on_close(lambda: _lock.release())
32
-
23
+
24
+ identifier = str(uuid.uuid4())
25
+ LOCKS[identifier] = threading.Lock()
26
+
27
+ def release():
28
+ LOCKS[identifier].release()
29
+
30
+ self.assertTrue(LOCKS[identifier].acquire(timeout=30))
31
+
32
+ connection.on_open(release)
33
+ connection.on_close(release)
34
+
33
35
  result = connection.start()
34
36
 
35
37
  self.assertTrue(result)
36
-
37
- self.assertTrue(_lock.acquire(timeout=30)) # Released on open
38
-
38
+
39
+ self.assertTrue(LOCKS[identifier].acquire(timeout=30))
40
+ # Released on open
41
+
39
42
  result = connection.start()
40
43
 
41
44
  self.assertFalse(result)
42
45
 
43
46
  connection.stop()
44
47
 
48
+ del LOCKS[identifier]
49
+
45
50
  def test_open_close(self):
46
51
  self.connection = self.get_connection()
47
-
48
- _lock = threading.Lock()
49
52
 
50
- self.connection.on_open(lambda: _lock.release())
51
- self.connection.on_close(lambda: _lock.release())
53
+ identifier = str(uuid.uuid4())
54
+ LOCKS[identifier] = threading.Lock()
55
+
56
+ def release():
57
+ LOCKS[identifier].release()
52
58
 
53
- self.assertTrue(_lock.acquire())
59
+ self.connection.on_open(release)
60
+ self.connection.on_close(release)
61
+
62
+ self.assertTrue(LOCKS[identifier].acquire())
54
63
 
55
64
  self.connection.start()
56
65
 
57
- self.assertTrue(_lock.acquire())
58
-
66
+ self.assertTrue(LOCKS[identifier].acquire())
67
+
59
68
  self.connection.stop()
60
-
61
- self.assertTrue(_lock.acquire())
62
69
 
63
- _lock.release()
64
- del _lock
70
+ self.assertTrue(LOCKS[identifier].acquire())
71
+
72
+ release()
73
+ del LOCKS[identifier]
test/reconnection_test.py CHANGED
@@ -1,22 +1,19 @@
1
- import os
2
- import unittest
3
1
  import logging
4
2
  import time
5
3
  import uuid
6
4
  import threading
7
5
 
8
- from subprocess import Popen, PIPE
9
6
  from signalrcore.hub_connection_builder import HubConnectionBuilder
10
7
  from signalrcore.hub.errors import HubConnectionError
11
- from test.base_test_case import BaseTestCase, Urls
12
- from signalrcore.transport.websockets.reconnection import RawReconnectionHandler, IntervalReconnectionHandler
8
+ from test.base_test_case import BaseTestCase
9
+ from signalrcore.transport.websockets.reconnection\
10
+ import RawReconnectionHandler, IntervalReconnectionHandler
13
11
 
14
12
 
15
- class TestReconnectMethods(BaseTestCase):
13
+ LOCKS = {}
14
+
16
15
 
17
- def receive_message(self, args):
18
- self.assertEqual(args[1], self.message)
19
- self.received = True
16
+ class TestReconnectMethods(BaseTestCase):
20
17
 
21
18
  def test_reconnect_interval_config(self):
22
19
  connection = HubConnectionBuilder()\
@@ -27,21 +24,27 @@ class TestReconnectMethods(BaseTestCase):
27
24
  "intervals": [1, 2, 4, 45, 6, 7, 8, 9, 10]
28
25
  })\
29
26
  .build()
30
- _lock = threading.Lock()
31
- connection.on_open(lambda: _lock.release())
32
- connection.on_close(lambda: _lock.release())
33
27
 
34
- self.assertTrue(_lock.acquire(timeout=10))
28
+ identifier = str(uuid.uuid4())
29
+ LOCKS[identifier] = threading.Lock()
30
+
31
+ def release():
32
+ LOCKS[identifier].release()
33
+
34
+ connection.on_open(release)
35
+ connection.on_close(release)
36
+
37
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
35
38
 
36
39
  connection.start()
37
40
 
38
- self.assertTrue(_lock.acquire(timeout=10))
41
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
39
42
 
40
43
  connection.stop()
41
44
 
42
- self.assertTrue(_lock.acquire(timeout=10))
45
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
43
46
 
44
- del _lock
47
+ del LOCKS[identifier]
45
48
 
46
49
  def test_reconnect_interval(self):
47
50
  connection = HubConnectionBuilder()\
@@ -61,21 +64,26 @@ class TestReconnectMethods(BaseTestCase):
61
64
  .configure_logging(logging.ERROR)\
62
65
  .build()
63
66
 
64
- _lock = threading.Lock()
67
+ identifier = str(uuid.uuid4())
68
+ LOCKS[identifier] = threading.Lock()
69
+
70
+ def release(msg=None):
71
+ LOCKS[identifier].release()
65
72
 
66
- _lock.acquire(timeout=10)
73
+ LOCKS[identifier].acquire(timeout=10)
67
74
 
68
- connection.on_open(lambda: _lock.release())
75
+ connection.on_open(release)
69
76
 
70
- connection.on("ReceiveMessage", lambda _: _lock.release())
77
+ connection.on("ReceiveMessage", release)
71
78
 
72
79
  connection.start()
73
80
 
74
- self.assertTrue(_lock.acquire(timeout=10)) # Released on ReOpen
75
-
81
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
82
+ # Released on ReOpen
83
+
76
84
  connection.send("DisconnectMe", [])
77
85
 
78
- self.assertTrue(_lock.acquire(timeout=10))
86
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
79
87
 
80
88
  time.sleep(10)
81
89
 
@@ -84,23 +92,29 @@ class TestReconnectMethods(BaseTestCase):
84
92
  lambda: connection.send("DisconnectMe", []))
85
93
 
86
94
  connection.stop()
87
- del _lock
95
+ del LOCKS[identifier]
88
96
 
89
97
  def reconnect_test(self, connection):
90
- _lock = threading.RLock()
98
+ identifier = str(uuid.uuid4())
99
+ LOCKS[identifier] = threading.Lock()
100
+
101
+ def release():
102
+ LOCKS[identifier].release()
91
103
 
92
- connection.on_open(lambda: _lock.release())
104
+ connection.on_open(release)
93
105
 
94
106
  connection.start()
95
107
 
96
- self.assertTrue(_lock.acquire(timeout=10)) # Release on Open
108
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
109
+ # Release on Open
97
110
 
98
111
  connection.send("DisconnectMe", [])
99
112
 
100
- self.assertTrue(_lock.acquire(timeout=10)) # released on open
113
+ self.assertTrue(LOCKS[identifier].acquire(timeout=10))
114
+ # released on open
101
115
 
102
116
  connection.stop()
103
- del _lock
117
+ del LOCKS[identifier]
104
118
 
105
119
  def test_raw_reconnection(self):
106
120
  connection = HubConnectionBuilder()\
@@ -117,11 +131,11 @@ class TestReconnectMethods(BaseTestCase):
117
131
 
118
132
  def test_raw_handler(self):
119
133
  handler = RawReconnectionHandler(5, 10)
120
- attemp = 0
134
+ attempt = 0
121
135
 
122
- while attemp <= 10:
136
+ while attempt <= 10:
123
137
  self.assertEqual(handler.next(), 5)
124
- attemp = attemp + 1
138
+ attempt = attempt + 1
125
139
 
126
140
  self.assertRaises(ValueError, handler.next)
127
141
 
@@ -1,14 +1,10 @@
1
- import os
2
- import unittest
3
1
  import logging
4
- import time
5
- import uuid
6
2
  import requests
7
- from subprocess import Popen, PIPE
8
3
  from signalrcore.hub_connection_builder import HubConnectionBuilder
9
4
  from signalrcore.protocol.messagepack_protocol import MessagePackHubProtocol
10
5
  from test.base_test_case import BaseTestCase, Urls
11
6
 
7
+
12
8
  class TestSendAuthErrorMethod(BaseTestCase):
13
9
  server_url = Urls.server_url_ssl_auth
14
10
  login_url = Urls.login_url_ssl
@@ -23,8 +19,9 @@ class TestSendAuthErrorMethod(BaseTestCase):
23
19
  json={
24
20
  "username": self.email,
25
21
  "password": self.password
26
- },verify=False)
27
- if response.status_code == 200:
22
+ },
23
+ verify=False)
24
+ if response.status_code == 200: # pragma: no cover
28
25
  return response.json()["token"]
29
26
  raise requests.exceptions.ConnectionError()
30
27
 
@@ -35,26 +32,29 @@ class TestSendAuthErrorMethod(BaseTestCase):
35
32
  self._test_send(msgpack=False)
36
33
 
37
34
  def test_send_msgpack(self):
38
- self._test_send(msgpack=True)
39
-
35
+ self._test_send(msgpack=True)
36
+
40
37
  def _test_send(self, msgpack=False):
41
38
  builder = HubConnectionBuilder()\
42
- .with_url(self.server_url,
43
- options={
44
- "verify_ssl": False,
45
- "access_token_factory": self.login,
46
- })
47
-
39
+ .with_url(
40
+ self.server_url,
41
+ options={
42
+ "verify_ssl": False,
43
+ "access_token_factory": self.login,
44
+ })
45
+
48
46
  if msgpack:
49
47
  builder.with_hub_protocol(MessagePackHubProtocol())
50
-
48
+
51
49
  builder.configure_logging(logging.ERROR)
52
50
  self.connection = builder.build()
53
51
  self.connection.on_open(self.on_open)
54
52
  self.connection.on_close(self.on_close)
55
- self.assertRaises(requests.exceptions.ConnectionError, lambda :self.connection.start())
53
+ self.assertRaises(
54
+ requests.exceptions.ConnectionError,
55
+ lambda: self.connection.start())
56
+
56
57
 
57
-
58
58
  class TestSendNoSslAuthMethod(TestSendAuthErrorMethod):
59
59
  server_url = Urls.server_url_no_ssl_auth
60
60
  login_url = Urls.login_url_no_ssl
test/send_auth_test.py CHANGED
@@ -1,14 +1,12 @@
1
- import os
2
- import unittest
3
1
  import threading
4
2
  import logging
5
- import time
6
3
  import uuid
7
4
  import requests
8
5
  from signalrcore.hub_connection_builder import HubConnectionBuilder
9
6
  from signalrcore.protocol.messagepack_protocol import MessagePackHubProtocol
10
7
  from test.base_test_case import BaseTestCase, Urls
11
8
 
9
+
12
10
  class TestSendAuthMethod(BaseTestCase):
13
11
  server_url = Urls.server_url_ssl_auth
14
12
  login_url = Urls.login_url_ssl
@@ -24,19 +22,21 @@ class TestSendAuthMethod(BaseTestCase):
24
22
  json={
25
23
  "username": self.email,
26
24
  "password": self.password
27
- },verify=False)
25
+ },
26
+ verify=False)
28
27
  return response.json()["token"]
29
28
 
30
- def _setUp(self, msgpack= False):
29
+ def _setUp(self, msgpack=False):
31
30
  builder = HubConnectionBuilder()\
32
- .with_url(self.server_url,
33
- options={
34
- "verify_ssl": False,
35
- "access_token_factory": self.login,
36
- "headers": {
37
- "mycustomheader": "mycustomheadervalue"
38
- }
39
- })
31
+ .with_url(
32
+ self.server_url,
33
+ options={
34
+ "verify_ssl": False,
35
+ "access_token_factory": self.login,
36
+ "headers": {
37
+ "mycustomheader": "mycustomheadervalue"
38
+ }
39
+ })
40
40
 
41
41
  if msgpack:
42
42
  builder.with_hub_protocol(MessagePackHubProtocol())
@@ -55,7 +55,7 @@ class TestSendAuthMethod(BaseTestCase):
55
55
  self._lock = threading.Lock()
56
56
  self.assertTrue(self._lock.acquire(timeout=30))
57
57
  self.connection.start()
58
-
58
+
59
59
  def on_open(self):
60
60
  self._lock.release()
61
61
 
@@ -65,23 +65,26 @@ class TestSendAuthMethod(BaseTestCase):
65
65
  def receive_message(self, args):
66
66
  self._lock.release()
67
67
  self.assertEqual(args[0], self.message)
68
-
68
+
69
69
  def test_send(self):
70
70
  self.message = "new message {0}".format(uuid.uuid4())
71
71
  self.username = "mandrewcito"
72
72
  self.assertTrue(self._lock.acquire(timeout=30))
73
73
  self.connection.send("SendMessage", [self.message])
74
74
  self.assertTrue(self._lock.acquire(timeout=30))
75
- del self._lock
76
-
75
+ del self._lock
76
+
77
+
77
78
  class TestSendNoSslAuthMethod(TestSendAuthMethod):
78
79
  server_url = Urls.server_url_no_ssl_auth
79
80
  login_url = Urls.login_url_no_ssl
80
81
 
82
+
81
83
  class TestSendAuthMethodMsgPack(TestSendAuthMethod):
82
84
  def setUp(self):
83
85
  self._setUp(msgpack=True)
84
86
 
87
+
85
88
  class TestSendNoSslAuthMethodMsgPack(TestSendAuthMethod):
86
89
  server_url = Urls.server_url_no_ssl_auth
87
- login_url = Urls.login_url_no_ssl
90
+ login_url = Urls.login_url_no_ssl