def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf, sdk_name=sdk_name, uuid=None) self.pubnub.uuid = "UUID_SetStateTest" self.pubnub._telemetry_manager = TelemetryManager() self.set_state = SetState(self.pubnub) self.state = {'name': 'Alex', "count": 5}
def setUp(self): self.pubnub = MagicMock( spec=PubNub, config=pnconf, sdk_name=sdk_name, uuid=None ) self.pubnub.uuid = "UUID_SetStateTest" self.set_state = SetState(self.pubnub) self.state = {'name': 'Alex', "count": 5}
class TestSetState(unittest.TestCase): def setUp(self): self.pubnub = MagicMock(spec=PubNub, config=pnconf, sdk_name=sdk_name, uuid=None, _get_token=lambda: None) self.pubnub.uuid = "UUID_SetStateTest" self.pubnub._telemetry_manager = TelemetryManager() self.set_state = SetState(self.pubnub) self.state = {'name': 'Alex', "count": 5} def test_set_state_single_channel(self): self.set_state.channels('ch').state(self.state) self.assertEqual( self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, "ch", self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) self.assertEqual(params['uuid'], self.pubnub.uuid) self.assertEqual( json.loads(helper.url_decode(params['state'])), json.loads( helper.url_decode( '%7B%22count%22%3A%205%2C%20%22name%22%3A%20%22Alex%22%7D') )) self.assertEqual(self.set_state._channels, ['ch']) def test_set_state_single_group(self): self.set_state.channel_groups('gr').state(self.state) self.assertEqual( self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, ",", self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) self.assertEqual(params['uuid'], self.pubnub.uuid) self.assertEqual(params['channel-group'], 'gr') self.assertEqual( json.loads(helper.url_decode(params['state'])), json.loads( helper.url_decode( '%7B%22count%22%3A%205%2C%20%22name%22%3A%20%22Alex%22%7D') )) assert len(self.set_state._channels) == 0 self.assertEqual(self.set_state._groups, ['gr'])
class TestSetState(unittest.TestCase): def setUp(self): self.pubnub = MagicMock( spec=PubNub, config=pnconf, sdk_name=sdk_name, uuid=None ) self.pubnub.uuid = "UUID_SetStateTest" self.set_state = SetState(self.pubnub) self.state = {'name': 'Alex', "count": 5} def test_set_state_single_channel(self): self.set_state.channels('ch').state(self.state) self.assertEquals(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, "ch", self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) self.assertEqual(params['uuid'], self.pubnub.uuid) self.assertEqual(json.loads(helper.url_decode(params['state'])), json.loads(helper.url_decode('%7B%22count%22%3A%205%2C%20%22name%22%3A%20%22Alex%22%7D'))) self.assertEqual(self.set_state._channels, ['ch']) def test_set_state_single_group(self): self.set_state.channel_groups('gr').state(self.state) self.assertEquals(self.set_state.build_path(), SetState.SET_STATE_PATH % (pnconf.subscribe_key, ",", self.pubnub.uuid)) params = self.set_state.build_params_callback()({}) self.assertEqual(params['pnsdk'], sdk_name) self.assertEqual(params['uuid'], self.pubnub.uuid) self.assertEqual(params['channel-group'], 'gr') self.assertEqual(json.loads(helper.url_decode(params['state'])), json.loads(helper.url_decode('%7B%22count%22%3A%205%2C%20%22name%22%3A%20%22Alex%22%7D'))) assert len(self.set_state._channels) == 0 self.assertEqual(self.set_state._groups, ['gr'])