Exemple #1
0
def test_not_configured():
    """If mixpanel is not configured, no request is sent."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        with mock.patch('portfoliyo.mixpanel.settings', spec=[]):
            mixpanel.track('some-event', {'property': 'value'})

    assert not mock_urlopen.call_count
Exemple #2
0
def test_not_configured():
    """If mixpanel is not configured, no request is sent."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        with mock.patch('portfoliyo.mixpanel.settings', spec=[]):
            mixpanel.track('some-event', {'property': 'value'})

    assert not mock_urlopen.call_count
Exemple #3
0
def test_track():
    """Track sends correct request to Mixpanel."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        mock_urlopen.return_value.getcode.return_value = 200
        mock_urlopen.return_value.read.return_value = '1'
        with mock.patch('portfoliyo.mixpanel.settings') as mock_settings:
            mock_settings.MIXPANEL_ID = 'mixpanel-token'
            mixpanel.track('some-event', {'property': 'value'})

    expected_data = {
        'event': 'some-event',
        'properties': {'token': 'mixpanel-token', 'property': 'value'},
        }

    assert_url_and_data(mock_urlopen, expected_data)
Exemple #4
0
def test_track():
    """Track sends correct request to Mixpanel."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        mock_urlopen.return_value.getcode.return_value = 200
        mock_urlopen.return_value.read.return_value = '1'
        with mock.patch('portfoliyo.mixpanel.settings') as mock_settings:
            mock_settings.MIXPANEL_ID = 'mixpanel-token'
            mixpanel.track('some-event', {'property': 'value'})

    expected_data = {
        'event': 'some-event',
        'properties': {
            'token': 'mixpanel-token',
            'property': 'value'
        },
    }

    assert_url_and_data(mock_urlopen, expected_data)
Exemple #5
0
def test_bad_response():
    """Logs warning if response body is not '1'."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        mock_urlopen.return_value.getcode.return_value = 200
        mock_urlopen.return_value.read.return_value = '0'
        with mock.patch('portfoliyo.mixpanel.settings') as mock_settings:
            mock_settings.MIXPANEL_ID = 'mptok'
            with mock.patch('portfoliyo.mixpanel.logger') as mock_logger:
                mixpanel.track('some-event')


    mock_logger.warning.assert_called_with(
        "Mixpanel returned bad response %s",
        '0',
        extra={
            'stack': True,
            'params': {'event': 'some-event', 'properties': {'token': 'mptok'}},
            },
        )
Exemple #6
0
def test_bad_response():
    """Logs warning if response body is not '1'."""
    with mock.patch('portfoliyo.mixpanel.urllib2.urlopen') as mock_urlopen:
        mock_urlopen.return_value.getcode.return_value = 200
        mock_urlopen.return_value.read.return_value = '0'
        with mock.patch('portfoliyo.mixpanel.settings') as mock_settings:
            mock_settings.MIXPANEL_ID = 'mptok'
            with mock.patch('portfoliyo.mixpanel.logger') as mock_logger:
                mixpanel.track('some-event')

    mock_logger.warning.assert_called_with(
        "Mixpanel returned bad response %s",
        '0',
        extra={
            'stack': True,
            'params': {
                'event': 'some-event',
                'properties': {
                    'token': 'mptok'
                }
            },
        },
    )