|
4 | 4 | # http://creativecommons.org/publicdomain/zero/1.0/ |
5 | 5 |
|
6 | 6 | from pathlib import Path |
| 7 | +import json |
7 | 8 | import re |
8 | 9 | import sys |
9 | 10 | import textwrap |
@@ -901,3 +902,66 @@ def test_no_lint_sorted(): |
901 | 902 | assert all_objects.value["category"]["metric"].no_lint == ["lint1", "lint2"] |
902 | 903 | assert all_objects.value["pings"]["ping"].no_lint == ["lint1", "lint2"] |
903 | 904 | assert all_objects.value["tags"]["tag"].no_lint == ["lint1", "lint2"] |
| 905 | + |
| 906 | + |
| 907 | +def test_no_internal_fields_exposed(): |
| 908 | + """ |
| 909 | + We accidentally exposed fields like `_config` and `_generate_enums` before. |
| 910 | + These ended up in probe-scraper output. |
| 911 | +
|
| 912 | + We replicate the code probe-scraper uses |
| 913 | + and ensure we get the JSON we expect from it. |
| 914 | + """ |
| 915 | + |
| 916 | + results = parser.parse_objects( |
| 917 | + [ |
| 918 | + util.add_required( |
| 919 | + { |
| 920 | + "category": { |
| 921 | + "metric": { |
| 922 | + "type": "event", |
| 923 | + "extra_keys": { |
| 924 | + "key_a": {"description": "desc-a", "type": "boolean"} |
| 925 | + }, |
| 926 | + } |
| 927 | + }, |
| 928 | + } |
| 929 | + ), |
| 930 | + ] |
| 931 | + ) |
| 932 | + errs = list(results) |
| 933 | + assert len(errs) == 0 |
| 934 | + |
| 935 | + metrics = { |
| 936 | + metric.identifier(): metric.serialize() |
| 937 | + for category, probes in results.value.items() |
| 938 | + for probe_name, metric in probes.items() |
| 939 | + } |
| 940 | + |
| 941 | + expected = { |
| 942 | + "category.metric": { |
| 943 | + "bugs": ["http://bugzilla.mozilla.org/12345678"], |
| 944 | + "data_reviews": ["https://example.com/review/"], |
| 945 | + "defined_in": {"line": 3}, |
| 946 | + "description": "DESCRIPTION...", |
| 947 | + "disabled": False, |
| 948 | + "expires": "never", |
| 949 | + "extra_keys": {"key_a": {"description": "desc-a", "type": "boolean"}}, |
| 950 | + "gecko_datapoint": "", |
| 951 | + "lifetime": "ping", |
| 952 | + "metadata": {}, |
| 953 | + "no_lint": [], |
| 954 | + "notification_emails": ["nobody@example.com"], |
| 955 | + "send_in_pings": ["events"], |
| 956 | + "type": "event", |
| 957 | + "version": 0, |
| 958 | + } |
| 959 | + } |
| 960 | + expected_json = json.dumps(expected, sort_keys=True, indent=2) |
| 961 | + |
| 962 | + out_json = json.dumps( |
| 963 | + metrics, |
| 964 | + sort_keys=True, |
| 965 | + indent=2, |
| 966 | + ) |
| 967 | + assert expected_json == out_json |
0 commit comments