Bug 1383793 Added test to make sure whitelist is used correctly for histogram_tools.py r=chutten draft
authorJordan Hu <jhu.jordan@gmail.com>
Mon, 02 Apr 2018 00:59:49 -0400
changeset 776370 7ea9db19e7ca8cc0774a1a399380f5210e0906f0
parent 765132 31a33fc619562e5b326585c6864d86832dac5126
child 780041 71b594627657cd463a378f229339e0ed73708b75
push id104858
push userbmo:jhu.jordan@gmail.com
push dateMon, 02 Apr 2018 22:50:15 +0000
reviewerschutten
bugs1383793
milestone60.0a1
Bug 1383793 Added test to make sure whitelist is used correctly for histogram_tools.py r=chutten MozReview-Commit-ID: FAD6fiMbPWx
toolkit/components/telemetry/tests/python/python.ini
toolkit/components/telemetry/tests/python/test_histogramtools_strict.py
--- a/toolkit/components/telemetry/tests/python/python.ini
+++ b/toolkit/components/telemetry/tests/python/python.ini
@@ -1,1 +1,2 @@
 [test_histogramtools_non_strict.py]
+[test_histogramtools_strict.py]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/python/test_histogramtools_strict.py
@@ -0,0 +1,96 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.import json
+
+import mozunit
+import sys
+import unittest
+from os import path
+from test_histogramtools_non_strict import load_histogram
+
+TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir))
+sys.path.append(TELEMETRY_ROOT_PATH)
+from shared_telemetry_utils import ParserError
+import parse_histograms
+
+
+class TestParser(unittest.TestCase):
+    def test_valid_histogram(self):
+        SAMPLE_HISTOGRAM = {
+            "TEST_VALID_HISTOGRAM": {
+                "record_in_processes": ["main", "content"],
+                "expires_in_version": "never",
+                "kind": "boolean",
+                "alert_emails": ["team@mozilla.xyz"],
+                "description": "Test histogram",
+                "bug_numbers": [1383793]
+            }
+        }
+        histograms = load_histogram(SAMPLE_HISTOGRAM)
+        parse_histograms.load_whitelist()
+
+        hist = parse_histograms.Histogram('TEST_VALID_HISTOGRAM',
+                                          histograms['TEST_VALID_HISTOGRAM'],
+                                          strict_type_checks=True)
+
+        ParserError.exit_func()
+        self.assertTrue(hist.expiration(), "never")
+        self.assertTrue(hist.kind(), "boolean")
+        self.assertTrue(hist.record_in_processes, ["main", "content"])
+
+    def test_missing_bug_numbers_histogram(self):
+        SAMPLE_HISTOGRAM = {
+            "TEST_WHITELIST_HISTOGRAM": {
+                "record_in_processes": ["main", "content"],
+                "expires_in_version": "never",
+                "kind": "boolean",
+                "alert_emails": ["team@mozilla.xyz"],
+                "description": "Test histogram"
+            }
+        }
+        histograms = load_histogram(SAMPLE_HISTOGRAM)
+        parse_histograms.load_whitelist()
+
+        hist = parse_histograms.Histogram('TEST_WHITELIST_HISTOGRAM',
+                                          histograms['TEST_WHITELIST_HISTOGRAM'],
+                                          strict_type_checks=True)
+
+        self.assertRaises(SystemExit, ParserError.exit_func)
+
+    def test_histogram_on_whitelist(self):
+        SAMPLE_HISTOGRAM = {
+            "TEST_WHITELIST_HISTOGRAM": {
+                "record_in_processes": ["main", "content"],
+                "expires_in_version": "never",
+                "kind": "boolean",
+                "alert_emails": ["team@mozilla.xyz"],
+                "description": "has accessibility support been instantiated",
+            }
+        }
+        histograms = load_histogram(SAMPLE_HISTOGRAM)
+
+        # set global whitelists for parse_histograms
+        parse_histograms.whitelists = {
+            "alert_emails": [],
+            "bug_numbers": [
+                "TEST_WHITELIST_HISTOGRAM"
+            ],
+            "n_buckets": [],
+            "expiry_default": [],
+            "kind": []
+        }
+
+        hist = parse_histograms.Histogram('TEST_WHITELIST_HISTOGRAM',
+                                          histograms['TEST_WHITELIST_HISTOGRAM'],
+                                          strict_type_checks=True)
+
+        ParserError.exit_func()
+        self.assertEqual(hist.expiration(), 'never')
+        self.assertEqual(hist.kind(), 'boolean')
+        self.assertEqual(hist.record_in_processes(), ["main", "content"])
+        self.assertEqual(hist.keyed(), False)
+
+        parse_histograms.whitelists = None
+
+if __name__ == '__main__':
+    mozunit.main()