Skip to content

Commit 8cf4f08

Browse files
author
Alexandre Vincent
committed
[fix] Replicate geo config_test_param hack in firmware_upgrader
1 parent f7b10d1 commit 8cf4f08

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

openwisp_firmware_upgrader/apps.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.conf import settings
12
from django.db.models.signals import post_save
23
from django.utils.translation import gettext_lazy as _
34
from swapper import get_model_name, load_model
@@ -26,6 +27,35 @@ def ready(self, *args, **kwargs):
2627
super().ready(*args, **kwargs)
2728
self.register_menu_groups()
2829
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)
2959

3060
def register_menu_groups(self):
3161
register_menu_group(

0 commit comments

Comments
 (0)