Commits

Anonymous committed 55bdc65

* Added DummyMixpanelUtility, a mixpanel utility that does nothing. Set mixpanel.enabled = False in your config file to use it instead of the normal MixpanelUtility.

Comments (0)

Files changed (2)

pyramid_mixpanel/__init__.py

 
 def includeme(config):
     log.debug('Including pyramid_mixpanel')
-    config.registry.registerUtility(MixpanelUtility(config.registry.settings))
+    if config.registry.settings.get("mixpanel.enabled", True):
+        log.debug('Tracking enabled.')
+        utility = MixpanelUtility(config.registry.settings)
+    else:
+        log.debug('Tracking disabled -- using dummy utility.')
+        utility = DummyMixpanelUtility()
+    config.registry.registerUtility(utility)
     config.commit()
 
 
         elif result != '1':
             log.warning('unknown status returned by mixpanel people '
                         'tracking: %r', result)
+
+
+@implementer(IMixpanelUtility)
+class DummyMixpanelUtility(object):
+    """Dummy mixpanel utility -- it does nothing.
+
+    Use it as a replacement for the regular mixpanel utility when
+    running tests.
+    """
+    def track(self, event, properties):
+        pass
+
+    def people_track(self, distinct_id, properties):
+        pass

pyramid_mixpanel/tests/unittests/test_pyramid_mixpanel.py

         config.commit.assert_called_once_with()
         utility.assert_called_once_with(config.registry.settings)
 
+    @mock.patch('pyramid_mixpanel.DummyMixpanelUtility')
+    def test_includeme_tracking_disabled(self, dummy_utility):
+        from pyramid_mixpanel import includeme
+        config = mock.Mock()
+        config.registry.settings = {"mixpanel.enabled": False}
+
+        includeme(config)
+
+        config.registry.registerUtility.assert_called_once_with(
+            dummy_utility.return_value
+        )
+        config.commit.assert_called_once_with()
+        dummy_utility.assert_called_once_with()
+
     def test_get_mixpanel_utility(self):
         from pyramid_mixpanel import get_mixpanel_utility, IMixpanelUtility
         request = mock.Mock()