Skip to content

Commit

Permalink
Merge branch 'main' into add-config-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lrafeei authored Jun 30, 2023
2 parents 1ec9bb5 + 3bdb013 commit 0f2313e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/template_jinja2/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from testing_support.fixtures import ( # noqa: F401; pylint: disable=W0611
collector_agent_registration_fixture,
collector_available_fixture,
)

_default_settings = {
"transaction_tracer.explain_threshold": 0.0,
"transaction_tracer.transaction_threshold": 0.0,
"transaction_tracer.stack_trace_threshold": 0.0,
"debug.log_data_collector_payloads": True,
"debug.record_transaction_failure": True,
}

collector_agent_registration = collector_agent_registration_fixture(
app_name="Python Agent Test (template_jinja2)", default_settings=_default_settings
)
41 changes: 41 additions & 0 deletions tests/template_jinja2/test_jinja2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from jinja2 import Template
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task


@validate_transaction_metrics(
"test_render",
background_task=True,
scoped_metrics=(
("Template/Render/<template>", 1),
("Template/Compile/<template>", 1),
),
)
@background_task(name="test_render")
def test_render():
template_to_render = Template("hello, {{ name }}!")
result = template_to_render.render(name="NR")
assert result == "hello, NR!"


def test_render_outside_txn():
template_to_render = Template("hello, {{ name }}!")
result = template_to_render.render(name="NR")
assert result == "hello, NR!"
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ envlist =
kafka-messagebroker_kafkapython-{pypy27,py27,py37,py38,pypy38}-kafkapythonlatest,
kafka-messagebroker_kafkapython-{py27,py38}-kafkapython{020001,020000,0104},
python-template_genshi-{py27,py37,py311}-genshilatest
python-template_jinja2-{py37,py311}-jinja2latest
python-template_mako-{py27,py37,py310,py311}

[testenv]
Expand Down Expand Up @@ -382,6 +383,7 @@ deps =
messagebroker_kafkapython-kafkapython020000: kafka-python<2.0.1
messagebroker_kafkapython-kafkapython0104: kafka-python<1.5
template_genshi-genshilatest: genshi
template_jinja2-jinja2latest: Jinja2
template_mako: mako

setenv =
Expand Down Expand Up @@ -491,6 +493,7 @@ changedir =
messagebroker_confluentkafka: tests/messagebroker_confluentkafka
messagebroker_kafkapython: tests/messagebroker_kafkapython
template_genshi: tests/template_genshi
template_jinja2: tests/template_jinja2
template_mako: tests/template_mako

[pytest]
Expand Down

0 comments on commit 0f2313e

Please sign in to comment.