|
| 1 | +from django.conf import settings |
1 | 2 | from django.db.models.signals import post_save |
2 | 3 | from django.utils.translation import gettext_lazy as _ |
3 | 4 | from swapper import get_model_name, load_model |
@@ -26,6 +27,35 @@ def ready(self, *args, **kwargs): |
26 | 27 | super().ready(*args, **kwargs) |
27 | 28 | self.register_menu_groups() |
28 | 29 | self.connect_device_signals() |
| 30 | + if getattr(settings, "TESTING", False): |
| 31 | + self._add_params_to_test_config() |
| 32 | + |
| 33 | + def _add_params_to_test_config(self): |
| 34 | + """ |
| 35 | + this methods adds the management fields of BaseTestAdmin |
| 36 | + to the parameters used in config.tests.test_admin.TestAdmin |
| 37 | + this hack is needed for the following reasons: |
| 38 | + - avoids breaking config.tests.test_admin.TestAdmin |
| 39 | + - avoids adding logic of firmware_upgrader app in config, this |
| 40 | + way config doesn't know anything about firmware_upgrader, keeping |
| 41 | + complexity down to a sane level |
| 42 | + """ |
| 43 | + from openwisp_controller.config.tests.test_admin import ( |
| 44 | + TestAdmin as TestConfigAdmin, |
| 45 | + ) |
| 46 | + |
| 47 | + from .tests.test_admin import BaseTestAdmin |
| 48 | + |
| 49 | + params = BaseTestAdmin._device_params |
| 50 | + delete_keys = [] |
| 51 | + # delete unnecessary fields |
| 52 | + # leave only management fields |
| 53 | + for key in params.keys(): |
| 54 | + if "_FORMS" not in key: |
| 55 | + delete_keys.append(key) |
| 56 | + for key in delete_keys: |
| 57 | + del params[key] |
| 58 | + TestConfigAdmin._additional_params.update(params) |
29 | 59 |
|
30 | 60 | def register_menu_groups(self): |
31 | 61 | register_menu_group( |
|
0 commit comments