Skip to content

Commit 7fbbe79

Browse files
committed
[tests/fix] Test passing arbitrary org params to register view
- test_register_with_org_id: the test was passing without any change - test_register_with_org_param: trying to pass the org ID in the "organization" parameter caused an uncaught exception, the change in the code fixes the error
1 parent cb6f91e commit 7fbbe79

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

openwisp_controller/config/controller/views.py

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ def init_object(self, **kwargs):
280280
config_model = device_model.get_config_model()
281281
options = {}
282282
for attr in kwargs.keys():
283+
if attr in ['organization', 'organization_id']:
284+
continue
283285
# skip attributes that are not model fields
284286
try:
285287
device_model._meta.get_field(attr)

openwisp_controller/config/tests/test_controller.py

+15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Vpn = load_model('config', 'Vpn')
3737
Ca = load_model('django_x509', 'Ca')
3838
OrganizationConfigSettings = load_model('config', 'OrganizationConfigSettings')
39+
Organization = load_model('openwisp_users', 'Organization')
3940

4041

4142
class TestController(
@@ -430,6 +431,20 @@ def test_register(self, **kwargs):
430431
def test_register_with_management_ip(self):
431432
self.test_register(management_ip='10.0.0.2')
432433

434+
def test_register_with_org_id(self):
435+
org1 = self._get_org()
436+
org2 = Organization.objects.create(name='org2', slug='org2')
437+
device = self.test_register(organization_id=str(org2.id))
438+
self.assertEqual(device.organization, org1)
439+
self.assertNotEqual(device.organization, org2)
440+
441+
def test_register_with_org_param(self):
442+
org1 = self._get_org()
443+
org2 = Organization.objects.create(name='org2', slug='org2')
444+
device = self.test_register(organization=str(org2.id))
445+
self.assertEqual(device.organization, org1)
446+
self.assertNotEqual(device.organization, org2)
447+
433448
def test_register_exceeds_org_device_limit(self):
434449
org = self._get_org()
435450
org.config_limits.device_limit = 1

0 commit comments

Comments
 (0)