|
| 1 | + |
| 2 | +from pubnub.pubnub import PubNub |
| 3 | +from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult |
| 4 | +from pubnub.models.consumer.v3.channel import Channel |
| 5 | +from pubnub.models.consumer.v3.space import Space |
| 6 | +from tests.helper import pnconf_pam_copy |
| 7 | +from tests.integrational.vcr_helper import pn_vcr |
| 8 | + |
| 9 | +pubnub = PubNub(pnconf_pam_copy()) |
| 10 | +pubnub.config.uuid = "test_grant" |
| 11 | + |
| 12 | + |
| 13 | +@pn_vcr.use_cassette( |
| 14 | + 'tests/integrational/fixtures/native_sync/pam/grant_token_with_uuid_and_channels.yaml', |
| 15 | + filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature'] |
| 16 | +) |
| 17 | +def test_grant_auth_key_with_uuid_and_channels(): |
| 18 | + envelope = pubnub.grant_token()\ |
| 19 | + .ttl(60)\ |
| 20 | + .authorized_uuid('some_uuid')\ |
| 21 | + .channels([ |
| 22 | + Channel().id('some_channel_id').read().write(), |
| 23 | + Channel().pattern('some_*').read().write() |
| 24 | + ])\ |
| 25 | + .sync() |
| 26 | + assert isinstance(envelope.result, PNGrantTokenResult) |
| 27 | + assert envelope.result.token |
| 28 | + |
| 29 | + |
| 30 | +@pn_vcr.use_cassette( |
| 31 | + 'tests/integrational/fixtures/native_sync/pam/grant_token_user_space.yaml', |
| 32 | + filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'timestamp', 'signature'] |
| 33 | +) |
| 34 | +def test_grant_auth_key_with_user_id_and_spaces(): |
| 35 | + envelope = pubnub.grant_token()\ |
| 36 | + .ttl(60)\ |
| 37 | + .authorized_user('some_user_id')\ |
| 38 | + .spaces([ |
| 39 | + Space().id('some_space_id').read().write(), |
| 40 | + Space().pattern('some_*').read().write() |
| 41 | + ])\ |
| 42 | + .sync() |
| 43 | + assert isinstance(envelope.result, PNGrantTokenResult) |
| 44 | + assert envelope.result.token |
0 commit comments