Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for genshi and mako. #799

Merged
merged 7 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/template_genshi/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_genshi)", default_settings=_default_settings
)
38 changes: 38 additions & 0 deletions tests/template_genshi/test_genshi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 genshi.template import MarkupTemplate
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/genshi.core:Stream.render", 1),),
)
@background_task(name="test_render")
def test_render():
template_to_render = MarkupTemplate("<h1>hello, $name!</h1>")
result = template_to_render.generate(name="NR").render("xhtml")
assert result == "<h1>hello, NR!</h1>"


def test_render_outside_txn():
template_to_render = MarkupTemplate("<h1>hello, $name!</h1>")
result = template_to_render.generate(name="NR").render("xhtml")
assert result == "<h1>hello, NR!</h1>"
17 changes: 13 additions & 4 deletions tests/template_mako/test_mako.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@
# limitations under the License.

from mako.template import Template
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task


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


def test_render_outside_txn():
template = Template("hello, ${name}!")
result = template.render(name="NR")
assert result == "hello, NR!"
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ envlist =
kafka-messagebroker_confluentkafka-{py39}-confluentkafka{0108},
kafka-messagebroker_kafkapython-{pypy,py27,py37,py38,pypy37}-kafkapythonlatest,
kafka-messagebroker_kafkapython-{py27,py38}-kafkapython{020001,020000,0104},
python-template_mako-{py27,py37,py38,py39,py310,py311}
python-template_genshi-{py27,py37,py311}-genshilatest
python-template_mako-{py27,py37,py310,py311}

[testenv]
deps =
Expand Down Expand Up @@ -377,7 +378,8 @@ deps =
messagebroker_kafkapython-kafkapython020001: kafka-python<2.0.2
messagebroker_kafkapython-kafkapython020000: kafka-python<2.0.1
messagebroker_kafkapython-kafkapython0104: kafka-python<1.5
template_mako: mako<1.2
template_genshi-genshilatest: genshi
template_mako: mako

setenv =
PYTHONPATH={toxinidir}/tests
Expand Down Expand Up @@ -487,6 +489,7 @@ changedir =
messagebroker_pika: tests/messagebroker_pika
messagebroker_confluentkafka: tests/messagebroker_confluentkafka
messagebroker_kafkapython: tests/messagebroker_kafkapython
template_genshi: tests/template_genshi
template_mako: tests/template_mako

[pytest]
Expand Down