Ejemplo n.º 1
0
    def test_autopatching_twice(self):
        patch(django=True)

        # Call django.setup() twice and ensure we don't add a duplicate tracer
        import django
        django.setup()
        django.setup()

        from django.conf import settings
        found_app = 0

        for app in settings.INSTALLED_APPS:
            if app == 'ddtrace.contrib.django':
                found_app += 1

        eq_(found_app, 1)
        eq_(settings.MIDDLEWARE_CLASSES[0],
            'ddtrace.contrib.django.TraceMiddleware')

        found_mw = 0
        for mw in settings.MIDDLEWARE_CLASSES:
            if mw == 'ddtrace.contrib.django.TraceMiddleware':
                found_mw += 1

        eq_(found_mw, 1)
Ejemplo n.º 2
0
    def test_patch_raise_exception_manual_patch(self):
        # Manual patching should not be affected by the environment variable override.
        with self.assertRaises(monkey.ModuleNotFoundException) as me:
            monkey.patch(module_dne=True)

        assert (
            "integration module ddtrace.contrib.module_dne does not exist, module will not have tracing available"
            in str(me.exception))
        assert "module_dne" not in monkey._PATCHED_MODULES
Ejemplo n.º 3
0
    def test_autopatching(self):
        patch(django=True)

        import django
        ok_(django._datadog_patch)
        django.setup()

        from django.conf import settings
        ok_('ddtrace.contrib.django' in settings.INSTALLED_APPS)
        eq_(settings.MIDDLEWARE_CLASSES[0],
            'ddtrace.contrib.django.TraceMiddleware')
 def test_autopatching_empty_middleware(self):
     with self.settings(MIDDLEWARE=[]):
         patch(django=True)
         django.setup()
     assert django._datadog_patch
     assert 'ddtrace.contrib.django' in settings.INSTALLED_APPS
     assert settings.MIDDLEWARE[
         0] == 'ddtrace.contrib.django.TraceMiddleware'
     # MIDDLEWARE_CLASSES gets created internally in django 1.10 & 1.11 but doesn't
     # exist at all in 2.0.
     assert not getattr(settings, 'MIDDLEWARE_CLASSES', None) or \
         'ddtrace.contrib.django.TraceMiddleware' \
         not in settings.MIDDLEWARE_CLASSES
     assert settings.MIDDLEWARE[
         -1] == 'ddtrace.contrib.django.TraceExceptionMiddleware'
     assert not getattr(settings, 'MIDDLEWARE_CLASSES', None) or \
         'ddtrace.contrib.django.TraceExceptionMiddleware' \
         not in settings.MIDDLEWARE_CLASSES
 def setUp(self):
     super(DjangoAutopatchTest, self).setUp()
     patch(django=True)
     django.setup()
Ejemplo n.º 6
0
 def setUp(self):
     super(DjangoAutopatchTest, self).setUp()
     patch(django=True)
     django.setup()
Ejemplo n.º 7
0
 def test_patch_all_env_override_manual_patch(self):
     # Manual patching should not be affected by the environment variable override.
     monkey.patch(sqlite3=True)
     assert "sqlite3" in monkey._PATCHED_MODULES