Skip to content

Commit 0c8555a

Browse files
author
seba-aln
authored
Require config.uuid when creating PubNub instance (#110)
1 parent f6bd5ea commit 0c8555a

File tree

20 files changed

+343
-88
lines changed

20 files changed

+343
-88
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 5.5.0
2+
version: 6.0.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-5.5.0
21+
package-name: pubnub-6.0.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -97,8 +97,8 @@ sdks:
9797
-
9898
distribution-type: library
9999
distribution-repository: git release
100-
package-name: pubnub-5.5.0
101-
location: https://github.com/pubnub/python/releases/download/v5.5.0/pubnub-5.5.0.tar.gz
100+
package-name: pubnub-6.0.0
101+
location: https://github.com/pubnub/python/releases/download/v6.0.0/pubnub-6.0.0.tar.gz
102102
supported-platforms:
103103
supported-operating-systems:
104104
Linux:
@@ -169,6 +169,11 @@ sdks:
169169
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
170170
is-required: Required
171171
changelog:
172+
- date: 2022-01-13
173+
version: v6.0.0
174+
changes:
175+
- type: improvement
176+
text: "BREAKING CHANGES: uuid is required parameter while creating an instance of PubNub."
172177
- date: 2021-12-16
173178
version: v5.5.0
174179
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v6.0.0
2+
January 13 2022
3+
4+
#### Modified
5+
- BREAKING CHANGES: uuid is required parameter while creating an instance of PubNub.
6+
17
## v5.5.0
28
December 16 2021
39

pubnub/pnconfiguration.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .enums import PNHeartbeatNotificationOptions, PNReconnectionPolicy
2-
from . import utils
32

43

54
class PNConfiguration(object):
@@ -8,7 +7,7 @@ class PNConfiguration(object):
87

98
def __init__(self):
109
# TODO: add validation
11-
self.uuid = None
10+
self._uuid = None
1211
self.origin = "ps.pndsn.com"
1312
self.ssl = True
1413
self.non_subscribe_request_timeout = 10
@@ -36,10 +35,10 @@ def __init__(self):
3635
self._heartbeat_interval = PNConfiguration.DEFAULT_HEARTBEAT_INTERVAL
3736

3837
def validate(self):
39-
assert self.uuid is None or isinstance(self.uuid, str)
38+
PNConfiguration.validate_not_empty_string(self.uuid)
4039

41-
if not self.uuid:
42-
self.uuid = utils.uuid()
40+
def validate_not_empty_string(value: str):
41+
assert value and isinstance(value, str) and value.strip() != "", "UUID missing or invalid type"
4342

4443
def scheme(self):
4544
if self.ssl:
@@ -97,3 +96,12 @@ def heartbeat_interval(self):
9796

9897
# TODO: set log level
9998
# TODO: set log level
99+
100+
@property
101+
def uuid(self):
102+
return self._uuid
103+
104+
@uuid.setter
105+
def uuid(self, uuid):
106+
PNConfiguration.validate_not_empty_string(uuid)
107+
self._uuid = uuid

pubnub/pubnub_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
class PubNubCore:
6767
"""A base class for PubNub Python API implementations"""
68-
SDK_VERSION = "5.5.0"
68+
SDK_VERSION = "6.0.0"
6969
SDK_NAME = "PubNub-Python"
7070

7171
TIMESTAMP_DIVIDER = 1000

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pytest-cov
33
pycryptodomex
44
flake8
55
pytest
6-
pytest-asyncio
6+
pytest-asyncio==0.16.0
77
aiohttp
88
requests
99
cbor2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pubnub',
5-
version='5.5.0',
5+
version='6.0.0',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='[email protected]',

tests/functional/test_fire.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from pubnub.pubnub import PubNub
2-
from pubnub.pnconfiguration import PNConfiguration
32
from pubnub.endpoints.pubsub.fire import Fire
4-
from tests.helper import url_encode
3+
from tests.helper import url_encode, pnconf_copy
54
import json
65

6+
pnconf = pnconf_copy()
77

8-
SUB_KEY = 'sub'
9-
PUB_KEY = 'pub'
8+
SUB_KEY = pnconf.subscribe_key
9+
PUB_KEY = pnconf.publish_key
1010
CHAN = 'chan'
1111
MSG = 'x'
1212
MSG_ENCODED = url_encode(MSG)
@@ -15,11 +15,8 @@
1515

1616

1717
def test_fire():
18-
config = PNConfiguration()
19-
config.subscribe_key = SUB_KEY
20-
config.publish_key = PUB_KEY
21-
config.auth_key = AUTH
22-
fire = PubNub(config).fire()
18+
pnconf.auth_key = AUTH
19+
fire = PubNub(pnconf).fire()
2320

2421
fire.channel(CHAN).message(MSG)
2522
assert fire.build_path() == Fire.FIRE_GET_PATH % (PUB_KEY, SUB_KEY, CHAN, 0, MSG_ENCODED)

tests/functional/test_message_count.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import pytest
22

33
from pubnub.pubnub import PubNub
4-
from pubnub.pnconfiguration import PNConfiguration
54
from pubnub.endpoints.message_count import MessageCount
65
from pubnub.exceptions import PubNubException
6+
from tests.helper import pnconf
77

8-
9-
SUB_KEY = 'bla'
8+
SUB_KEY = pnconf.subscribe_key
109

1110

1211
@pytest.fixture
1312
def mc():
14-
config = PNConfiguration()
15-
config.subscribe_key = SUB_KEY
16-
return PubNub(config).message_counts()
13+
return PubNub(pnconf).message_counts()
1714

1815

1916
def test_single_channel(mc):

tests/functional/test_signal.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import pytest
22

33
from pubnub.pubnub import PubNub
4-
from pubnub.pnconfiguration import PNConfiguration
54
from pubnub.exceptions import PubNubException
65
from pubnub.endpoints.signal import Signal
7-
from tests.helper import url_encode
6+
from tests.helper import url_encode, pnconf_copy
87

9-
10-
SUB_KEY = 'sub'
11-
PUB_KEY = 'pub'
8+
pnconf = pnconf_copy()
9+
SUB_KEY = pnconf.subscribe_key
10+
PUB_KEY = pnconf.publish_key
1211
CHAN = 'chan'
1312
MSG = 'x'
1413
MSG_ENCODED = url_encode(MSG)
1514
AUTH = 'auth'
15+
UUID = 'uuid'
1616

1717

1818
def test_signal():
19-
config = PNConfiguration()
20-
config.subscribe_key = SUB_KEY
21-
config.publish_key = PUB_KEY
22-
config.auth_key = AUTH
23-
signal = PubNub(config).signal()
19+
pnconf.auth_key = AUTH
20+
signal = PubNub(pnconf).signal()
2421

2522
with pytest.raises(PubNubException):
2623
signal.validate_params()

tests/helper.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
pub_key_mock = "pub-c-mock-key"
4242
sub_key_mock = "sub-c-mock-key"
43+
uuid_mock = "uuid-mock"
4344

4445
pub_key_pam = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
4546
sub_key_pam = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
@@ -49,55 +50,66 @@
4950
pnconf.publish_key = pub_key
5051
pnconf.subscribe_key = sub_key
5152
pnconf.enable_subscribe = False
53+
pnconf.uuid = uuid_mock
5254

5355
pnconf_sub = PNConfiguration()
5456
pnconf_sub.publish_key = pub_key
5557
pnconf_sub.subscribe_key = sub_key
58+
pnconf_sub.uuid = uuid_mock
5659

5760
pnconf_enc = PNConfiguration()
5861
pnconf_enc.publish_key = pub_key
5962
pnconf_enc.subscribe_key = sub_key
6063
pnconf_enc.cipher_key = "testKey"
6164
pnconf_enc.enable_subscribe = False
65+
pnconf_enc.uuid = uuid_mock
6266

6367
pnconf_enc_sub = PNConfiguration()
6468
pnconf_enc_sub.publish_key = pub_key
6569
pnconf_enc_sub.subscribe_key = sub_key
6670
pnconf_enc_sub.cipher_key = "testKey"
71+
pnconf_enc_sub.uuid = uuid_mock
6772

6873
pnconf_pam = PNConfiguration()
6974
pnconf_pam.publish_key = pub_key_pam
7075
pnconf_pam.subscribe_key = sub_key_pam
7176
pnconf_pam.secret_key = sec_key_pam
7277
pnconf_pam.enable_subscribe = False
78+
pnconf_pam.uuid = uuid_mock
7379

7480

7581
pnconf_pam_stub = PNConfiguration()
7682
pnconf_pam_stub.publish_key = "pub-stub"
7783
pnconf_pam_stub.subscribe_key = "sub-c-stub"
7884
pnconf_pam_stub.secret_key = "sec-c-stub"
85+
pnconf_pam_stub.uuid = uuid_mock
7986

8087
pnconf_ssl = PNConfiguration()
8188
pnconf_ssl.publish_key = pub_key
8289
pnconf_ssl.subscribe_key = sub_key
8390
pnconf_ssl.ssl = True
91+
pnconf_ssl.uuid = uuid_mock
8492

8593
message_count_config = PNConfiguration()
8694
message_count_config.publish_key = 'demo-36'
8795
message_count_config.subscribe_key = 'demo-36'
8896
message_count_config.origin = 'balancer1g.bronze.aws-pdx-1.ps.pn'
97+
message_count_config.uuid = uuid_mock
8998

90-
objects_config = PNConfiguration()
91-
objects_config.publish_key = 'demo'
92-
objects_config.subscribe_key = 'demo'
99+
pnconf_demo = PNConfiguration()
100+
pnconf_demo.publish_key = 'demo'
101+
pnconf_demo.subscribe_key = 'demo'
102+
pnconf_demo.uuid = uuid_mock
93103

94104
file_upload_config = PNConfiguration()
95105
file_upload_config.publish_key = pub_key_mock
96106
file_upload_config.subscribe_key = sub_key_mock
107+
file_upload_config.uuid = uuid_mock
97108

98109
mocked_config = PNConfiguration()
99110
mocked_config.publish_key = pub_key_mock
100111
mocked_config.subscribe_key = sub_key_mock
112+
mocked_config.uuid = uuid_mock
101113

102114
hardcoded_iv_config = PNConfiguration()
103115
hardcoded_iv_config.use_random_initialization_vector = False
@@ -154,8 +166,8 @@ def pnconf_mc_copy():
154166
return copy(message_count_config)
155167

156168

157-
def pnconf_obj_copy():
158-
return copy(objects_config)
169+
def pnconf_demo_copy():
170+
return copy(pnconf_demo)
159171

160172

161173
sdk_name = "Python-UnitTest"

0 commit comments

Comments
 (0)