Skip to content

Commit

Permalink
[change] Revert "[chore] Renamed device_group > devicegroup in code"
Browse files Browse the repository at this point in the history
This reverts commit 8de60b2.
  • Loading branch information
nemesifier committed Jul 15, 2021
1 parent e2e725a commit 702be03
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 55 deletions.
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ Allows to specify backend URL for API requests, if the frontend is hosted separa
Allows to specify a `list` of tuples for adding commands as described in
`'How to add commands" <#how-to-add-commands>`_ section.

``OPENWISP_CONTROLLER_DEVICEGROUP_SCHEMA``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``OPENWISP_CONTROLLER_DEVICE_GROUP_SCHEMA``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+--------------+------------------------------------------+
| **type**: | ``dict`` |
Expand Down Expand Up @@ -1092,7 +1092,7 @@ You can achieve following by using Device Groups:
- Group similar devices by having dedicated groups for access points, routers, etc.
- Store additional information regarding a group in the structured metadata field.
- Customize structure and validation of metadata field of DeviceGroup to standardize
information across all groups using `"OPENWISP_CONTROLLER_DEVICEGROUP_SCHEMA" <#openwisp-controller-devicegroup-schema>`_
information across all groups using `"OPENWISP_CONTROLLER_DEVICE_GROUP_SCHEMA" <#openwisp-controller-device-group-schema>`_
setting.

.. image:: https://raw.githubusercontent.com/openwisp/openwisp-controller/master/docs/device-groups.png
Expand Down Expand Up @@ -1680,10 +1680,10 @@ The signal is emitted when the device name changes.

It is not emitted when the device is created.

``devicegroup_changed``
~~~~~~~~~~~~~~~~~~~~~~~
``device_group_changed``
~~~~~~~~~~~~~~~~~~~~~~~~

**Path**: ``openwisp_controller.config.signals.devicegroup_changed``
**Path**: ``openwisp_controller.config.signals.device_group_changed``

**Arguments**:

Expand Down
2 changes: 1 addition & 1 deletion openwisp_controller/config/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def get_urls(self):
return urls

def schema_view(self, request):
return JsonResponse(app_settings.DEVICEGROUP_SCHEMA)
return JsonResponse(app_settings.DEVICE_GROUP_SCHEMA)


admin.site.register(Device, DeviceAdmin)
Expand Down
4 changes: 2 additions & 2 deletions openwisp_controller/config/base/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from openwisp_utils.base import KeyField

from .. import settings as app_settings
from ..signals import device_name_changed, devicegroup_changed, management_ip_changed
from ..signals import device_group_changed, device_name_changed, management_ip_changed
from ..validators import device_name_validator, mac_address_validator
from .base import BaseModel

Expand Down Expand Up @@ -240,7 +240,7 @@ def _check_group_id_changed(self):
return

if self._initial_group_id != self.group_id:
devicegroup_changed.send(
device_group_changed.send(
sender=self.__class__,
instance=self,
group_id=self.group_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Meta:

def clean(self):
try:
jsonschema.Draft4Validator(app_settings.DEVICEGROUP_SCHEMA).validate(
jsonschema.Draft4Validator(app_settings.DEVICE_GROUP_SCHEMA).validate(
self.meta_data
)
except SchemaError as e:
Expand Down
2 changes: 1 addition & 1 deletion openwisp_controller/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .base.config import AbstractConfig
from .base.device import AbstractDevice
from .base.devicegroup import AbstractDeviceGroup
from .base.device_group import AbstractDeviceGroup
from .base.multitenancy import AbstractOrganizationConfigSettings
from .base.tag import AbstractTaggedTemplate, AbstractTemplateTag
from .base.template import AbstractTemplate
Expand Down
4 changes: 2 additions & 2 deletions openwisp_controller/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def get_settings_value(option, default):
'DEVICE_VERBOSE_NAME', (_('Device'), _('Devices'))
)
DEVICE_NAME_UNIQUE = get_settings_value('DEVICE_NAME_UNIQUE', True)
DEVICEGROUP_SCHEMA = get_settings_value(
'DEVICEGROUP_SCHEMA', {'type': 'object', 'properties': {}}
DEVICE_GROUP_SCHEMA = get_settings_value(
'DEVICE_GROUP_SCHEMA', {'type': 'object', 'properties': {}}
)
2 changes: 1 addition & 1 deletion openwisp_controller/config/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
providing_args=['instance', 'management_ip', 'old_management_ip']
)
device_name_changed = Signal(providing_args=['instance'])
devicegroup_changed = Signal(providing_args=['instance', 'group', 'old_group'])
device_group_changed = Signal(providing_args=['instance', 'group', 'old_group'])
8 changes: 4 additions & 4 deletions openwisp_controller/config/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,8 @@ def test_multitenant_admin(self):
).user
user.groups.add(Group.objects.get(name='Operator'))

self._create_devicegroup(name='Org1 APs', organization=org1)
self._create_devicegroup(name='Org2 APs', organization=org2)
self._create_device_group(name='Org1 APs', organization=org1)
self._create_device_group(name='Org2 APs', organization=org2)
self.client.logout()
self.client.force_login(user)

Expand All @@ -1240,8 +1240,8 @@ def test_multitenant_admin(self):
def test_organization_filter(self):
org1 = self._create_org(name='org1')
org2 = self._create_org(name='org1')
self._create_devicegroup(name='Org1 APs', organization=org1)
self._create_devicegroup(name='Org2 APs', organization=org2)
self._create_device_group(name='Org1 APs', organization=org1)
self._create_device_group(name='Org2 APs', organization=org2)
url = reverse(f'admin:{self.app_label}_devicegroup_changelist')
query = f'?organization__id__exact={org1.pk}'
response = self.client.get(url)
Expand Down
26 changes: 14 additions & 12 deletions openwisp_controller/config/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ def test_device_create_with_devicegroup(self):
path = reverse('config_api:device_list')
data = self._get_device_data.copy()
org = self._get_org()
devicegroup = self._create_devicegroup()
device_group = self._create_device_group()
data['organization'] = org.pk
data['group'] = devicegroup.pk
data['group'] = device_group.pk
response = self.client.post(path, data, content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertEqual(Device.objects.count(), 1)
self.assertEqual(response.data['group'], devicegroup.pk)
self.assertEqual(response.data['group'], device_group.pk)

def test_device_list_api(self):
self._create_device()
Expand Down Expand Up @@ -591,24 +591,26 @@ def test_devicegroup_create_api(self):
self.assertEqual(response.data['organization'], org.pk)

def test_devicegroup_list_api(self):
self._create_devicegroup()
self._create_device_group()
path = reverse('config_api:devicegroup_list')
with self.assertNumQueries(4):
r = self.client.get(path)
self.assertEqual(r.status_code, 200)

def test_devicegroup_detail_api(self):
devicegroup = self._create_devicegroup()
path = reverse('config_api:devicegroup_detail', args=[devicegroup.pk])
device_group = self._create_device_group()
path = reverse('config_api:devicegroup_detail', args=[device_group.pk])

with self.subTest('Test GET'):
with self.assertNumQueries(3):
response = self.client.get(path)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['name'], devicegroup.name)
self.assertEqual(response.data['description'], devicegroup.description)
self.assertDictEqual(response.data['meta_data'], devicegroup.meta_data)
self.assertEqual(response.data['organization'], devicegroup.organization.pk)
self.assertEqual(response.data['name'], device_group.name)
self.assertEqual(response.data['description'], device_group.description)
self.assertDictEqual(response.data['meta_data'], device_group.meta_data)
self.assertEqual(
response.data['organization'], device_group.organization.pk
)

with self.subTest('Test PATCH'):
response = self.client.patch(
Expand All @@ -617,9 +619,9 @@ def test_devicegroup_detail_api(self):
content_type='application/json',
)
self.assertEqual(response.status_code, 200)
devicegroup.refresh_from_db()
device_group.refresh_from_db()
self.assertDictEqual(
devicegroup.meta_data, self._get_devicegroup_data['meta_data']
device_group.meta_data, self._get_devicegroup_data['meta_data']
)

with self.subTest('Test DELETE'):
Expand Down
22 changes: 11 additions & 11 deletions openwisp_controller/config/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openwisp_utils.tests import AssertNumQueriesSubTestMixin, catch_signal

from .. import settings as app_settings
from ..signals import device_name_changed, devicegroup_changed, management_ip_changed
from ..signals import device_group_changed, device_name_changed, management_ip_changed
from ..validators import device_name_validator, mac_address_validator
from .utils import CreateConfigTemplateMixin, CreateDeviceGroupMixin

Expand Down Expand Up @@ -352,38 +352,38 @@ def test_device_name_changed_not_emitted_on_creation(self):
self._create_device(organization=self._get_org())
handler.assert_not_called()

def test_devicegroup_changed_emitted(self):
def test_device_group_changed_emitted(self):
org = self._get_org()
device = self._create_device(name='test', organization=org)
devicegroup = self._create_devicegroup()
device_group = self._create_device_group()

with catch_signal(devicegroup_changed) as handler:
device.group = devicegroup
with catch_signal(device_group_changed) as handler:
device.group = device_group
device.save()
handler.assert_called_once_with(
signal=devicegroup_changed,
signal=device_group_changed,
sender=Device,
instance=device,
old_group_id=None,
group_id=devicegroup.id,
group_id=device_group.id,
)

def test_devicegroup_changed_not_emitted_on_creation(self):
with catch_signal(devicegroup_changed) as handler:
def test_device_group_changed_not_emitted_on_creation(self):
with catch_signal(device_group_changed) as handler:
self._create_device(organization=self._get_org())
handler.assert_not_called()

def test_device_field_changed_checks(self):
self._create_device()
devicegroup = self._create_devicegroup()
device_group = self._create_device_group()
with self.subTest('Deferred fields remained deferred'):
device = Device.objects.only('id', 'created').first()
device._check_changed_fields()

with self.subTest('Deferred fields becomes non-deferred'):
device.name = 'new-name'
device.management_ip = '10.0.0.1'
device.group_id = devicegroup.id
device.group_id = device_group.id
# Another query is generated due to "config,set_status_modified"
# on name change
with self.assertNumQueries(2):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@


class TestDeviceGroup(TestOrganizationMixin, CreateDeviceGroupMixin, TestCase):
def test_devicegroup(self):
self._create_devicegroup(meta_data={'captive_portal_url': 'https//example.com'})
def test_device_group(self):
self._create_device_group(
meta_data={'captive_portal_url': 'https//example.com'}
)
self.assertEqual(DeviceGroup.objects.count(), 1)

def test_devicegroup_schema_validation(self):
devicegroup_schema = {
def test_device_group_schema_validation(self):
device_group_schema = {
'required': ['captive_portal_url'],
'properties': {
'captive_portal_url': {
Expand All @@ -29,11 +31,11 @@ def test_devicegroup_schema_validation(self):
'additionalProperties': True,
}

with patch.object(app_settings, 'DEVICEGROUP_SCHEMA', devicegroup_schema):
with patch.object(app_settings, 'DEVICE_GROUP_SCHEMA', device_group_schema):
with self.subTest('Test for failing validation'):
self.assertRaises(ValidationError, self._create_devicegroup)
self.assertRaises(ValidationError, self._create_device_group)

with self.subTest('Test for passing validation'):
self._create_devicegroup(
self._create_device_group(
meta_data={'captive_portal_url': 'https://example.com'}
)
10 changes: 5 additions & 5 deletions openwisp_controller/config/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _create_config(self, **kwargs):


class CreateDeviceGroupMixin:
def _create_devicegroup(self, **kwargs):
def _create_device_group(self, **kwargs):
options = {
'name': 'Routers',
'description': 'Group for all routers',
Expand All @@ -158,10 +158,10 @@ def _create_devicegroup(self, **kwargs):
options.update(kwargs)
if 'organization' not in options:
options['organization'] = self._get_org()
devicegroup = DeviceGroup(**options)
devicegroup.full_clean()
devicegroup.save()
return devicegroup
device_group = DeviceGroup(**options)
device_group.full_clean()
device_group.save()
return device_group


class SeleniumTestCase(StaticLiveServerTestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/openwisp2/sample_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from openwisp_controller.config.base.config import AbstractConfig
from openwisp_controller.config.base.device import AbstractDevice
from openwisp_controller.config.base.devicegroup import AbstractDeviceGroup
from openwisp_controller.config.base.device_group import AbstractDeviceGroup
from openwisp_controller.config.base.multitenancy import (
AbstractOrganizationConfigSettings,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/openwisp2/sample_config/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TestController as BaseTestController,
)
from openwisp_controller.config.tests.test_device import TestDevice as BaseTestDevice
from openwisp_controller.config.tests.test_devicegroup import (
from openwisp_controller.config.tests.test_device_group import (
TestDeviceGroup as BaseTestDeviceGroup,
)
from openwisp_controller.config.tests.test_notifications import (
Expand Down

0 comments on commit 702be03

Please sign in to comment.