Skip to content

Commit 4b4776e

Browse files
committed
Acceptance tests for files
cleanup + add acceptance test action
1 parent 6d5f4e6 commit 4b4776e

File tree

16 files changed

+146
-911
lines changed

16 files changed

+146
-911
lines changed

.github/workflows/run-tests.yml

+4
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,13 @@ jobs:
7474
cp sdk-specifications/features/access/authorization-failure-reporting.feature tests/acceptance/pam
7575
cp sdk-specifications/features/access/grant-token.feature tests/acceptance/pam
7676
cp sdk-specifications/features/access/revoke-token.feature tests/acceptance/pam
77+
cp sdk-specifications/features/files/file-upload-to-space.feature tests/acceptance/files
78+
cp sdk-specifications/features/history/history-vsp.feature tests/acceptance/history
7779
7880
sudo pip3 install -r requirements-dev.txt
7981
behave --junit tests/acceptance/pam
82+
behave --junit tests/acceptance/files
83+
behave --junit tests/acceptance/history
8084
- name: Expose acceptance tests reports
8185
uses: actions/upload-artifact@v3
8286
if: always()

pubnub/endpoints/file_operations/send_file.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pubnub.models.consumer.message_type import PNMessageType
1010
from typing import Union
1111

12+
1213
class SendFileNative(FileOperationEndpoint, TimeTokenOverrideMixin):
1314
def __init__(self, pubnub):
1415
super(SendFileNative, self).__init__(pubnub)
@@ -71,8 +72,6 @@ def is_compressable(self):
7172
return True
7273

7374
def custom_params(self):
74-
import ipdb
75-
ipdb.set_trace()
7675
params = {}
7776
if self._message_type is not None:
7877
params['type'] = str(self._message_type)
@@ -158,7 +157,9 @@ def sync(self):
158157
ttl(self._ttl).\
159158
replicate(self._replicate).\
160159
ptto(self._ptto).\
161-
cipher_key(self._cipher_key).sync()
160+
cipher_key(self._cipher_key).\
161+
message_type(self._message_type).\
162+
space_id(self._space_id).sync()
162163

163164
response_envelope.result.timestamp = publish_file_response.result.timestamp
164165
return response_envelope

pubnub/models/consumer/history.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def from_json(cls, json_input, include_message_actions=False, include_message_ty
9090

9191
if include_message_type:
9292
message.message_type = PNMessageType.from_response(
93-
user_type=item['type'] if 'type' in item.keys() else None,
94-
internal_type=item['message_type'])
93+
message_type=item['type'] if 'type' in item.keys() else None,
94+
pn_message_type=item['message_type'])
9595

9696
if include_space_id:
9797
message.space_id = item['space_id']
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class PNMessageType:
2-
_internal_type: str = None
3-
_user_type: str = None
2+
pn_message_type: str = None
3+
message_type: str = None
44
_type_mapping = {
55
'None': 'message',
66
'0': 'message',
@@ -10,18 +10,18 @@ class PNMessageType:
1010
'4': 'file',
1111
}
1212

13-
def __init__(self, user_type: str = None) -> None:
14-
self._user_type = user_type
13+
def __init__(self, message_type: str = None) -> None:
14+
self.message_type = message_type
1515

16-
def set_internal_type(self, internal_type: str):
17-
self._internal_type = self._type_mapping[str(internal_type)]
16+
def set_pn_message_type(self, pn_message_type: str):
17+
self.pn_message_type = self._type_mapping[str(pn_message_type)]
1818
return self
1919

20-
def from_response(user_type: str = None, internal_type: str = None):
21-
return PNMessageType(user_type).set_internal_type(internal_type)
20+
def from_response(message_type: str = None, pn_message_type: str = None):
21+
return PNMessageType(message_type).set_pn_message_type(pn_message_type)
2222

2323
def __str__(self) -> str:
24-
return self._user_type if self._user_type is not None else str(self._internal_type)
24+
return self.message_type if self.message_type is not None else str(self.pn_message_type)
2525

2626
def toJSON(self) -> str:
2727
return str(self)

tests/acceptance/files/environment.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import requests
2+
3+
from tests.acceptance import MOCK_SERVER_URL, CONTRACT_INIT_ENDPOINT, CONTRACT_EXPECT_ENDPOINT
4+
5+
6+
def before_scenario(context, feature):
7+
for tag in feature.tags:
8+
if "contract" in tag:
9+
_, contract_name = tag.split("=")
10+
response = requests.get(MOCK_SERVER_URL + CONTRACT_INIT_ENDPOINT + contract_name)
11+
assert response
12+
13+
14+
def after_scenario(context, feature):
15+
for tag in feature.tags:
16+
if "contract" in tag:
17+
response = requests.get(MOCK_SERVER_URL + CONTRACT_EXPECT_ENDPOINT)
18+
assert response
19+
20+
response_json = response.json()
21+
22+
assert not response_json["expectations"]["failed"]
23+
assert not response_json["expectations"]["pending"]

tests/acceptance/files/steps/steps.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from behave import given, when, then
2+
from pubnub.exceptions import PubNubException
3+
from tests.helper import pnconf_demo_copy
4+
from pubnub.pubnub import PubNub
5+
6+
7+
@given(u'the demo keyset')
8+
def step_impl(context):
9+
config = pnconf_demo_copy()
10+
config.origin = "localhost:8090"
11+
config.ssl = False
12+
pubnub_instance = PubNub(config)
13+
context.peer = pubnub_instance
14+
15+
16+
@when(u'I send a file with \'{space_id}\' space id and \'{message_type}\' message type')
17+
def step_impl(context, space_id, message_type):
18+
try:
19+
with open('tests/acceptance/files/test.txt', 'rb') as file_object:
20+
envelope = context.peer.send_file().channel('test').message('test').should_store(True).ttl(200). \
21+
file_name('test.txt').file_object(file_object).space_id(space_id).message_type(message_type).sync()
22+
context.status = envelope.status
23+
context.result = envelope.result
24+
except PubNubException as error:
25+
context.status = error
26+
27+
28+
@then(u'I receive a successful response')
29+
def step_impl(context):
30+
assert context.status.error is None
31+
assert 'file_id' in context.result.__dict__
32+
33+
34+
@then(u'I receive an error response')
35+
def step_impl(context):
36+
assert type(context.status) == PubNubException
37+
38+
39+
@when(u'I list files')
40+
def step_impl(context):
41+
envelope = context.peer.list_files().channel('test').sync()
42+
context.status = envelope.status
43+
context.result = envelope.result
44+
45+
46+
@then(u'I receive successful response')
47+
def step_impl(context):
48+
assert type(context.status) is PubNubException or context.status.error is None
49+
50+
51+
@when(u'I publish file message')
52+
def step_impl(context):
53+
try:
54+
envelope = context.peer.publish_file_message().channel('test').message('test').should_store(True).ttl(200).\
55+
file_name('test.txt').file_id('1338').sync()
56+
context.status = envelope.status
57+
context.result = envelope.result
58+
except PubNubException as error:
59+
context.status = error
60+
61+
62+
@then(u'I receive error response')
63+
def step_impl(context):
64+
assert type(context.status) is PubNubException or context.status.error is True
65+
66+
67+
@when(u'I delete file')
68+
def step_impl(context):
69+
envelope = context.peer.delete_file().channel('test').file_name('test.txt').file_id('1338').sync()
70+
context.status = envelope.status
71+
context.result = envelope.result
72+
73+
74+
@when(u'I download file')
75+
def step_impl(context):
76+
envelope = context.peer.get_file_url().channel('test').file_name('test.txt').file_id('1338').sync()
77+
context.status = envelope.status
78+
context.result = envelope.result
79+
80+
81+
@when(u'I send file')
82+
def step_impl(context):
83+
try:
84+
with open('tests/acceptance/files/test.txt', 'rb') as file_object:
85+
envelope = context.peer.send_file().channel('test').message('test').should_store(True).ttl(200). \
86+
file_name('test.txt').file_object(file_object).sync()
87+
context.status = envelope.status
88+
context.result = envelope.result
89+
except PubNubException as error:
90+
context.status = error

tests/acceptance/files/test.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Lorem Ipsum Dolor Sit Ament Enim
2+
TG9yZW0gSXBzdW0gRG9sb3IgU2l0IEFtZW50IEVuaW0=
3+
VEc5eVpXMGdTWEJ6ZFcwZ1JHOXNiM0lnVTJsMElFRnRaVzUwSUVWdWFXMD0=

tests/integrational/fixtures/asyncio/subscription/cg_join_leave.yaml

-133
This file was deleted.

0 commit comments

Comments
 (0)