chore: add tests for tracking mode

This commit is contained in:
Sergey Motornyuk 2023-06-14 20:28:47 +03:00
parent acb7a81bc4
commit 2cee663cf3
2 changed files with 24 additions and 7 deletions

View File

@ -0,0 +1,14 @@
import pytest
from ckanext.googleanalytics import config
@pytest.mark.parametrize(("tracking_id", "mode"), [
("UA-123", "ga"),
("G-123", "gtag"),
("GTM-123", "gtm"),
("HELLO-123", "ga"),
])
def test_tracking_mode(tracking_id, mode, monkeypatch, ckan_config):
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_ID, tracking_id)
assert mode == config.tracking_mode()

View File

@ -3,6 +3,14 @@ import pytest
import ckan.plugins.toolkit as tk
from ckanext.googleanalytics import config
def _render_header(mode, tracking_id):
return tk.render_snippet("googleanalytics/snippets/_{}.html".format(mode), {
"googleanalytics_id": tracking_id,
"googleanalytics_domain": config.domain(),
"googleanalytics_fields": config.fields(),
"googleanalytics_linked_domains": config.linked_domains()
})
@pytest.mark.usefixtures("with_plugins", "with_request_context")
class TestCodeSnippets:
@ -12,11 +20,6 @@ class TestCodeSnippets:
snippet = tk.h.googleanalytics_header()
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_ID, tracking_id)
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_MODE, mode)
snippet = tk.render_snippet("googleanalytics/snippets/_{}.html".format(mode), {
"googleanalytics_id": tracking_id,
"googleanalytics_domain": config.domain(),
"googleanalytics_fields": config.fields(),
"googleanalytics_linked_domains": config.linked_domains()
})
resp = app.get("/")
snippet = _render_header(mode, tracking_id)
resp = app.get("/about")
assert snippet in resp.body