Skip to content

Commit dc1a8e8

Browse files
author
Sebastian Molenda
authored
some test fixing (#200)
* some test fixing * organization * remove unused file
1 parent 686b4f4 commit dc1a8e8

38 files changed

+1608
-576
lines changed

.github/workflows/commands-handler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Process command
1313
if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true
1414
runs-on:
15-
group: Default
15+
group: organization/Default
1616
steps:
1717
- name: Check referred user
1818
id: user-check

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Check release required
1111
if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true
1212
runs-on:
13-
group: Default
13+
group: organization/Default
1414
outputs:
1515
release: ${{ steps.check.outputs.ready }}
1616
steps:
@@ -31,7 +31,7 @@ jobs:
3131
needs: check-release
3232
if: needs.check-release.outputs.release == 'true'
3333
runs-on:
34-
group: Default
34+
group: organization/Default
3535
steps:
3636
- name: Checkout repository
3737
uses: actions/checkout@v4

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
tests:
2222
name: Integration and Unit tests
2323
runs-on:
24-
group: Default
24+
group: organization/Default
2525
strategy:
2626
max-parallel: 1
2727
fail-fast: true
@@ -54,7 +54,7 @@ jobs:
5454
acceptance-tests:
5555
name: Acceptance tests
5656
runs-on:
57-
group: Default
57+
group: organization/Default
5858
timeout-minutes: 5
5959
steps:
6060
- name: Checkout project
@@ -103,7 +103,7 @@ jobs:
103103
name: Tests
104104
needs: [tests, acceptance-tests]
105105
runs-on:
106-
group: Default
106+
group: organization/Default
107107
steps:
108108
- name: Tests summary
109109
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"

.github/workflows/run-validations.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
name: Lint project
88
runs-on:
9-
group: Default
9+
group: organization/Default
1010
steps:
1111
- name: Checkout project
1212
uses: actions/checkout@v4
@@ -24,7 +24,7 @@ jobs:
2424
pubnub-yml:
2525
name: "Validate .pubnub.yml"
2626
runs-on:
27-
group: Default
27+
group: organization/Default
2828
steps:
2929
- name: Checkout project
3030
uses: actions/checkout@v4
@@ -46,7 +46,7 @@ jobs:
4646
name: Validations
4747
needs: [pubnub-yml, lint]
4848
runs-on:
49-
group: Default
49+
group: organization/Default
5050
steps:
5151
- name: Validations summary
5252
run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed"

pubnub/pubnub_asyncio.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ async def close_pending_tasks(self, tasks):
6262
await asyncio.sleep(0.1)
6363

6464
async def create_session(self):
65-
self._session = aiohttp.ClientSession(
66-
loop=self.event_loop,
67-
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
68-
connector=self._connector
69-
)
65+
if not self._session:
66+
self._session = aiohttp.ClientSession(
67+
loop=self.event_loop,
68+
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
69+
connector=self._connector
70+
)
7071

7172
async def close_session(self):
7273
if self._session is not None:
@@ -76,12 +77,7 @@ async def set_connector(self, cn):
7677
await self._session.close()
7778

7879
self._connector = cn
79-
80-
self._session = aiohttp.ClientSession(
81-
loop=self.event_loop,
82-
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
83-
connector=self._connector
84-
)
80+
await self.create_session()
8581

8682
async def stop(self):
8783
if self._subscription_manager:

tests/integrational/asyncio/test_fire.py

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

3-
from tests.helper import pnconf_copy
3+
from tests.helper import pnconf_env_copy
44
from tests.integrational.vcr_helper import pn_vcr
55
from pubnub.pubnub_asyncio import PubNubAsyncio, AsyncioEnvelope
66
from pubnub.models.consumer.pubsub import PNFireResult
77
from pubnub.models.consumer.common import PNStatus
88

99

1010
@pn_vcr.use_cassette(
11-
'tests/integrational/fixtures/asyncio/publish/fire_get.yaml',
11+
'tests/integrational/fixtures/asyncio/publish/fire_get.json', serializer='pn_json',
1212
filter_query_parameters=['uuid', 'seqn', 'pnsdk']
1313
)
1414
@pytest.mark.asyncio
1515
async def test_single_channel(event_loop):
16-
config = pnconf_copy()
16+
config = pnconf_env_copy()
1717
config.enable_subscribe = False
1818
pn = PubNubAsyncio(config, custom_event_loop=event_loop)
1919
chan = 'unique_sync'

tests/integrational/asyncio/test_publish.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pubnub.models.consumer.common import PNStatus
1010
from pubnub.models.consumer.pubsub import PNPublishResult
1111
from pubnub.pubnub_asyncio import PubNubAsyncio, AsyncioEnvelope, PubNubAsyncioException
12-
from tests.helper import pnconf_copy, pnconf_enc_copy, pnconf_pam_copy
12+
from tests.helper import pnconf_enc_env_copy, pnconf_pam_env_copy, pnconf_env_copy
1313
from tests.integrational.vcr_helper import pn_vcr
1414

1515
pn.set_stream_logger('pubnub', logging.DEBUG)
@@ -47,12 +47,12 @@ async def assert_success_publish_post(pubnub, msg):
4747

4848

4949
@pn_vcr.use_cassette(
50-
'tests/integrational/fixtures/asyncio/publish/mixed_via_get.yaml',
51-
filter_query_parameters=['uuid', 'seqn', 'pnsdk']
50+
'tests/integrational/fixtures/asyncio/publish/mixed_via_get.json', serializer='pn_json',
51+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub']
5252
)
5353
@pytest.mark.asyncio
5454
async def test_publish_mixed_via_get(event_loop):
55-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
55+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
5656
await asyncio.gather(
5757
asyncio.ensure_future(assert_success_publish_get(pubnub, "hi")),
5858
asyncio.ensure_future(assert_success_publish_get(pubnub, 5)),
@@ -64,24 +64,24 @@ async def test_publish_mixed_via_get(event_loop):
6464

6565

6666
@pn_vcr.use_cassette(
67-
'tests/integrational/fixtures/asyncio/publish/object_via_get.yaml',
67+
'tests/integrational/fixtures/asyncio/publish/object_via_get.json', serializer='pn_json',
6868
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
6969
match_on=['method', 'scheme', 'host', 'port', 'object_in_path', 'query']
7070
)
7171
@pytest.mark.asyncio
7272
async def test_publish_object_via_get(event_loop):
73-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
73+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
7474
await asyncio.ensure_future(assert_success_publish_get(pubnub, {"name": "Alex", "online": True}))
7575

7676
await pubnub.stop()
7777

7878

7979
@pn_vcr.use_cassette(
80-
'tests/integrational/fixtures/asyncio/publish/mixed_via_post.yaml',
81-
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
80+
'tests/integrational/fixtures/asyncio/publish/mixed_via_post.json', serializer='pn_json',
81+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
8282
@pytest.mark.asyncio
8383
async def test_publish_mixed_via_post(event_loop):
84-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
84+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
8585
await asyncio.gather(
8686
asyncio.ensure_future(assert_success_publish_post(pubnub, "hi")),
8787
asyncio.ensure_future(assert_success_publish_post(pubnub, 5)),
@@ -92,24 +92,24 @@ async def test_publish_mixed_via_post(event_loop):
9292

9393

9494
@pn_vcr.use_cassette(
95-
'tests/integrational/fixtures/asyncio/publish/object_via_post.yaml',
95+
'tests/integrational/fixtures/asyncio/publish/object_via_post.json', serializer='pn_json',
9696
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
9797
match_on=['method', 'scheme', 'host', 'port', 'path', 'query', 'object_in_body'])
9898
@pytest.mark.asyncio
9999
async def test_publish_object_via_post(event_loop):
100-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
100+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
101101
await asyncio.ensure_future(assert_success_publish_post(pubnub, {"name": "Alex", "online": True}))
102102

103103
await pubnub.stop()
104104

105105

106106
@pn_vcr.use_cassette(
107-
'tests/integrational/fixtures/asyncio/publish/mixed_via_get_encrypted.yaml',
108-
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
107+
'tests/integrational/fixtures/asyncio/publish/mixed_via_get_encrypted.json', serializer='pn_json',
108+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
109109
@pytest.mark.asyncio
110110
async def test_publish_mixed_via_get_encrypted(event_loop):
111111
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
112-
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
112+
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
113113
await asyncio.gather(
114114
asyncio.ensure_future(assert_success_publish_get(pubnub, "hi")),
115115
asyncio.ensure_future(assert_success_publish_get(pubnub, 5)),
@@ -120,28 +120,28 @@ async def test_publish_mixed_via_get_encrypted(event_loop):
120120

121121

122122
@pn_vcr.use_cassette(
123-
'tests/integrational/fixtures/asyncio/publish/object_via_get_encrypted.yaml',
123+
'tests/integrational/fixtures/asyncio/publish/object_via_get_encrypted.json', serializer='pn_json',
124124
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
125125
match_on=['host', 'method', 'query']
126126
)
127127
@pytest.mark.asyncio
128128
async def test_publish_object_via_get_encrypted(event_loop):
129129
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
130-
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
130+
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
131131
await asyncio.ensure_future(assert_success_publish_get(pubnub, {"name": "Alex", "online": True}))
132132

133133
await pubnub.stop()
134134

135135

136136
@pn_vcr.use_cassette(
137-
'tests/integrational/fixtures/asyncio/publish/mixed_via_post_encrypted.yaml',
138-
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
137+
'tests/integrational/fixtures/asyncio/publish/mixed_via_post_encrypted.json', serializer='pn_json',
138+
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
139139
match_on=['method', 'path', 'query', 'body']
140140
)
141141
@pytest.mark.asyncio
142142
async def test_publish_mixed_via_post_encrypted(event_loop):
143143
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
144-
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
144+
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
145145
await asyncio.gather(
146146
asyncio.ensure_future(assert_success_publish_post(pubnub, "hi")),
147147
asyncio.ensure_future(assert_success_publish_post(pubnub, 5)),
@@ -153,38 +153,38 @@ async def test_publish_mixed_via_post_encrypted(event_loop):
153153

154154

155155
@pn_vcr.use_cassette(
156-
'tests/integrational/fixtures/asyncio/publish/object_via_post_encrypted.yaml',
156+
'tests/integrational/fixtures/asyncio/publish/object_via_post_encrypted.json', serializer='pn_json',
157157
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
158158
match_on=['method', 'path', 'query']
159159
)
160160
@pytest.mark.asyncio
161161
async def test_publish_object_via_post_encrypted(event_loop):
162162
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
163-
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
163+
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
164164
await asyncio.ensure_future(assert_success_publish_post(pubnub, {"name": "Alex", "online": True}))
165165

166166
await pubnub.stop()
167167

168168

169169
@pytest.mark.asyncio
170170
async def test_error_missing_message(event_loop):
171-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
171+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
172172
await assert_client_side_error(pubnub.publish().channel(ch).message(None), "Message missing")
173173

174174
await pubnub.stop()
175175

176176

177177
@pytest.mark.asyncio
178178
async def test_error_missing_channel(event_loop):
179-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
179+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
180180
await assert_client_side_error(pubnub.publish().channel("").message("hey"), "Channel missing")
181181

182182
await pubnub.stop()
183183

184184

185185
@pytest.mark.asyncio
186186
async def test_error_non_serializable(event_loop):
187-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
187+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
188188

189189
def method():
190190
pass
@@ -194,23 +194,23 @@ def method():
194194

195195

196196
@pn_vcr.use_cassette(
197-
'tests/integrational/fixtures/asyncio/publish/meta_object.yaml',
197+
'tests/integrational/fixtures/asyncio/publish/meta_object.json', serializer='pn_json',
198198
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
199199
match_on=['host', 'method', 'path', 'meta_object_in_query'])
200200
@pytest.mark.asyncio
201201
async def test_publish_with_meta(event_loop):
202-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
202+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
203203

204204
await assert_success_await(pubnub.publish().channel(ch).message("hey").meta({'a': 2, 'b': 'qwer'}))
205205
await pubnub.stop()
206206

207207

208208
@pn_vcr.use_cassette(
209-
'tests/integrational/fixtures/asyncio/publish/do_not_store.yaml',
209+
'tests/integrational/fixtures/asyncio/publish/do_not_store.json', serializer='pn_json',
210210
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
211211
@pytest.mark.asyncio
212212
async def test_publish_do_not_store(event_loop):
213-
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
213+
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
214214

215215
await assert_success_await(pubnub.publish().channel(ch).message("hey").should_store(False))
216216
await pubnub.stop()
@@ -225,11 +225,11 @@ async def assert_server_side_error_yield(pub, expected_err_msg):
225225

226226

227227
@pn_vcr.use_cassette(
228-
'tests/integrational/fixtures/asyncio/publish/invalid_key.yaml',
228+
'tests/integrational/fixtures/asyncio/publish/invalid_key.json', serializer='pn_json',
229229
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
230230
@pytest.mark.asyncio
231231
async def test_error_invalid_key(event_loop):
232-
pnconf = pnconf_pam_copy()
232+
pnconf = pnconf_pam_env_copy()
233233

234234
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
235235

@@ -238,11 +238,11 @@ async def test_error_invalid_key(event_loop):
238238

239239

240240
@pn_vcr.use_cassette(
241-
'tests/integrational/fixtures/asyncio/publish/not_permitted.yaml',
241+
'tests/integrational/fixtures/asyncio/publish/not_permitted.json', serializer='pn_json',
242242
filter_query_parameters=['uuid', 'seqn', 'signature', 'timestamp', 'pnsdk'])
243243
@pytest.mark.asyncio
244244
async def test_not_permitted(event_loop):
245-
pnconf = pnconf_pam_copy()
245+
pnconf = pnconf_pam_env_copy()
246246
pnconf.secret_key = None
247247
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)
248248

@@ -252,7 +252,7 @@ async def test_not_permitted(event_loop):
252252

253253
@pytest.mark.asyncio
254254
async def test_publish_super_admin_call(event_loop):
255-
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
255+
pubnub = PubNubAsyncio(pnconf_pam_env_copy(), custom_event_loop=event_loop)
256256

257257
await pubnub.publish().channel(ch).message("hey").future()
258258
await pubnub.publish().channel("f#!|oo.bar").message("hey^&#$").should_store(True).meta({

tests/integrational/asyncio/test_subscribe.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ async def test_cg_join_leave():
336336
assert prs_envelope.uuid == pubnub_listener.uuid
337337
assert prs_envelope.channel == ch
338338
assert prs_envelope.subscription == gr
339+
await asyncio.sleep(2)
339340

340341
pubnub.add_listener(callback_messages)
341342
pubnub.subscribe().channel_groups(gr).execute()
@@ -349,6 +350,7 @@ async def test_cg_join_leave():
349350
assert prs_envelope.uuid == pubnub.uuid
350351
assert prs_envelope.channel == ch
351352
assert prs_envelope.subscription == gr
353+
await asyncio.sleep(2)
352354

353355
pubnub.unsubscribe().channel_groups(gr).execute()
354356

@@ -363,6 +365,7 @@ async def test_cg_join_leave():
363365
assert prs_envelope.subscription == gr
364366

365367
pubnub_listener.unsubscribe().channel_groups(gr).execute()
368+
await asyncio.sleep(2)
366369

367370
# with EE you don't have to wait for disconnect
368371
if isinstance(pubnub._subscription_manager, AsyncioSubscriptionManager):

0 commit comments

Comments
 (0)