Mitja Nikolaus | 7e41c91 | 2018-09-21 14:54:26 +0200 | [diff] [blame] | 1 | """Tests for the crashreport stats template tags.""" |
| 2 | |
| 3 | from django.template import Context, Template |
| 4 | from django.test import TestCase |
| 5 | |
| 6 | from crashreport_stats.tests.utils import Dummy |
| 7 | |
| 8 | |
| 9 | class CrashreportStatsTemplateTagsTests(TestCase): |
| 10 | """Test rendering of the crashreport stats template tags.""" |
| 11 | |
| 12 | @staticmethod |
| 13 | def _create_template(template_name, parameter_keys): |
| 14 | parameters_string = " ".join( |
| 15 | ["{}={}".format(key, key) for key in parameter_keys] |
| 16 | ) |
| 17 | |
| 18 | load_template_tag_format = ( |
| 19 | "{{% load crashreport_stats_tags %}} {{% {} {} %}}" |
| 20 | ) |
| 21 | template_load_string = load_template_tag_format.format( |
| 22 | template_name, parameters_string |
| 23 | ) |
| 24 | |
| 25 | return Template(template_load_string) |
| 26 | |
| 27 | def _assert_rendered_template_contains( |
| 28 | self, template_name, parameters, *expected_contents |
| 29 | ): |
| 30 | template = self._create_template(template_name, parameters.keys()) |
| 31 | |
| 32 | rendered = template.render(Context(parameters)) |
| 33 | |
| 34 | for expected_content in expected_contents: |
| 35 | self.assertIn(expected_content, rendered) |
| 36 | |
| 37 | def test_device_overview_template(self): |
| 38 | """Test rendering of the device overview template.""" |
| 39 | template_name = "device_overview" |
| 40 | |
| 41 | title = "Device Overview Test" |
| 42 | parameters = {"title": title, "uuid": Dummy.UUIDs[0]} |
| 43 | |
| 44 | self._assert_rendered_template_contains( |
| 45 | template_name, |
| 46 | parameters, |
| 47 | title, |
| 48 | Dummy.UUIDs[0], |
| 49 | '"UUID:"', |
| 50 | '"Board Date:"', |
| 51 | '"Last Active:"', |
| 52 | '"HeartBeats sent:"', |
| 53 | '"Prob. Crashes:"', |
| 54 | '"Prob. Crashes per Day:"', |
| 55 | '"SMPLs:"', |
| 56 | '"SMPLs per Day:"', |
| 57 | ) |
| 58 | |
| 59 | def test_device_crashreport_table_template(self): |
| 60 | """Test rendering of the crashreport table template.""" |
| 61 | template_name = "device_crashreport_table" |
| 62 | |
| 63 | title = "Device Crashreport Table Test" |
| 64 | parameters = {"title": title, "uuid": Dummy.UUIDs[0]} |
| 65 | |
| 66 | self._assert_rendered_template_contains( |
| 67 | template_name, |
| 68 | parameters, |
| 69 | title, |
| 70 | Dummy.UUIDs[0], |
| 71 | '"Build Fingerprint"', |
| 72 | '"Date"', |
| 73 | '"Likely Reboot Reason"', |
| 74 | '"Logfiles"', |
| 75 | ) |
| 76 | |
| 77 | def test_device_update_history_template(self): |
| 78 | """Test rendering of the device update history template.""" |
| 79 | template_name = "device_update_history" |
| 80 | |
| 81 | title = "Device Update History Test" |
| 82 | parameters = {"title": title, "uuid": Dummy.UUIDs[0]} |
| 83 | |
| 84 | self._assert_rendered_template_contains( |
| 85 | template_name, |
| 86 | parameters, |
| 87 | title, |
| 88 | Dummy.UUIDs[0], |
| 89 | '"device_update_statistic"', |
| 90 | '"Version"', |
| 91 | '"Update Date"', |
| 92 | '"HB"', |
| 93 | '"PC"', |
| 94 | '"SMPLs"', |
| 95 | ) |
| 96 | |
| 97 | def test_device_report_history_template(self): |
| 98 | """Test rendering of the device report history template.""" |
| 99 | template_name = "device_report_history" |
| 100 | |
| 101 | title = "Device Report History Test" |
| 102 | parameters = {"title": title, "uuid": Dummy.UUIDs[0]} |
| 103 | |
| 104 | self._assert_rendered_template_contains( |
| 105 | template_name, |
| 106 | parameters, |
| 107 | title, |
| 108 | Dummy.UUIDs[0], |
| 109 | "'Date'", |
| 110 | "'Heartbeats'", |
| 111 | "'prob. Crashes'", |
| 112 | "'SMPL'", |
| 113 | "'other'", |
| 114 | ) |
| 115 | |
| 116 | def test_versions_table_template(self): |
| 117 | """Test rendering of the versions table template.""" |
| 118 | template_name = "versions_table" |
| 119 | |
| 120 | title = "FP2 OS Versions Test" |
| 121 | parameters = {"title": title, "is_official_release": True} |
| 122 | |
| 123 | self._assert_rendered_template_contains( |
| 124 | template_name, |
| 125 | parameters, |
| 126 | title, |
| 127 | 'is_official_release: "True"', |
| 128 | '"versions_overview_table"', |
| 129 | '"Version"', |
| 130 | '"HB"', |
| 131 | '"PC"', |
| 132 | '"SMPLs"', |
| 133 | ) |
| 134 | |
| 135 | def test_versions_pie_chart_template(self): |
| 136 | """Test rendering of the versions pie chart template.""" |
| 137 | template_name = "versions_pie_chart" |
| 138 | |
| 139 | title = "FP2 Version Distribution Test" |
| 140 | parameters = {"title": title, "is_official_release": True} |
| 141 | |
| 142 | self._assert_rendered_template_contains( |
| 143 | template_name, |
| 144 | parameters, |
| 145 | title, |
| 146 | 'is_official_release: "True"', |
| 147 | '"versions_overview_pie_chart"', |
| 148 | ) |
| 149 | |
| 150 | def test_versions_area_chart_template(self): |
| 151 | """Test rendering of the versions area chart template.""" |
| 152 | template_name = "versions_area_chart" |
| 153 | |
| 154 | title = "FP2 Version Distribution Test" |
| 155 | parameters = {"title": title, "is_official_release": True} |
| 156 | |
| 157 | self._assert_rendered_template_contains( |
| 158 | template_name, |
| 159 | parameters, |
| 160 | title, |
| 161 | 'is_official_release: "True"', |
| 162 | '"versions_overview_area_chart"', |
| 163 | ) |
| 164 | |
| 165 | def test_versions_bar_chart_template(self): |
| 166 | """Test rendering of the versions bar chart template.""" |
| 167 | template_name = "versions_bar_chart" |
| 168 | |
| 169 | title = "Version Stability Test" |
| 170 | parameters = {"title": title, "is_official_release": True} |
| 171 | |
| 172 | self._assert_rendered_template_contains( |
| 173 | template_name, |
| 174 | parameters, |
| 175 | title, |
| 176 | 'is_official_release: "True"', |
| 177 | '"versions_overview_bar_chart"', |
| 178 | ) |