Skip to content

Commit 18fdf5c

Browse files
committed
test(acceptance): define missing steps
1 parent fd6754b commit 18fdf5c

4 files changed

Lines changed: 103 additions & 7 deletions

File tree

pytest.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/acceptance/pam/steps/then_steps.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
22
from behave import then
3+
from soupsieve.util import lower
4+
35
from pubnub.exceptions import PubNubException
46

57

@@ -18,6 +20,11 @@ def step_impl(context, channel):
1820
context.token_resource = context.parsed_token["resources"]["channels"].get(channel.strip("'"))
1921
assert context.token_resource
2022

23+
@then("token {data_type} permission {permission}")
24+
def step_impl(context, data_type, permission):
25+
assert context.token_resource
26+
assert context.token_resource[lower(permission)] == True
27+
2128

2229
@then("the token contains the authorized UUID {test_uuid}")
2330
def step_impl(context, test_uuid):
@@ -80,6 +87,75 @@ def step_impl(context):
8087
context.pam_call_error = json.loads(context.pam_call_result._errormsg)
8188

8289

90+
@then("the error status code is {error_code}")
91+
def step_impl(context, error_code):
92+
assert context.pam_call_error['status'] == int(error_code)
93+
94+
95+
@then("the auth error message is '{error_message}'")
96+
@then("the error message is '{error_message}'")
97+
def step_impl(context, error_message):
98+
if 'message' in context.pam_call_error:
99+
assert context.pam_call_error['message'] == error_message
100+
elif 'error' in context.pam_call_error and 'message' in context.pam_call_error['error']:
101+
assert context.pam_call_error['error']['message'] == error_message
102+
else:
103+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
104+
105+
106+
@then("the error detail message is not empty")
107+
def step_impl(context, details_message):
108+
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
109+
assert len(context.pam_call_error['error']['details']) > 0
110+
assert 'message' in context.pam_call_error['error']['details'][0]
111+
assert len(context.pam_call_error['error']['details'][0]['message']) > 0
112+
else:
113+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
114+
115+
116+
@then("the error detail message is '{details_message}'")
117+
def step_impl(context, details_message):
118+
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
119+
assert len(context.pam_call_error['error']['details']) > 0
120+
assert 'message' in context.pam_call_error['error']['details'][0]
121+
assert context.pam_call_error['error']['details'][0]['message'] == details_message
122+
else:
123+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
124+
125+
126+
@then("the error detail location is '{details_location}'")
127+
def step_impl(context, details_location):
128+
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
129+
assert len(context.pam_call_error['error']['details']) > 0
130+
assert 'location' in context.pam_call_error['error']['details'][0]
131+
assert context.pam_call_error['error']['details'][0]['location'] == details_location
132+
else:
133+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
134+
135+
136+
@then("the error detail location type is '{details_location_type}'")
137+
def step_impl(context, details_location_type):
138+
if 'error' in context.pam_call_error and 'details' in context.pam_call_error['error']:
139+
assert len(context.pam_call_error['error']['details']) > 0
140+
assert 'locationType' in context.pam_call_error['error']['details'][0]
141+
assert context.pam_call_error['error']['details'][0]['locationType'] == details_location_type
142+
else:
143+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
144+
145+
146+
@then("the error service is '{error_service}'")
147+
def step_impl(context, error_service):
148+
assert context.pam_call_error['service'] == error_service
149+
150+
151+
@then("the error source is '{error_source}'")
152+
def step_impl(context, error_source):
153+
if 'error' in context.pam_call_error and 'source' in context.pam_call_error['error']:
154+
assert context.pam_call_error['error']['source'] == error_source
155+
else:
156+
raise AssertionError("Unexpected payload: {}".format(context.pam_call_error))
157+
158+
83159
@then("the result is successful")
84160
def step_impl(context):
85161
assert context.publish_result.result.timetoken

tests/integrational/asyncio/test_change_uuid.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import pytest
23

34
from pubnub.models.consumer.signal import PNSignalResult
@@ -52,12 +53,21 @@ async def test_change_uuid_no_lock():
5253
assert isinstance(envelope.status, PNStatus)
5354

5455

55-
def test_uuid_validation_at_init():
56+
@pytest.fixture
57+
def event_loop():
58+
loop = asyncio.new_event_loop()
59+
try:
60+
yield loop
61+
finally:
62+
loop.run_until_complete(asyncio.sleep(0))
63+
loop.close()
64+
65+
def test_uuid_validation_at_init(event_loop):
5666
with pytest.raises(AssertionError) as exception:
5767
pnconf = PNConfiguration()
5868
pnconf.publish_key = "demo"
5969
pnconf.subscribe_key = "demo"
60-
PubNubAsyncio(pnconf)
70+
PubNubAsyncio(pnconf, custom_event_loop=event_loop)
6171

6272
assert str(exception.value) == 'UUID missing or invalid type'
6373

tests/integrational/asyncio/test_message_count.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import pytest
23

34
from pubnub.pubnub_asyncio import PubNubAsyncio
@@ -7,13 +8,24 @@
78
from tests.helper import pnconf_mc_copy
89
from tests.integrational.vcr_helper import pn_vcr
910

11+
@pytest.fixture
12+
def event_loop():
13+
loop = asyncio.new_event_loop()
14+
try:
15+
yield loop
16+
finally:
17+
loop.run_until_complete(asyncio.sleep(0))
18+
loop.close()
1019

1120
@pytest.fixture
12-
def pn():
21+
def pn(event_loop):
1322
config = pnconf_mc_copy()
1423
config.enable_subscribe = False
15-
pn = PubNubAsyncio(config)
16-
yield pn
24+
pn = PubNubAsyncio(config, custom_event_loop=event_loop)
25+
try:
26+
yield pn
27+
finally:
28+
event_loop.run_until_complete(pn.stop())
1729

1830

1931
@pn_vcr.use_cassette(

0 commit comments

Comments
 (0)