コード例 #1
0
def test_get_name_from_func_class():
    class X(object):
        def x(self):
            pass

    assert "tests.utils.tests.x" == get_name_from_func(X.x)
    assert "tests.utils.tests.x" == get_name_from_func(X().x)
コード例 #2
0
    def process_response(self, request, response):
        if django_settings.DEBUG and not self.client.config.debug:
            return response
        try:
            if hasattr(response, "status_code"):
                transaction_name = None
                if self.client.config.django_transaction_name_from_route and hasattr(
                        request.resolver_match, "route"):
                    transaction_name = request.resolver_match.route
                elif getattr(request, "_zuqa_view_func", False):
                    transaction_name = get_name_from_func(
                        request._zuqa_view_func)
                if transaction_name:
                    transaction_name = build_name_with_http_method_prefix(
                        transaction_name, request)
                    zuqa.set_transaction_name(transaction_name, override=False)

                zuqa.set_context(
                    lambda: self.client.get_data_from_request(
                        request, constants.TRANSACTION), "request")
                zuqa.set_context(
                    lambda: self.client.get_data_from_response(
                        response, constants.TRANSACTION), "response")
                zuqa.set_context(lambda: self.client.get_user_info(request),
                                 "user")
                zuqa.set_transaction_result("HTTP {}xx".format(
                    response.status_code // 100),
                                            override=False)
        except Exception:
            self.client.error_logger.error(
                "Exception during timing of request", exc_info=True)
        return response
コード例 #3
0
def test_get_name_from_func_partialmethod_bound():
    class X(object):
        def x(self, x):
            pass

        p = partialmethod(x, "x")

    assert "partial(tests.utils.tests.x)" == get_name_from_func(X().p)
コード例 #4
0
    def __call__(self, func):
        self.name = self.name or get_name_from_func(func)

        @functools.wraps(func)
        def decorated(*args, **kwds):
            with self:
                return func(*args, **kwds)

        return decorated
コード例 #5
0
 def end_transaction(task_id, task, *args, **kwargs):
     name = get_name_from_func(task)
     client.end_transaction(name, kwargs.get("state", "None"))
コード例 #6
0
def test_get_name_from_func_lambda():
    assert "tests.utils.tests.<lambda>" == get_name_from_func(lambda x: "x")
コード例 #7
0
def test_get_name_from_func_partial():
    def x(x):
        pass

    p = partial(x, "x")
    assert "partial(tests.utils.tests.x)" == get_name_from_func(p)
コード例 #8
0
def test_get_name_from_func():
    def x():
        pass

    assert "tests.utils.tests.x" == get_name_from_func(x)