Skip to content

Commit

Permalink
Merge pull request #10 from shashwat1002/implement_multitenancy_admin
Browse files Browse the repository at this point in the history
[admin] implement multitenant admin
  • Loading branch information
nemesifier committed Nov 25, 2018
2 parents d6c3283 + 9c9a44d commit b411073
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
5 changes: 3 additions & 2 deletions openwisp_ipam/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from django.contrib import admin
from openwisp_utils.admin import MultitenantAdminMixin

from django_ipam.base.admin import AbstractIpAddressAdmin, AbstractSubnetAdmin

from .models import IpAddress, Subnet


@admin.register(IpAddress)
class IPAddressAdmin(AbstractIpAddressAdmin):
class IPAddressAdmin(MultitenantAdminMixin, AbstractIpAddressAdmin):
pass


@admin.register(Subnet)
class BaseSubnet(AbstractSubnetAdmin):
class BaseSubnet(MultitenantAdminMixin, AbstractSubnetAdmin):
app_name = 'openwisp_ipam'
53 changes: 53 additions & 0 deletions openwisp_ipam/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.forms import ModelForm
from django.test import TestCase
from django.urls import reverse
from openwisp_utils.tests.utils import TestMultitenantAdminMixin

from django_ipam.tests.base.test_admin import BaseTestAdmin
from django_ipam.tests.base.test_api import BaseTestApi
Expand Down Expand Up @@ -169,3 +170,55 @@ def test_create_user(self):
}
)
self.assertIsNotNone(self.user_model.objects.get(username="test1212"))


class TestMultitenantAdmin(TestMultitenantAdminMixin, CreateModelsMixin, TestCase):
ipaddress_model = swapper.load_model('openwisp_ipam', 'IPAddress')
subnet_model = swapper.load_model('openwisp_ipam', 'Subnet')

def _create_multitenancy_test_env(self):
org1 = self._create_org(name="test1organization")
org2 = self._create_org(name="test2organization")
subnet1 = self._create_subnet(
subnet='172.16.0.1/16',
organization=org1
)
subnet2 = self._create_subnet(
subnet='192.168.0.1/16',
organization=org2
)
ipadd1 = self._create_ipaddress(
ip_address='172.16.0.1',
organization=org1,
subnet=subnet1

)
ipadd2 = self._create_ipaddress(
ip_address='192.168.0.1',
organization=org2,
subnet=subnet2
)
operator = self._create_operator(organizations=[org1])
data = dict(
org1=org1, org2=org2,
subnet1=subnet1, subnet2=subnet2,
ipadd1=ipadd1, ipadd2=ipadd2,
operator=operator
)
return data

def test_multitenancy_ip_queryset(self):
data = self._create_multitenancy_test_env()
self._test_multitenant_admin(
url=reverse('admin:openwisp_ipam_ipaddress_changelist'),
visible=[data['ipadd1']],
hidden=[data['ipadd2']]
)

def test_multitenancy_subnet_queryset(self):
data = self._create_multitenancy_test_env()
self._test_multitenant_admin(
url=reverse('admin:openwisp_ipam_subnet_changelist'),
visible=[data['subnet1']],
hidden=[data['subnet2']]
)

0 comments on commit b411073

Please sign in to comment.