Skip to content

Commit

Permalink
[tests] Removed operator_permission_filters from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp committed Mar 8, 2022
1 parent da7eb4b commit 435353f
Show file tree
Hide file tree
Showing 9 changed files with 1,224 additions and 43 deletions.
11 changes: 5 additions & 6 deletions openwisp_controller/config/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class TestAdmin(
object_model = Device
object_location_model = DeviceLocation
maxDiff = None
operator_permission_filters = [
{'codename__endswith': 'config'},
{'codename__endswith': 'device'},
{'codename__endswith': 'template'},
{'codename__endswith': 'vpn'},
]
_device_params = {
'name': 'test-device',
'hardware_id': '1234',
Expand Down Expand Up @@ -197,6 +191,7 @@ def _create_multitenancy_test_env(self, vpn=False):
org2 = self._create_org(name='test2org')
inactive = self._create_org(name='inactive-org', is_active=False)
operator = self._create_operator(organizations=[org1, inactive])
administrator = self._create_administrator(organizations=[org1, inactive])
t1 = self._create_template(name='template1org', organization=org1)
t2 = self._create_template(name='template2org', organization=org2)
t3 = self._create_template(name='t3-inactive', organization=inactive)
Expand Down Expand Up @@ -229,6 +224,7 @@ def _create_multitenancy_test_env(self, vpn=False):
org2=org2,
inactive=inactive,
operator=operator,
administrator=administrator,
)
if vpn:
v1 = self._create_vpn(name='vpn1org', organization=org1)
Expand Down Expand Up @@ -316,6 +312,7 @@ def test_vpn_organization_fk_queryset(self):
visible=[data['org1'].name],
hidden=[data['org2'].name, data['inactive']],
select_widget=True,
administrator=True,
)

def test_vpn_ca_fk_queryset(self):
Expand All @@ -325,6 +322,7 @@ def test_vpn_ca_fk_queryset(self):
visible=[data['vpn1'].ca.name, data['vpn_shared'].ca.name],
hidden=[data['vpn2'].ca.name, data['vpn_inactive'].ca.name],
select_widget=True,
administrator=True,
)

def test_vpn_cert_fk_queryset(self):
Expand All @@ -334,6 +332,7 @@ def test_vpn_cert_fk_queryset(self):
visible=[data['vpn1'].cert.name, data['vpn_shared'].cert.name],
hidden=[data['vpn2'].cert.name, data['vpn_inactive'].cert.name],
select_widget=True,
administrator=True,
)

def test_changelist_recover_deleted_button(self):
Expand Down
4 changes: 2 additions & 2 deletions openwisp_controller/config/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def test_vpn_create_api(self):
def test_vpn_create_with_shared_objects(self):
org1 = self._get_org()
shared_ca = self._create_ca(name='shared_ca', organization=None)
test_user = self._create_operator(organizations=[org1])
test_user = self._create_administrator(organizations=[org1])
self.client.force_login(test_user)
data = self._get_vpn_data.copy()
data['organization'] = org1.pk
Expand All @@ -472,7 +472,7 @@ def test_vpn_list_for_shared_objects(self):
ca = self._create_ca(name='shared_ca', organization=None)
self._create_cert(ca=ca, name='shared_cert', organization=None)
org1 = self._get_org()
test_user = self._create_operator(organizations=[org1])
test_user = self._create_administrator(organizations=[org1])
self.client.force_login(test_user)
path = reverse('config_api:vpn_list')
r = self.client.get(path, {'format': 'api'})
Expand Down
13 changes: 5 additions & 8 deletions openwisp_controller/connection/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
class TestConnectionAdmin(TestAdminMixin, CreateConnectionsMixin, TestCase):
config_app_label = 'config'
app_label = 'connection'
operator_permission_filters = [
{'codename__endswith': 'config'},
{'codename__endswith': 'device'},
{'codename__endswith': 'template'},
{'codename__endswith': 'connection'},
{'codename__endswith': 'credentials'},
{'codename__endswith': 'device_connection'},
]
_device_params = TestConfigAdmin._device_params.copy()

def _get_device_params(self, org):
Expand All @@ -44,6 +36,7 @@ def _create_multitenancy_test_env(self):
org2 = self._create_org(name='test2org')
inactive = self._create_org(name='inactive-org', is_active=False)
operator = self._create_operator(organizations=[org1, inactive])
administrator = self._create_administrator(organizations=[org1, inactive])
cred1 = self._create_credentials(organization=org1, name='test1cred')
cred2 = self._create_credentials(organization=org2, name='test2cred')
cred3 = self._create_credentials(organization=inactive, name='test3cred')
Expand All @@ -61,6 +54,7 @@ def _create_multitenancy_test_env(self):
org2=org2,
inactive=inactive,
operator=operator,
administrator=administrator,
)
return data

Expand All @@ -70,6 +64,7 @@ def test_credentials_queryset(self):
url=reverse(f'admin:{self.app_label}_credentials_changelist'),
visible=[data['cred1'].name, data['org1'].name],
hidden=[data['cred2'].name, data['org2'].name, data['cred3_inactive'].name],
administrator=True,
)

def test_credentials_organization_fk_queryset(self):
Expand All @@ -79,6 +74,7 @@ def test_credentials_organization_fk_queryset(self):
visible=[data['org1'].name],
hidden=[data['org2'].name, data['inactive']],
select_widget=True,
administrator=True,
)

def test_connection_queryset(self):
Expand All @@ -91,6 +87,7 @@ def test_connection_queryset(self):
data['org2'].name,
data['dc3_inactive'].credentials.name,
],
administrator=True,
)

def test_connection_credentials_fk_queryset(self):
Expand Down
10 changes: 0 additions & 10 deletions openwisp_controller/geo/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ class TestAdmin(TestAdminMixin, TestGeoMixin, BaseTestAdmin, TestCase):
object_location_model = DeviceLocation
user_model = get_user_model()

operator_permission_filters = [
{'codename__endswith': 'config'},
{'codename__endswith': 'device'},
{'codename__endswith': 'template'},
{'codename__endswith': 'vpn'},
{'codename__endswith': 'location'},
{'codename__endswith': 'floorplan'},
{'codename__endswith': 'devicelocation'},
]

def setUp(self):
"""override TestAdminMixin.setUp"""
pass
Expand Down
10 changes: 5 additions & 5 deletions openwisp_controller/pki/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
class TestAdmin(TestPkiMixin, TestAdminMixin, TestOrganizationMixin, TestCase):
app_label = 'pki'

operator_permission_filters = [
{'codename__endswith': 'ca'},
{'codename__endswith': 'cert'},
]

def _create_multitenancy_test_env(self, cert=False):
org1 = self._create_org(name='test1org')
org2 = self._create_org(name='test2org')
inactive = self._create_org(name='inactive-org', is_active=False)
operator = self._create_operator(organizations=[org1, inactive])
administrator = self._create_administrator(organizations=[org1, inactive])
ca1 = self._create_ca(name='ca1', organization=org1)
ca2 = self._create_ca(name='ca2', organization=org2)
ca_shared = self._create_ca(name='ca-shared', organization=None)
Expand All @@ -37,6 +33,7 @@ def _create_multitenancy_test_env(self, cert=False):
org2=org2,
inactive=inactive,
operator=operator,
administrator=administrator,
)
if cert:
cert1 = self._create_cert(name='cert1', ca=ca1, organization=org1)
Expand Down Expand Up @@ -77,6 +74,7 @@ def test_ca_organization_fk_queryset(self):
visible=[data['org1'].name],
hidden=[data['org2'].name, data['inactive']],
select_widget=True,
administrator=True,
)

def test_cert_queryset(self):
Expand All @@ -99,6 +97,7 @@ def test_cert_organization_fk_queryset(self):
visible=[data['org1'].name],
hidden=[data['org2'].name, data['inactive']],
select_widget=True,
administrator=True,
)

def test_cert_ca_fk_queryset(self):
Expand All @@ -108,6 +107,7 @@ def test_cert_ca_fk_queryset(self):
visible=[data['ca1'].name, data['ca_shared'].name],
hidden=[data['ca2'].name, data['ca_inactive'].name],
select_widget=True,
administrator=True,
)

def test_cert_changeform_200(self):
Expand Down
Loading

0 comments on commit 435353f

Please sign in to comment.