Skip to content

Commit 63af4a4

Browse files
[fix] Restored disappeared download configuration button #259
Fixes #259
1 parent ee590ef commit 63af4a4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

openwisp_controller/config/admin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def get_extra_context(self, pk=None):
9090
if pk:
9191
ctx['download_url'] = reverse('{0}_download'.format(prefix), args=[pk])
9292
try:
93-
has_config = (
94-
self.model.__name__ == 'Device'
95-
and self.model.objects.get(pk=pk)._has_config()
96-
)
93+
has_config = True
94+
if self.model.__name__ == 'Device':
95+
has_config = self.model.objects.get(pk=pk)._has_config()
9796
except (ObjectDoesNotExist, ValidationError):
9897
raise Http404()
9998
else:

openwisp_controller/config/tests/test_admin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,12 @@ def test_download_template_config(self):
614614
response = self.client.get(path)
615615
self.assertEqual(response.get('content-type'), 'application/octet-stream')
616616

617+
def test_template_has_download_config(self):
618+
t = Template.objects.first()
619+
path = reverse(f'admin:{self.app_label}_template_change', args=[t.pk])
620+
r = self.client.get(path)
621+
self.assertContains(r, 'Download configuration')
622+
617623
def test_preview_template(self):
618624
template = Template.objects.get(name='radio0')
619625
path = reverse(f'admin:{self.app_label}_template_preview')
@@ -759,6 +765,12 @@ def test_download_vpn_config(self):
759765
response = self.client.get(path)
760766
self.assertEqual(response.get('content-type'), 'application/octet-stream')
761767

768+
def test_vpn_has_download_config(self):
769+
v = self._create_vpn()
770+
path = reverse(f'admin:{self.app_label}_vpn_change', args=[v.pk])
771+
r = self.client.get(path)
772+
self.assertContains(r, 'Download configuration')
773+
762774
def test_preview_vpn(self):
763775
v = self._create_vpn()
764776
path = reverse(f'admin:{self.app_label}_vpn_preview')
@@ -810,6 +822,14 @@ def test_error_if_download_config(self):
810822
)
811823
self.assertNotContains(res, 'Download configuration')
812824

825+
def test_device_has_download_config(self):
826+
d = self._create_device()
827+
t = Template.objects.first()
828+
self._create_config(device=d, backend=t.backend, config=t.config)
829+
path = reverse(f'admin:{self.app_label}_device_change', args=[d.pk])
830+
r = self.client.get(path)
831+
self.assertContains(r, 'Download configuration')
832+
813833
def test_preview_device_with_context(self):
814834
path = reverse(f'admin:{self.app_label}_device_preview')
815835
config = json.dumps(

0 commit comments

Comments
 (0)