def test_super_call(self): ch1 = "state-tornado-ch1" ch2 = "state-tornado-ch2" pnconf = pnconf_pam_copy() pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop) pubnub.config.uuid = 'test-state-tornado-uuid-|.*$' state = {"name": "Alex", "count": 5} env = yield pubnub.set_state() \ .channels([ch1, ch2]) \ .state(state) \ .future() assert env.result.state['name'] == "Alex" assert env.result.state['count'] == 5 env = yield pubnub.get_state() \ .channels([ch1, ch2]) \ .future() assert env.result.channels[ch1]['name'] == "Alex" assert env.result.channels[ch2]['name'] == "Alex" assert env.result.channels[ch1]['count'] == 5 assert env.result.channels[ch2]['count'] == 5 pubnub.stop() self.stop()
def test_single_channel_group(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" cg = "test-pam-asyncio-cg" env = (yield from pubnub.grant() .channel_groups(cg) .write(True) .read(True) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.level == 'channel-group' assert env.result.groups[cg].read_enabled == 1 assert env.result.groups[cg].write_enabled == 1 assert env.result.groups[cg].manage_enabled == 0 env = (yield from pubnub.audit() .channel_groups(cg) .future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.level == 'channel-group' assert env.result.groups[cg].read_enabled == 1 assert env.result.groups[cg].write_enabled == 1 assert env.result.groups[cg].manage_enabled == 0 pubnub.stop()
def test_not_permitted(self): ch = "history-native-sync-ch" pubnub = PubNub(pnconf_pam_copy()) pubnub.config.uuid = "history-native-sync-uuid" with pytest.raises(PubNubException): pubnub.history().channel(ch).count(5).sync()
def test_single_channel_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" ch = "test-pam-asyncio-ch" auth = "test-pam-asyncio-auth" env = (yield from pubnub.grant() .channels(ch) .write(True) .read(True) .auth_keys(auth) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch].auth_keys[auth].read_enabled == 1 assert env.result.channels[ch].auth_keys[auth].write_enabled == 1 assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0 env = (yield from pubnub.audit() .channels(ch) .auth_keys(auth) .future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.channels[ch].auth_keys[auth].read_enabled == 1 assert env.result.channels[ch].auth_keys[auth].write_enabled == 1 assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0 pubnub.stop()
def test_multiple_channel_groups_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" gr1 = "test-pam-asyncio-cg1" gr2 = "test-pam-asyncio-cg2" auth = "test-pam-asyncio-auth" env = (yield from pubnub.grant() .channel_groups([gr1, gr2]) .write(True) .read(True) .auth_keys(auth) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.groups[gr1].auth_keys[auth].read_enabled is True assert env.result.groups[gr2].auth_keys[auth].read_enabled is True assert env.result.groups[gr1].auth_keys[auth].write_enabled is True assert env.result.groups[gr2].auth_keys[auth].write_enabled is True assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False env = (yield from pubnub.audit() .channel_groups([gr1, gr2]) .future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.groups[gr1].auth_keys[auth].read_enabled is True assert env.result.groups[gr2].auth_keys[auth].read_enabled is True assert env.result.groups[gr1].auth_keys[auth].write_enabled is True assert env.result.groups[gr2].auth_keys[auth].write_enabled is True assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False pubnub.stop()
def test_global_level(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" env = (yield from pubnub.grant().write(True).read(True).future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert len(env.result.channels) == 0 assert len(env.result.groups) == 0 assert env.result.read_enabled is True assert env.result.write_enabled is True assert env.result.manage_enabled is False env = (yield from pubnub.audit().future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert len(env.result.channels) >= 0 assert len(env.result.groups) >= 0 assert env.result.read_enabled is True assert env.result.write_enabled is True assert env.result.manage_enabled is False env = yield from pubnub.revoke().future() assert isinstance(env.result, PNAccessManagerGrantResult) assert len(env.result.channels) == 0 assert len(env.result.groups) == 0 assert env.result.read_enabled is False assert env.result.write_enabled is False assert env.result.manage_enabled is False pubnub.stop()
def test_multiple_channels(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" ch1 = "test-pam-asyncio-ch1" ch2 = "test-pam-asyncio-ch2" env = (yield from pubnub.grant().channels([ch1, ch2]).write(True).read(True).future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch1].read_enabled is True assert env.result.channels[ch2].read_enabled is True assert env.result.channels[ch1].write_enabled is True assert env.result.channels[ch2].write_enabled is True assert env.result.channels[ch1].manage_enabled is False assert env.result.channels[ch2].manage_enabled is False env = (yield from pubnub.audit().channels([ch1, ch2]).future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.channels[ch1].read_enabled is True assert env.result.channels[ch2].read_enabled is True assert env.result.channels[ch1].write_enabled is True assert env.result.channels[ch2].write_enabled is True assert env.result.channels[ch1].manage_enabled is False assert env.result.channels[ch2].manage_enabled is False pubnub.stop()
def test_multiple_channel_groups_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" gr1 = "test-pam-asyncio-cg1" gr2 = "test-pam-asyncio-cg2" auth = "test-pam-asyncio-auth" env = (yield from pubnub.grant().channel_groups( [gr1, gr2]).write(True).read(True).auth_keys(auth).future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.groups[gr1].auth_keys[auth].read_enabled is True assert env.result.groups[gr2].auth_keys[auth].read_enabled is True assert env.result.groups[gr1].auth_keys[auth].write_enabled is True assert env.result.groups[gr2].auth_keys[auth].write_enabled is True assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False env = (yield from pubnub.audit().channel_groups([gr1, gr2]).future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.groups[gr1].auth_keys[auth].read_enabled is True assert env.result.groups[gr2].auth_keys[auth].read_enabled is True assert env.result.groups[gr1].auth_keys[auth].write_enabled is True assert env.result.groups[gr2].auth_keys[auth].write_enabled is True assert env.result.groups[gr1].auth_keys[auth].manage_enabled is False assert env.result.groups[gr2].auth_keys[auth].manage_enabled is False pubnub.stop()
async def test_error_invalid_key(event_loop): pnconf = pnconf_pam_copy() pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) await assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "Invalid Key") await pubnub.stop()
def test_super_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) ch = "channel-groups-torna|do-ch" gr = "channel-groups-torna|do-cg" pubnub.config.auth = "h.e|l%l,0" # add env = yield from pubnub.add_channel_to_channel_group() \ .channels(ch).channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsAddChannelResult) # list env = yield from pubnub.list_channels_in_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsListResult) # remove channel env = yield from pubnub.remove_channel_from_channel_group().channel_group(gr).channels(ch).future() assert isinstance(env.result, PNChannelGroupsRemoveChannelResult) # remove group env = yield from pubnub.remove_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsRemoveGroupResult) # list env = yield from pubnub.list_channels_in_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsListResult) pubnub.stop()
def test_not_permitted(event_loop): pnconf = pnconf_pam_copy() pnconf.secret_key = None pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) yield from assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "HTTP Client Error (403") pubnub.stop()
async def test_super_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) ch = "channel-groups-torna|do-ch" gr = "channel-groups-torna|do-cg" pubnub.config.auth = "h.e|l%l,0" # add env = await pubnub.add_channel_to_channel_group() \ .channels(ch).channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsAddChannelResult) # list env = await pubnub.list_channels_in_channel_group().channel_group( gr).future() assert isinstance(env.result, PNChannelGroupsListResult) # remove channel env = await pubnub.remove_channel_from_channel_group().channel_group( gr).channels(ch).future() assert isinstance(env.result, PNChannelGroupsRemoveChannelResult) # remove group env = await pubnub.remove_channel_group().channel_group(gr).future() assert isinstance(env.result, PNChannelGroupsRemoveGroupResult) # list env = await pubnub.list_channels_in_channel_group().channel_group( gr).future() assert isinstance(env.result, PNChannelGroupsListResult) pubnub.stop()
def test_multiple_channels(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" ch1 = "test-pam-asyncio-ch1" ch2 = "test-pam-asyncio-ch2" env = (yield from pubnub.grant() .channels([ch1, ch2]) .write(True) .read(True) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch1].read_enabled is True assert env.result.channels[ch2].read_enabled is True assert env.result.channels[ch1].write_enabled is True assert env.result.channels[ch2].write_enabled is True assert env.result.channels[ch1].manage_enabled is False assert env.result.channels[ch2].manage_enabled is False env = (yield from pubnub.audit() .channels([ch1, ch2]) .future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert env.result.channels[ch1].read_enabled is True assert env.result.channels[ch2].read_enabled is True assert env.result.channels[ch1].write_enabled is True assert env.result.channels[ch2].write_enabled is True assert env.result.channels[ch1].manage_enabled is False assert env.result.channels[ch2].manage_enabled is False pubnub.stop()
def test_error_forbidden(self): pubnub = PubNubTwisted(pnconf_pam_copy()) with pytest.raises(PubNubTwistedException) as exception: yield pubnub.publish().channel("not_permitted_channel").message("hey").deferred() self.assertEqual(exception.value.status.error_data.information, "HTTP Client Error (403): {u'status': 403, u'message': u'Forbidden', u'payload':" " {u'channels': [u'not_permitted_channel']}, u'service': u'Access Manager', u'error': True}")
def test_publish_super_admin_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) yield from pubnub.publish().channel(ch).message("hey").future() yield from pubnub.publish().channel("foo.bar").message("hey^&#$").should_store(True).meta({ 'name': 'alex' }).future() pubnub.stop()
def test_super_call_with_channel_only(self): ch = "history-native-sync-ch" pubnub = PubNub(pnconf_pam_copy()) pubnub.config.uuid = "history-native-sync-uuid" envelope = pubnub.history().channel(ch).sync() assert isinstance(envelope.result, PNHistoryResult) assert not envelope.status.is_error()
def test_error_not_permitted_403(self): my_pnconf = pnconf_pam_copy() my_pnconf.secret_key = None self.pubnub = PubNubTornado(my_pnconf, custom_ioloop=self.io_loop) self.assert_server_side_error( self.pubnub.publish().channel("not_permitted_channel").message("hey"), "HTTP Client Error (403)") self.assert_server_side_error_yield( self.pubnub.publish().channel("not_permitted_channel").message("hey"), "HTTP Client Error (403)")
def test_super_call_with_all_params(self): ch = "history-native-sync-ch" pubnub = PubNub(pnconf_pam_copy()) pubnub.config.uuid = "history-native-sync-uuid" envelope = pubnub.history().channel(ch).count(2).include_timetoken(True).reverse(True).start(1).end(2).sync() assert isinstance(envelope.result, PNHistoryResult) assert not envelope.status.is_error()
def test_error_forbidden(self): pubnub = PubNubTwisted(pnconf_pam_copy()) with pytest.raises(PubNubTwistedException) as exception: yield pubnub.publish().channel("not_permitted_channel").message( "hey").deferred() self.assertEqual( exception.value.status.error_data.information, "HTTP Client Error (403): {u'status': 403, u'message': u'Forbidden', u'payload':" " {u'channels': [u'not_permitted_channel']}, u'service': u'Access Manager', u'error': True}" )
def test_where_now_super_admin_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) uuid = 'test-where-now-asyncio-uuid' pubnub.config.uuid = uuid env = yield from pubnub.where_now() \ .uuid(uuid) \ .future() assert isinstance(env.result, PNWhereNowResult) pubnub.stop()
def test_where_now_super_admin_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) uuid = 'test-where-now-asyncio-uuid' pubnub.config.uuid = uuid res = yield from pubnub.where_now() \ .uuid(uuid) \ .result() assert isinstance(res, PNWhereNowResult) pubnub.stop()
async def test_where_now_super_admin_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) uuid = 'test-where-now-asyncio-uuid-.*|@' pubnub.config.uuid = uuid res = await pubnub.where_now() \ .uuid(uuid) \ .result() assert isinstance(res, PNWhereNowResult) await pubnub.stop()
async def test_single_channel(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" ch = "test-pam-asyncio-ch" env = await pubnub.grant().channels(ch).write(True).read(True).future() assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch].read_enabled == 1 assert env.result.channels[ch].write_enabled == 1 assert env.result.channels[ch].manage_enabled == 0 assert env.result.channels[ch].delete_enabled == 0 await pubnub.stop()
def test_access_denied_unsubscribe_operation(event_loop): channel = "not-permitted-channel" pnconf = pnconf_pam_copy() pnconf.secret_key = None pnconf.enable_subscribe = True pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) callback = AccessDeniedListener() pubnub.add_listener(callback) pubnub.subscribe().channels(channel).execute() yield from callback.access_denied_event.wait() pubnub.stop()
def test_state_super_admin_call(event_loop): pnconf = pnconf_pam_copy() pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) ch1 = "test-state-asyncio-ch1" ch2 = "test-state-asyncio-ch2" pubnub.config.uuid = "test-state-asyncio-uuid" state = {"name": "Alex", "count": 5} env = yield from pubnub.set_state().channels([ch1, ch2]).state(state).future() assert isinstance(env.result, PNSetStateResult) env = yield from pubnub.get_state().channels([ch1, ch2]).future() assert isinstance(env.result, PNGetStateResult) pubnub.stop()
def test_not_permitted(self): pnconf = pnconf_pam_copy() pnconf.secret_key = None PubNub(pnconf).publish() \ .channel("not_permitted_channel") \ .message("correct message") \ .async(self.callback) self.event.wait() assert self.status.is_error() assert self.response is None assert "HTTP Client Error (403)" in str(self.status.error_data.exception) assert "Forbidden" in str(self.status.error_data.exception) assert "Access Manager" in str(self.status.error_data.exception)
async def test_single_channel_group(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" cg = "test-pam-asyncio-cg" env = await pubnub.grant().channel_groups(cg).write(True).read(True ).future() assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.level == 'channel-group' assert env.result.groups[cg].read_enabled == 1 assert env.result.groups[cg].write_enabled == 1 assert env.result.groups[cg].manage_enabled == 0 assert env.result.groups[cg].delete_enabled == 0 await pubnub.stop()
def test_not_permitted(self): pnconf = pnconf_pam_copy() pnconf.secret_key = None PubNub(pnconf).publish()\ .channel("not_permitted_channel")\ .message("correct message")\ .pn_async(self.callback) self.event.wait() assert self.status.is_error() assert self.response is None assert "HTTP Client Error (403)" in str(self.status.error_data.exception) assert "Forbidden" in str(self.status.error_data.exception) assert "Access Manager" in str(self.status.error_data.exception)
def test_here_now_super_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-here-now-asyncio-uuid1' env = yield from pubnub.here_now().future() assert isinstance(env.result, PNHereNowResult) env = yield from pubnub.here_now().channel_groups("gr").include_uuids(True).include_state(True).future() assert isinstance(env.result, PNHereNowResult) env = yield from pubnub.here_now().channels('ch.bar*').channel_groups("gr.k").future() assert isinstance(env.result, PNHereNowResult) env = yield from pubnub.here_now().channels(['ch.bar*', 'ch2']).channel_groups("gr.k").future() assert isinstance(env.result, PNHereNowResult) pubnub.stop()
async def test_here_now_super_call(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = 'test-here-now-asyncio-uuid1' env = await pubnub.here_now().future() assert isinstance(env.result, PNHereNowResult) env = await pubnub.here_now().channel_groups("gr").include_uuids(True).include_state(True).future() assert isinstance(env.result, PNHereNowResult) env = await pubnub.here_now().channels('ch.bar*').channel_groups("gr.k").future() assert isinstance(env.result, PNHereNowResult) env = await pubnub.here_now().channels(['ch.bar*', 'ch2']).channel_groups("gr.k").future() assert isinstance(env.result, PNHereNowResult) pubnub.stop()
async def test_single_channel_group_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" gr = "test-pam-asyncio-cg" auth = "test-pam-asyncio-auth" env = await pubnub.grant().channel_groups(gr).write(True).read( True).auth_keys(auth).future() assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.level == 'channel-group+auth' assert env.result.groups[gr].auth_keys[auth].read_enabled == 1 assert env.result.groups[gr].auth_keys[auth].write_enabled == 1 assert env.result.groups[gr].auth_keys[auth].manage_enabled == 0 assert env.result.groups[gr].auth_keys[auth].delete_enabled == 0 await pubnub.stop()
async def test_multiple_channel_groups(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" gr1 = "test-pam-asyncio-cg1" gr2 = "test-pam-asyncio-cg2" env = await pubnub.grant().channel_groups( [gr1, gr2]).write(True).read(True).future() assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.groups[gr1].read_enabled is True assert env.result.groups[gr2].read_enabled is True assert env.result.groups[gr1].write_enabled is True assert env.result.groups[gr2].write_enabled is True assert env.result.groups[gr1].manage_enabled is False assert env.result.groups[gr2].manage_enabled is False assert env.result.groups[gr1].delete_enabled is False assert env.result.groups[gr2].delete_enabled is False await pubnub.stop()
def test_state_super_admin_call(event_loop): pnconf = pnconf_pam_copy() pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop) ch1 = 'test-state-asyncio-ch1' ch2 = 'test-state-asyncio-ch2' pubnub.config.uuid = 'test-state-asyncio-uuid' state = {"name": "Alex", "count": 5} env = yield from pubnub.set_state() \ .channels([ch1, ch2]) \ .state(state) \ .future() assert isinstance(env.result, PNSetStateResult) env = yield from pubnub.get_state() \ .channels([ch1, ch2]) \ .future() assert isinstance(env.result, PNGetStateResult) pubnub.stop()
def test_single_channel_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "test-pam-asyncio-uuid" ch = "test-pam-asyncio-ch" auth = "test-pam-asyncio-auth" env = (yield from pubnub.grant() .channels(ch) .write(True) .read(True) .auth_keys(auth) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch].auth_keys[auth].read_enabled == 1 assert env.result.channels[ch].auth_keys[auth].write_enabled == 1 assert env.result.channels[ch].auth_keys[auth].manage_enabled == 0 assert env.result.channels[ch].auth_keys[auth].delete_enabled == 0 pubnub.stop()
async def test_multiple_channels_with_auth(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" ch1 = "test-pam-asyncio-ch1" ch2 = "test-pam-asyncio-ch2" auth = "test-pam-asyncio-auth" env = await pubnub.grant().channels( [ch1, ch2]).write(True).read(True).auth_keys(auth).future() assert isinstance(env.result, PNAccessManagerGrantResult) assert env.result.channels[ch1].auth_keys[auth].read_enabled is True assert env.result.channels[ch2].auth_keys[auth].read_enabled is True assert env.result.channels[ch1].auth_keys[auth].write_enabled is True assert env.result.channels[ch2].auth_keys[auth].write_enabled is True assert env.result.channels[ch1].auth_keys[auth].manage_enabled is False assert env.result.channels[ch2].auth_keys[auth].manage_enabled is False assert env.result.channels[ch1].auth_keys[auth].delete_enabled is False assert env.result.channels[ch2].auth_keys[auth].delete_enabled is False await pubnub.stop()
def test_global_level(event_loop): pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) pubnub.config.uuid = "my_uuid" env = (yield from pubnub.grant() .write(True) .read(True) .future()) assert isinstance(env.result, PNAccessManagerGrantResult) assert len(env.result.channels) == 0 assert len(env.result.groups) == 0 assert env.result.read_enabled is True assert env.result.write_enabled is True assert env.result.manage_enabled is False env = (yield from pubnub.audit() .future()) assert isinstance(env.result, PNAccessManagerAuditResult) assert len(env.result.channels) >= 0 assert len(env.result.groups) >= 0 assert env.result.read_enabled is True assert env.result.write_enabled is True assert env.result.manage_enabled is False env = yield from pubnub.revoke().future() assert isinstance(env.result, PNAccessManagerGrantResult) assert len(env.result.channels) == 0 assert len(env.result.groups) == 0 assert env.result.read_enabled is False assert env.result.write_enabled is False assert env.result.manage_enabled is False pubnub.stop()
def test_super_call(self): ch1 = "state-tornado-ch1" ch2 = "state-tornado-ch2" pnconf = pnconf_pam_copy() pubnub = PubNub(pnconf) pubnub.config.uuid = 'test-state-native-uuid-|.*$' state = {"name": "Alex", "count": 5} env = pubnub.set_state() \ .channels([ch1, ch2]) \ .state(state) \ .sync() assert env.result.state['name'] == "Alex" assert env.result.state['count'] == 5 env = pubnub.get_state() \ .channels([ch1, ch2]) \ .sync() assert env.result.channels[ch1]['name'] == "Alex" assert env.result.channels[ch2]['name'] == "Alex" assert env.result.channels[ch1]['count'] == 5 assert env.result.channels[ch2]['count'] == 5
from pubnub.pubnub import PubNub from tests.integrational.vcr_helper import pn_vcr from tests.helper import pnconf_pam_copy from pubnub.models.consumer.access_manager import PNAccessManagerGrantResult pubnub = PubNub(pnconf_pam_copy()) pubnub.config.uuid = "test_grant" @pn_vcr.use_cassette('tests/integrational/fixtures/native_sync/pam/grant_with_spaces.yaml', filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature']) def test_grant_auth_key_with_spaces(): envelope = pubnub.grant()\ .read(True)\ .write(True)\ .channels("test channel")\ .auth_keys("client auth key with spaces")\ .ttl(60)\ .sync() assert isinstance(envelope.result, PNAccessManagerGrantResult)
import unittest try: from mock import MagicMock except ImportError: from unittest.mock import MagicMock from pubnub.endpoints.history import History from pubnub.pubnub import PubNub from tests.helper import pnconf_pam_copy, sdk_name from pubnub.managers import TelemetryManager pnconf = pnconf_pam_copy() pnconf.secret_key = None class TestHistory(unittest.TestCase): def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf, sdk_name=sdk_name, timestamp=MagicMock(return_value=123), uuid=None) self.pubnub.uuid = "UUID_UnitTest" self.pubnub._telemetry_manager = TelemetryManager() self.history = History(self.pubnub) def test_history_basic(self): self.history.channel('ch') self.assertEquals(self.history.build_path(),
import unittest from pubnub import utils from pubnub.endpoints.access.revoke import Revoke try: from mock import MagicMock except ImportError: from unittest.mock import MagicMock from pubnub.pubnub import PubNub from tests.helper import pnconf_pam_copy, sdk_name from pubnub.managers import TelemetryManager pnconf = pnconf_pam_copy() # pnconf.secret_key = None class TestRevoke(unittest.TestCase): def setUp(self): self.pubnub = MagicMock( spec=PubNub, config=pnconf, sdk_name=sdk_name, timestamp=MagicMock(return_value=123), uuid=None ) self.pubnub.uuid = "UUID_RevokeUnitTest" self.pubnub._telemetry_manager = TelemetryManager() self.revoke = Revoke(self.pubnub)