Example #1
0
    def test_pub_encrypted_list_message(self):
        conf = copy.copy(pnconf)
        conf.cipher_key = "testCipher"

        pubnub = MagicMock(
            spec=PubNub,
            config=conf,
            sdk_name=sdk_name,
            uuid="UUID_PublishUnitTest",
            _publish_sequence_manager=self.sm
        )
        pubnub._telemetry_manager = TelemetryManager()
        pub = Publish(pubnub)

        message = ["hi", "hi2", "hi3"]
        encoded_message = "%22FQyKoIWWm7oN27zKyoU0bpjpgx49JxD04EI%2F0a8rg%2Fo%3D%22"

        pub.channel("ch1").message(message)

        self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': pubnub.uuid,
        })
Example #2
0
    def test_pub_with_auth(self):
        conf = copy.copy(pnconf)
        conf.auth_key = "my_auth"

        pubnub = MagicMock(
            spec=PubNub,
            config=conf,
            sdk_name=sdk_name,
            uuid="UUID_PublishUnitTest",
            _publish_sequence_manager=self.sm
        )
        pubnub._telemetry_manager = TelemetryManager()
        pub = Publish(pubnub)
        message = "hey"
        encoded_message = url_encode(message)
        pub.channel("ch1").message(message)

        self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': pubnub.uuid,
            'auth': conf.auth_key,
        })
Example #3
0
def test_average_latency():
    manager = TelemetryManager()
    endpointLatencies = [
        {
            "timestamp": 100,
            "latency": 10
        },
        {
            "timestamp": 100,
            "latency": 20
        },
        {
            "timestamp": 100,
            "latency": 30
        },
        {
            "timestamp": 100,
            "latency": 40
        },
        {
            "timestamp": 100,
            "latency": 50
        },
    ]

    averageLatency = manager.average_latency_from_data(endpointLatencies)

    if not 30 == averageLatency:
        raise AssertionError()
Example #4
0
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf_copy(),
                             sdk_name=sdk_name)
     self.pubnub.config.uuid = "UUID_WhereNowTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.where_now = WhereNow(self.pubnub)
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf,
                             sdk_name=sdk_name,
                             uuid=None)
     self.pubnub.uuid = "UUID_ListChannelsInCGTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.list_push = ListPushProvisions(self.pubnub)
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf,
                             sdk_name=sdk_name,
                             uuid=None)
     self.pubnub.uuid = "UUID_GetStateTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.get_state = GetState(self.pubnub)
Example #7
0
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf,
                             sdk_name=sdk_name,
                             uuid=None)
     self.pubnub.uuid = "UUID_AddChannelToCGTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.add = AddChannelToChannelGroup(self.pubnub)
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf,
                             sdk_name=sdk_name,
                             uuid=None)
     self.pubnub.uuid = "UUID_SubscribeUnitTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.leave = Leave(self.pubnub)
Example #9
0
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf_copy(),
                             sdk_name=sdk_name)
     self.pubnub.uuid = "UUID_HeartbeatUnitTest"
     self.hb = Heartbeat(self.pubnub)
     self.pubnub._telemetry_manager = TelemetryManager()
     self.pubnub.config.set_presence_timeout(20)
    def setUp(self):
        self.pubnub = MagicMock(spec=PubNub,
                                config=pnconf,
                                sdk_name=sdk_name,
                                uuid=None)

        self.pubnub.uuid = "UUID_RemoveChannelsTest"
        self.pubnub._telemetry_manager = TelemetryManager()
        self.remove_channels = RemoveChannelsFromPush(self.pubnub)
 def setUp(self):
     self.pubnub = MagicMock(spec=PubNub,
                             config=pnconf,
                             sdk_name=sdk_name,
                             uuid=None,
                             _get_token=lambda: None)
     self.pubnub.uuid = "UUID_ListChannelsInCGTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.list = RemoveChannelGroup(self.pubnub)
Example #12
0
 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}
Example #13
0
 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)
Example #14
0
 def setUp(self):
     self.pubnub = MagicMock(
         spec=PubNub,
         config=pnconf,
         sdk_name=sdk_name,
         _get_token=lambda: None
     )
     self.pubnub.uuid = "UUID_HereNowTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.here_now = HereNow(self.pubnub)
    def setUp(self):
        self.pubnub = MagicMock(spec=PubNub,
                                config=pnconf,
                                sdk_name=sdk_name,
                                uuid=None,
                                _get_token=lambda: None)

        self.pubnub.uuid = "UUID_RemoveDeviceTest"
        self.pubnub._telemetry_manager = TelemetryManager()
        self.remove_device = RemoveDeviceFromPush(self.pubnub)
    def setUp(self):
        self.pubnub = MagicMock(spec=PubNub,
                                config=pnconf,
                                sdk_name=sdk_name,
                                uuid=None,
                                _get_token=lambda: None)

        self.pubnub.uuid = "UUID_AddChannelsTest"
        self.pubnub._telemetry_manager = TelemetryManager()
        self.add_channels = AddChannelsToPush(self.pubnub)
 def setUp(self):
     self.pubnub = MagicMock(
         spec=PubNub,
         config=pnconf,
         sdk_name=sdk_name,
         _get_token=lambda: None
     )
     self.pubnub.uuid = "UUID_SubscribeUnitTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.pubnub._token_manager = TokenManager()
     self.sub = Subscribe(self.pubnub)
Example #18
0
    def setUp(self):
        self.sm = MagicMock(get_next_sequence=MagicMock(return_value=2))

        self.pubnub = MagicMock(spec=PubNub,
                                config=pnconf,
                                sdk_name=sdk_name,
                                _publish_sequence_manager=self.sm)

        self.pubnub.uuid = "UUID_PublishUnitTest"
        self.pubnub._telemetry_manager = TelemetryManager()
        self.pub = Publish(self.pubnub)
Example #19
0
 def setUp(self):
     self.pubnub = MagicMock(
         spec=PubNub,
         config=pnconf,
         sdk_name=sdk_name,
         timestamp=MagicMock(return_value=""),
         uuid=None,
         _get_token=lambda: None
     )
     self.pubnub.uuid = "UUID_UnitTest"
     self.pubnub._telemetry_manager = TelemetryManager()
     self.history_delete = HistoryDelete(self.pubnub)
Example #20
0
def test_cleaning_up_latency_data():
    manager = TelemetryManager()
    manager.MAXIMUM_LATENCY_DATA_AGE = 1

    for i in range(0, 10):
        manager.store_latency(i, PNOperationType.PNPublishOperation)

    # await for store timestamp expired
    time.sleep(2)

    manager.clean_up_telemetry_data()
    print(manager.latencies)

    assert len(manager.operation_latencies()) == 0
Example #21
0
def test_valid_queries():
    manager = TelemetryManager()

    manager.store_latency(1, PNOperationType.PNPublishOperation)
    manager.store_latency(2, PNOperationType.PNPublishOperation)
    manager.store_latency(3, PNOperationType.PNPublishOperation)
    manager.store_latency(4, PNOperationType.PNHistoryOperation)
    manager.store_latency(5, PNOperationType.PNHistoryOperation)
    manager.store_latency(6, PNOperationType.PNHistoryOperation)
    manager.store_latency(7, PNOperationType.PNRemoveGroupOperation)
    manager.store_latency(8, PNOperationType.PNRemoveGroupOperation)
    manager.store_latency(9, PNOperationType.PNRemoveGroupOperation)

    queries = manager.operation_latencies()

    if not queries['l_pub'] == 2:
        raise AssertionError()
    if not queries['l_hist'] == 5:
        raise AssertionError()
    if not queries['l_cg'] == 8:
        raise AssertionError()