|
24 | 24 | from ..admin import BatchCommandAdmin, BatchCommandExecutionForm |
25 | 25 | from ..connectors.ssh import Ssh |
26 | 26 | from ..filters import GroupFilter, LocationFilter, TypeFilter |
| 27 | +from ..utils import format_modified |
27 | 28 | from ..widgets import CredentialsSchemaWidget |
28 | 29 | from .utils import BatchCommandMixin, CreateConnectionsMixin |
29 | 30 |
|
@@ -969,6 +970,28 @@ def test_change_view_command_rows(self): |
969 | 970 | self.assertEqual(rows[0]["output"], "… last") |
970 | 971 | self.assertEqual(rows[0]["status_display"], "in progress") |
971 | 972 | self.assertFalse(rows[0]["is_skipped"]) |
| 973 | + self.assertEqual( |
| 974 | + rows[0]["modified_display"], |
| 975 | + format_modified(commands[0].modified), |
| 976 | + ) |
| 977 | + |
| 978 | + with self.subTest("the rows follow the locale and the time zone"): |
| 979 | + default = self.client.get(url).context["commands"][0] |
| 980 | + with override_settings( |
| 981 | + LANGUAGE_CODE="it", TIME_ZONE="Pacific/Auckland" |
| 982 | + ): |
| 983 | + localized = self.client.get(url).context["commands"][0] |
| 984 | + self.assertEqual( |
| 985 | + localized["modified_display"], |
| 986 | + format_modified(commands[0].modified), |
| 987 | + ) |
| 988 | + self.assertNotEqual( |
| 989 | + localized["modified_display"], default["modified_display"] |
| 990 | + ) |
| 991 | + |
| 992 | + with self.subTest("skipped devices have no timestamp"): |
| 993 | + rows = self.client.get(url, {"page": 3}).context["commands"] |
| 994 | + self.assertEqual([row["modified_display"] for row in rows], [""] * 3) |
972 | 995 |
|
973 | 996 | with self.subTest("the page spanning commands and skipped devices"): |
974 | 997 | rows = self.client.get(url, {"page": 2}).context["commands"] |
@@ -1025,7 +1048,7 @@ def test_change_view_filters(self): |
1025 | 1048 | ) |
1026 | 1049 | device = self._create_device(organization=org, group=group) |
1027 | 1050 | DeviceLocation.objects.create(content_object=device, location=location) |
1028 | | - batch = self._create_batch_command(organization=org, group=group) |
| 1051 | + batch = self._create_batch_command(organization=org) |
1029 | 1052 | other_group = DeviceGroup.objects.create(name="skipped-group", organization=org) |
1030 | 1053 | skipped_device = self._create_device( |
1031 | 1054 | name="skipped-device", |
@@ -1133,20 +1156,58 @@ def test_change_view_filters(self): |
1133 | 1156 | titles = [str(spec.title) for spec in response.context["filter_specs"]] |
1134 | 1157 | self.assertNotIn("organization", titles) |
1135 | 1158 |
|
1136 | | - with self.subTest("the filters do not offer other organizations"): |
1137 | | - specs = { |
| 1159 | + def _filter_specs(target): |
| 1160 | + return { |
1138 | 1161 | str(spec.title): [str(choice["display"]) for choice in spec.choices] |
1139 | | - for spec in self.client.get(url).context["filter_specs"] |
| 1162 | + for spec in self.client.get(target).context["filter_specs"] |
1140 | 1163 | } |
1141 | | - self.assertNotIn(transferred_group.name, specs["device group"]) |
1142 | | - self.assertIn(other_group.name, specs["device group"]) |
1143 | | - self.assertNotIn(transferred_location.name, specs["location"]) |
| 1164 | + |
| 1165 | + with self.subTest("the filters do not offer other organizations"): |
| 1166 | + for login in (lambda: self.client.force_login(operator), self._login): |
| 1167 | + login() |
| 1168 | + specs = _filter_specs(url) |
| 1169 | + self.assertNotIn(transferred_group.name, specs["device group"]) |
| 1170 | + self.assertIn(other_group.name, specs["device group"]) |
| 1171 | + self.assertNotIn(transferred_location.name, specs["location"]) |
| 1172 | + self.assertIn(location.name, specs["location"]) |
| 1173 | + |
| 1174 | + with self.subTest("the filters do not wait for the commands to be created"): |
| 1175 | + fresh = self._create_batch_command(organization=org) |
| 1176 | + specs = _filter_specs( |
| 1177 | + reverse(f"admin:{self.app_label}_batchcommand_change", args=[fresh.pk]) |
| 1178 | + ) |
| 1179 | + self.assertIn(group.name, specs["device group"]) |
1144 | 1180 | self.assertIn(location.name, specs["location"]) |
1145 | | - self._login() |
1146 | | - specs = { |
1147 | | - str(spec.title): [str(choice["display"]) for choice in spec.choices] |
1148 | | - for spec in self.client.get(url).context["filter_specs"] |
1149 | | - } |
| 1181 | + self.assertNotIn("organization", specs) |
| 1182 | + |
| 1183 | + with self.subTest("the target of the batch is not offered as a filter"): |
| 1184 | + targeted = self._create_batch_command(organization=org, group=group) |
| 1185 | + specs = _filter_specs( |
| 1186 | + reverse( |
| 1187 | + f"admin:{self.app_label}_batchcommand_change", args=[targeted.pk] |
| 1188 | + ) |
| 1189 | + ) |
| 1190 | + self.assertNotIn("device group", specs) |
| 1191 | + self.assertIn("location", specs) |
| 1192 | + targeted = self._create_batch_command(organization=org, location=location) |
| 1193 | + specs = _filter_specs( |
| 1194 | + reverse( |
| 1195 | + f"admin:{self.app_label}_batchcommand_change", args=[targeted.pk] |
| 1196 | + ) |
| 1197 | + ) |
| 1198 | + self.assertNotIn("location", specs) |
| 1199 | + self.assertIn("device group", specs) |
| 1200 | + |
| 1201 | + with self.subTest("a system wide batch offers every organization"): |
| 1202 | + system_wide = self._create_batch_command(organization=None) |
| 1203 | + specs = _filter_specs( |
| 1204 | + reverse( |
| 1205 | + f"admin:{self.app_label}_batchcommand_change", |
| 1206 | + args=[system_wide.pk], |
| 1207 | + ) |
| 1208 | + ) |
| 1209 | + self.assertIn(org.name, specs["organization"]) |
| 1210 | + self.assertIn(org2.name, specs["organization"]) |
1150 | 1211 | self.assertIn(transferred_group.name, specs["device group"]) |
1151 | 1212 | self.assertIn(transferred_location.name, specs["location"]) |
1152 | 1213 |
|
|
0 commit comments