Exemplo n.º 1
0
    def test_patch_before_import(self):
        patch()
        import vertica_python

        # use a patched method from each class as indicators
        assert isinstance(vertica_python.Connection.cursor, wrapt.ObjectProxy)
        assert isinstance(vertica_python.vertica.cursor.Cursor.execute, wrapt.ObjectProxy)
Exemplo n.º 2
0
    def test_configuration_routine(self):
        """Ensure that the integration routines can be configured."""
        routine_config = dict(patch={
            'vertica_python.vertica.connection.Connection':
            dict(routines=dict(cursor=dict(
                operation_name='get_cursor',
                trace_enabled=True,
            ), ), ),
        }, )

        # Make a copy of the vertica config first before we merge our settings over
        # DEV: First argument gets merged into the second
        copy = _deepmerge(config.vertica, dict())
        overrides = _deepmerge(routine_config, copy)
        with self.override_config('vertica', overrides):
            patch()
            import vertica_python

            test_tracer = get_dummy_tracer()

            conn = vertica_python.connect(**VERTICA_CONFIG)
            Pin.override(conn, service='mycustomservice', tracer=test_tracer)
            conn.cursor()  # should be traced now
            conn.close()
        spans = test_tracer.writer.pop()
        assert len(spans) == 1
        assert spans[0].name == 'get_cursor'
        assert spans[0].service == 'mycustomservice'
Exemplo n.º 3
0
    def test_unpatch_after_import(self):
        patch()
        import vertica_python

        unpatch()
        assert not isinstance(vertica_python.Connection.cursor, wrapt.ObjectProxy)
        assert not isinstance(vertica_python.vertica.cursor.Cursor.execute, wrapt.ObjectProxy)
Exemplo n.º 4
0
    def test_idempotent_patch(self):
        patch()
        patch()
        import vertica_python

        assert not isinstance(vertica_python.Connection.cursor.__wrapped__, wrapt.ObjectProxy)
        assert not isinstance(vertica_python.vertica.cursor.Cursor.execute.__wrapped__, wrapt.ObjectProxy)
        assert isinstance(vertica_python.Connection.cursor, wrapt.ObjectProxy)
        assert isinstance(vertica_python.vertica.cursor.Cursor.execute, wrapt.ObjectProxy)
Exemplo n.º 5
0
    def test_configuration_service_name(self):
        """Ensure that the integration can be configured."""
        with self.override_config('vertica', dict(service_name='test_svc_name')):
            patch()
            import vertica_python

            test_tracer = get_dummy_tracer()

            conn = vertica_python.connect(**VERTICA_CONFIG)
            cur = conn.cursor()
            Pin.override(cur, tracer=test_tracer)
            with conn:
                cur.execute("DROP TABLE IF EXISTS {}".format(TEST_TABLE))
        spans = test_tracer.writer.pop()
        assert len(spans) == 1
        assert spans[0].service == "test_svc_name"
Exemplo n.º 6
0
def test_conn(test_tracer):
    ddtrace.tracer = test_tracer
    patch()

    import vertica_python  # must happen AFTER installing with patch()

    conn = vertica_python.connect(**VERTICA_CONFIG)
    cur = conn.cursor()
    cur.execute("DROP TABLE IF EXISTS {}".format(TEST_TABLE))
    cur.execute("""CREATE TABLE {} (
        a INT,
        b VARCHAR(32)
        )
        """.format(TEST_TABLE))
    test_tracer.writer.pop()
    return conn, cur
Exemplo n.º 7
0
    def test_patch_after_import(self):
        """Patching _after_ the import will not work because we hook into
        the module import system.

        Vertica uses a local reference to `Cursor` which won't get patched
        if we call `patch` after the module has already been imported.
        """
        import vertica_python

        assert not isinstance(vertica_python.vertica.connection.Connection.cursor, wrapt.ObjectProxy)
        assert not isinstance(vertica_python.vertica.cursor.Cursor.execute, wrapt.ObjectProxy)

        patch()

        conn = vertica_python.connect(**VERTICA_CONFIG)
        cursor = conn.cursor()
        assert not isinstance(cursor, wrapt.ObjectProxy)