当前位置: 首页>>代码示例>>Python>>正文


Python tasks.EventTracker类代码示例

本文整理汇总了Python中mixpanel.tasks.EventTracker的典型用法代码示例。如果您正苦于以下问题:Python EventTracker类的具体用法?Python EventTracker怎么用?Python EventTracker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EventTracker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_handle_properties_given

    def test_handle_properties_given(self):
        et = EventTracker()

        properties = et._handle_properties({'token': 'bar'}, None)
        self.assertEqual('bar', properties['token'])

        properties = et._handle_properties({'token': 'bar'}, 'foo')
        self.assertEqual('bar', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py

示例2: test_old_run

    def test_old_run(self):
        """non-recorded events should return False"""
        et = EventTracker()
        # Times older than 3 hours don't get recorded according to: http://mixpanel.com/api/docs/specification
        # equests will be rejected that are 3 hours older than present time
        result = et.run('event_foo', {'time': 1245613885})

        self.assertFalse(result)
开发者ID:Crowdbooster,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py

示例3: test_disable

    def test_disable(self):
        et = EventTracker()
        mp_settings.MIXPANEL_DISABLE = True

        def _fake_get_connection():
            assert False, "Should bail out before trying to get a connection."
        et._get_connection = _fake_get_connection

        et('foo')
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:9,代码来源:test_tasks.py

示例4: test_non_recorded

    def test_non_recorded(self):
        """non-recorded events should return False"""
        self.response.read.return_value = '0'

        et = EventTracker()
        # Times older than 3 hours don't get recorded according to:
        # http://mixpanel.com/api/docs/specification
        # requests will be rejected that are 3 hours older than present time
        # (though actually this is returnin False because of mocking network)
        result = et.run('event_foo', {'time': 1245613885})

        self.assertFalse(result)
开发者ID:datafyit,项目名称:mixpanel-celery,代码行数:12,代码来源:test_tasks.py

示例5: test_build_params

    def test_build_params(self):
        et = EventTracker()

        event = 'foo_event'
        is_test = 1
        properties = {'token': 'testtoken'}
        params = {'event': event, 'properties': properties}

        url_params = et._build_params(event, properties, is_test)

        expected_params = urllib.urlencode({
            'data': base64.b64encode(simplejson.dumps(params)),
            'test': is_test,
        })

        self.assertEqual(expected_params, url_params)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:16,代码来源:test_tasks.py

示例6: test_failed_request

    def test_failed_request(self):
        EventTracker.endpoint = 'brokenurl'

        with eager_tasks():
            result = EventTracker.delay('event_foo')

        self.assertNotEqual(result.traceback, None)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:7,代码来源:test_tasks.py

示例7: test_build_and_encode_params

    def test_build_and_encode_params(self):
        et = EventTracker()

        event = 'foo_event'
        test = True
        properties = {'token': 'testtoken'}
        params = {'event': event, 'properties': properties}

        params = et._build_params(event, properties)
        url_params = et._encode_params(params, test)

        expected_params = urllib.parse.urlencode({
            'data': base64.b64encode(json.dumps(params).encode('utf8')),
            'test': '1'
        })

        self.assertEqual(expected_params, url_params)
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:17,代码来源:test_tasks.py

示例8: test_failed_socket_request

    def test_failed_socket_request(self):
        def new_read(*args, **kwargs):
            raise socket.error('BOOM')

        self.response.read = new_read
        with eager_tasks():
            result = EventTracker.delay('event_foo')
        self.assertNotEqual(result.traceback, None)
开发者ID:winhamwr,项目名称:mixpanel-celery,代码行数:8,代码来源:test_tasks.py

示例9: send_mixpanel_event

def send_mixpanel_event(event_name, user, event_dict=None):
    """
    Helper function that takes from various views an event name, an event_dict and an user and populates the event dict with
    a) distinct_id of the user with key 'distinct_id'
    b) 'username' = user.firstname + user.lastname
    c) 'age' = in years, today - DOB
    d) 'gender' = user.gender
    e) total em
    f) redeemable em
    g) time on earthmiles = today - joining date
    and then calls EventTracker.delay() with the modified dictionary
    """
    from dateutil.relativedelta import relativedelta
    from datetime import datetime, date

    if event_dict == None:
        event_dict = {}
    try:
        age = relativedelta(datetime.today(), user.age, ).years
        days_on_em = (datetime.today() - user.date_joined.replace(tzinfo=None)).days
        event_dict.update(
            {
                'distinct_id': user.id,
                'Username': user.__str__(),
                'Age': age,
                'Gender': user.gender,
                'Days on Earthmiles': days_on_em,
                'Total Earthmiles': user.total_earthmiles,
                'Redeemable Earthmiles': user.redeemable_earthmiles,
            }
        )
    except AttributeError as e:
        event_dict.update(
            {
                'distinct_id': user.id,
            }
        )


    #Try to send event to mixpanel. If there is an error, it could be because we're testing on localhost, in which case, pass, else raise the error
    try:
        EventTracker.delay(event_name, event_dict)
    except ConnectionError as e:
        if 'localhost' not in str(e):
            raise
开发者ID:praveenjha527,项目名称:eatio-server,代码行数:45,代码来源:mixpanel_helper.py

示例10: test_is_test

    def test_is_test(self):
        et = EventTracker()

        self.assertEqual(et._is_test(None), 1)
        self.assertEqual(et._is_test(False), 0)
        self.assertEqual(et._is_test(True), 1)

        mp_settings.MIXPANEL_TEST_ONLY = False
        self.assertEqual(et._is_test(None), 0)
        self.assertEqual(et._is_test(False), 0)
        self.assertEqual(et._is_test(True), 1)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:11,代码来源:test_tasks.py

示例11: send_event

def send_event(event_name, **kwargs):
  if not event_name: raise ValueError("event name is required")
  EventTracker.delay(event_name, **kwargs)
开发者ID:huokedu,项目名称:dynamic-scrapy,代码行数:3,代码来源:analytics_service.py

示例12: test_failed_socket_request

 def test_failed_socket_request(self):
     self.response.read = Mock(side_effect=socket.error('BOOM'))
     with eager_tasks():
         result = EventTracker.delay('event_foo')
     self.assertNotEqual(result.traceback, None)
开发者ID:datafyit,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py

示例13: test_handle_properties_empty

    def test_handle_properties_empty(self):
        et = EventTracker()
        mp_settings.MIXPANEL_API_TOKEN = 'bar'

        properties = et._handle_properties(None, None)
        self.assertEqual('bar', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:6,代码来源:test_tasks.py

示例14: test_handle_properties_w_token

    def test_handle_properties_w_token(self):
        et = EventTracker()

        properties = et._handle_properties({}, 'foo')
        self.assertEqual('foo', properties['token'])
开发者ID:andela,项目名称:mixpanel-celery,代码行数:5,代码来源:test_tasks.py

示例15: test_failed_socket_request

    def test_failed_socket_request(self):
        mp_settings.MIXPANEL_API_SERVER = '127.0.0.1:60000'

        with eager_tasks():
            result = EventTracker.delay('event_foo')
        self.assertNotEqual(result.traceback, None)
开发者ID:andela,项目名称:mixpanel-celery,代码行数:6,代码来源:test_tasks.py


注:本文中的mixpanel.tasks.EventTracker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。