|
| 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 |
0 commit comments