Commits

Éric Araujo  committed 84a958f

* Use token from settings if not given in properties.

  • Participants
  • Parent commits e6368b7

Comments (0)

Files changed (2)

File pyramid_mixpanel/__init__.py

         by the client.
         """
         url = "https://api.mixpanel.com/track"
+        if u'token' not in properties:
+            properties[u'token'] = self.token
 
         try:
             params = {'event': event, 'properties': properties}

File pyramid_mixpanel/tests/unittests/test_pyramid_mixpanel.py

         mu = MixpanelUtility({'mixpanel.token': 'token'})
         event = 'test_event'
         properties = {
-            u'token': u'123456789',
             u'install_referrer': 'Direct Link',
             }
 
         mu.track(event, properties)
 
         url = "https://api.mixpanel.com/track"
+        properties['token'] = 'token'
+        params = {'event': event, 'properties': properties}
+        data = base64.b64encode(json.dumps(params))
+        m_get.assert_called_once_with(url, params={'data': data})
+
+    @mock.patch('requests.get')
+    def test_track_overriden_token(self, m_get):
+        from pyramid_mixpanel import MixpanelUtility
+        mu = MixpanelUtility({'mixpanel.token': 'config token'})
+        event = 'test_event2'
+        properties = {
+            u'referrer': u'Direct Link',
+            u'token': u'given token'
+            }
+
+        mu.track(event, properties)
+
+        url = "https://api.mixpanel.com/track"
         params = {'event': event, 'properties': properties}
         data = base64.b64encode(json.dumps(params))
         m_get.assert_called_once_with(url, params={'data': data})