|
1 | 1 | from django.contrib.auth.models import Permission |
2 | 2 | from django.test import TestCase |
| 3 | +from django.test.client import BOUNDARY, MULTIPART_CONTENT, encode_multipart |
3 | 4 | from django.test.testcases import TransactionTestCase |
4 | 5 | from django.urls import reverse |
5 | 6 | from openwisp_ipam.tests import CreateModelsMixin as CreateIpamModelsMixin |
|
10 | 11 | from openwisp_users.tests.utils import TestOrganizationMixin |
11 | 12 | from openwisp_utils.tests import capture_any_output, catch_signal |
12 | 13 |
|
| 14 | +from .. import settings as app_settings |
13 | 15 | from ..signals import group_templates_changed |
14 | 16 | from .utils import ( |
15 | 17 | CreateConfigTemplateMixin, |
@@ -354,6 +356,31 @@ def test_device_put_api(self): |
354 | 356 | self.assertEqual(d1.organization, org) |
355 | 357 | self.assertEqual(d1.config.backend, 'netjsonconfig.OpenWisp') |
356 | 358 |
|
| 359 | + def test_device_put_api_with_default_config_values(self): |
| 360 | + device = self._create_device(name='test-device') |
| 361 | + path = reverse('config_api:device_detail', args=[device.pk]) |
| 362 | + org = self._get_org() |
| 363 | + data = { |
| 364 | + 'name': 'change-test-device', |
| 365 | + 'organization': org.pk, |
| 366 | + 'mac_address': device.mac_address, |
| 367 | + 'config.backend': app_settings.DEFAULT_BACKEND, |
| 368 | + 'config.templates': [], |
| 369 | + 'config.context': 'null', |
| 370 | + 'config.config': 'null', |
| 371 | + } |
| 372 | + self.assertEqual(Config.objects.count(), 0) |
| 373 | + response = self.client.put( |
| 374 | + path, encode_multipart(BOUNDARY, data), content_type=MULTIPART_CONTENT |
| 375 | + ) |
| 376 | + self.assertEqual(response.status_code, 200) |
| 377 | + self.assertEqual(response.data['name'], 'change-test-device') |
| 378 | + self.assertEqual(response.data['organization'], org.pk) |
| 379 | + device.refresh_from_db() |
| 380 | + self.assertEqual(device.name, 'change-test-device') |
| 381 | + self.assertEqual(device.organization, org) |
| 382 | + self.assertEqual(Config.objects.count(), 0) |
| 383 | + |
357 | 384 | def test_device_api_change_config_backend(self): |
358 | 385 | t1 = self._create_template(name='t1', backend='netjsonconfig.OpenWrt') |
359 | 386 | t2 = self._create_template(name='t2', backend='netjsonconfig.OpenWisp') |
|
0 commit comments