Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests/fix] Test passing arbitrary org params to register view #819

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openwisp_controller/config/controller/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def init_object(self, **kwargs):
config_model = device_model.get_config_model()
options = {}
for attr in kwargs.keys():
if attr in ['organization', 'organization_id']:
continue
# skip attributes that are not model fields
try:
device_model._meta.get_field(attr)
Expand Down
15 changes: 15 additions & 0 deletions openwisp_controller/config/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Vpn = load_model('config', 'Vpn')
Ca = load_model('django_x509', 'Ca')
OrganizationConfigSettings = load_model('config', 'OrganizationConfigSettings')
Organization = load_model('openwisp_users', 'Organization')


class TestController(
Expand Down Expand Up @@ -430,6 +431,20 @@ def test_register(self, **kwargs):
def test_register_with_management_ip(self):
self.test_register(management_ip='10.0.0.2')

def test_register_with_org_id(self):
org1 = self._get_org()
org2 = Organization.objects.create(name='org2', slug='org2')
device = self.test_register(organization_id=str(org2.id))
self.assertEqual(device.organization, org1)
self.assertNotEqual(device.organization, org2)

def test_register_with_org_param(self):
org1 = self._get_org()
org2 = Organization.objects.create(name='org2', slug='org2')
device = self.test_register(organization=str(org2.id))
self.assertEqual(device.organization, org1)
self.assertNotEqual(device.organization, org2)

def test_register_exceeds_org_device_limit(self):
org = self._get_org()
org.config_limits.device_limit = 1
Expand Down
Loading