Exemplo n.º 1
0
    def test_overflow(self):
        client = Client('testsecret', max_queue_size=1)
        client.consumer.pause()
        time.sleep(5.1) # allow time for consumer to exit

        client.identify('userId')
        success, msg = client.identify('userId')
        self.assertFalse(success)
Exemplo n.º 2
0
    def test_overflow(self):
        client = Client('testsecret', max_queue_size=1)
        client.consumer.pause()
        time.sleep(5.1)  # allow time for consumer to exit

        for i in range(10):
            client.identify('userId')

        success, msg = client.identify('userId')
        self.assertFalse(success)
Exemplo n.º 3
0
    def test_overflow(self):
        client = Client('testsecret', max_queue_size=1)
        # Ensure consumer thread is no longer uploading
        client.join()

        for _ in range(10):
            client.identify('userId')

        success, _ = client.identify('userId')
        # Make sure we are informed that the queue is at capacity
        self.assertFalse(success)
Exemplo n.º 4
0
    def test_overflow(self):
        client = Client('testsecret', max_queue_size=1)
        # Ensure consumer thread is no longer uploading
        client.join()

        for i in range(10):
          client.identify('userId')

        success, msg = client.identify('userId')
        # Make sure we are informed that the queue is at capacity
        self.assertFalse(success)
Exemplo n.º 5
0
    def test_user_defined_upload_size(self):
        client = Client('testsecret', on_error=self.fail,
                        upload_size=10, upload_interval=3)

        def mock_post_fn(*args, **kwargs):
            self.assertEquals(len(kwargs['batch']), 10)

        # the post function should be called 2 times, with a batch size of 10
        # each time.
        with mock.patch('analytics.consumer.post', side_effect=mock_post_fn) as mock_post:
            for _ in range(20):
                client.identify('userId', {'trait': 'value'})
            time.sleep(1)
            self.assertEquals(mock_post.call_count, 2)
Exemplo n.º 6
0
    def test_synchronous(self):
        client = Client('testsecret', sync_mode=True)

        success, _ = client.identify('userId')
        self.assertFalse(client.consumers)
        self.assertTrue(client.queue.empty())
        self.assertTrue(success)
Exemplo n.º 7
0
    def test_synchronous(self):
        client = Client('testsecret', sync_mode=True)

        success, message = client.identify('userId')
        self.assertIsNone(client.consumer)
        self.assertTrue(client.queue.empty())
        self.assertTrue(success)
Exemplo n.º 8
0
    def test_user_defined_flush_at(self):
        client = Client('testsecret',
                        on_error=self.fail,
                        flush_at=10,
                        flush_interval=3)

        def mock_post_fn(*args, **kwargs):
            self.assertEqual(len(kwargs['batch']), 10)

        # the post function should be called 2 times, with a batch size of 10
        # each time.
        with mock.patch('analytics.consumer.post', side_effect=mock_post_fn) \
                as mock_post:
            for _ in range(20):
                client.identify('userId', {'trait': 'value'})
            time.sleep(1)
            self.assertEqual(mock_post.call_count, 2)
Exemplo n.º 9
0
class SegmentWrapper(AbstractBaseIdentityIntegrationWrapper):
    def __init__(self, api_key: str):
        self.analytics = SegmentClient(write_key=api_key)

    def _identify_user(self, data: dict) -> None:
        self.analytics.identify(**data)
        logger.debug(f"Sent event to Segment.")

    def generate_user_data(self, user_id, feature_states):
        return {
            "user_id": user_id,
            "traits": {
                feature_state.feature.name: feature_state.get_feature_state_value()
                if feature_state.get_feature_state_value() is not None
                else "None"
                for feature_state in feature_states
            },
        }
Exemplo n.º 10
0
    def test_synchronous(self):
        # Max queue size at 0 -> synchronous mode
        client = Client('testsecret', max_queue_size=0)
        # Ensure the consumer thread is not running
        client.consumer.pause()

        success, message = client.identify('userId')

        self.assertTrue(client.queue.empty())
        self.assertTrue(success)
Exemplo n.º 11
0
class SegmentWrapper(AbstractBaseIdentityIntegrationWrapper):
    def __init__(self, api_key: str):
        self.analytics = SegmentClient(write_key=api_key)

    def _identify_user(self, data: dict) -> None:
        self.analytics.identify(**data)
        logger.debug(f"Sent event to Segment.")

    def generate_user_data(self, user_id, feature_states):
        feature_properties = {}

        for feature_state in feature_states:
            value = feature_state.get_feature_state_value()
            feature_properties[feature_state.feature.name] = (
                value if (feature_state.enabled and value) else feature_state.enabled
            )

        return {
            "user_id": user_id,
            "traits": feature_properties,
        }
Exemplo n.º 12
0
 def test_proxies(self):
     client = Client('testsecret', proxies='203.243.63.16:80')
     success, msg = client.identify('userId', {'trait': 'value'})
     self.assertTrue(success)
Exemplo n.º 13
0
 def test_gzip(self):
     client = Client('testsecret', on_error=self.fail, gzip=True)
     for _ in range(10):
         client.identify('userId', {'trait': 'value'})
     client.flush()
     self.assertFalse(self.failed)
Exemplo n.º 14
0
 def test_gzip(self):
     client = Client('testsecret', on_error=self.fail, gzip=True)
     for _ in range(10):
         client.identify('userId', {'trait': 'value'})
     client.flush()
     self.assertFalse(self.failed)