diff --git a/ckanext/googleanalytics/tests/test_config.py b/ckanext/googleanalytics/tests/test_config.py new file mode 100644 index 0000000..5abf359 --- /dev/null +++ b/ckanext/googleanalytics/tests/test_config.py @@ -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() diff --git a/ckanext/googleanalytics/tests/test_view.py b/ckanext/googleanalytics/tests/test_view.py index cb73da3..80ef9e9 100644 --- a/ckanext/googleanalytics/tests/test_view.py +++ b/ckanext/googleanalytics/tests/test_view.py @@ -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