Skip to content

Commit

Permalink
[Fix] Save config updated details in device update API openwisp#658
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp committed Jun 18, 2022
1 parent 4860664 commit 0c0da6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions openwisp_controller/config/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def update(self, instance, validated_data):
instance.config.vpnclient_set.exclude(vpn__in=vpn_list).delete()
instance.config.templates.clear()
instance.config.templates.add(*[])
instance.config.save()

elif hasattr(instance, 'config') and validated_data.get('organization'):
if instance.organization != validated_data.get('organization'):
Expand Down
7 changes: 6 additions & 1 deletion openwisp_controller/config/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_device_put_api(self):
'organization': org.pk,
'mac_address': d1.mac_address,
'config': {
'backend': 'netjsonconfig.OpenWrt',
'backend': 'netjsonconfig.OpenWisp',
'status': 'modified',
'templates': [],
'context': '{}',
Expand All @@ -212,6 +212,11 @@ def test_device_put_api(self):
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data['name'], 'change-test-device')
self.assertEqual(r.data['organization'], org.pk)
self.assertEqual(r.data['config']['backend'], 'netjsonconfig.OpenWisp')
d1.refresh_from_db()
self.assertEqual(d1.name, 'change-test-device')
self.assertEqual(d1.organization, org)
self.assertEqual(d1.config.backend, 'netjsonconfig.OpenWisp')

# test device with VPN-client type template assigned to it
def test_device_with_vpn_client_template_assigned(self):
Expand Down

0 comments on commit 0c0da6b

Please sign in to comment.