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] Update TestMultitenantAdminMixin to use default operator group #106

Closed
nemesifier opened this issue Apr 17, 2020 · 8 comments · Fixed by #310
Closed

[tests] Update TestMultitenantAdminMixin to use default operator group #106

nemesifier opened this issue Apr 17, 2020 · 8 comments · Fixed by #310
Labels
Hacktoberfest Easy issues for attracting Hacktoberfest participants.

Comments

@nemesifier
Copy link
Member

nemesifier commented Apr 17, 2020

In this test utility code (which is reused across openwisp modules):

operator_permission_filters = []
def get_operator_permissions(self):
filters = Q()
for filter in self.operator_permission_filters:
filters = filters | Q(**filter)
return Permission.objects.filter(filters)
def _create_operator(self, organizations=[]):
operator = user_model.objects.create_user(username='operator',
password='tester',
email='operator@test.com',
is_staff=True)
operator.user_permissions.add(*self.get_operator_permissions())
for organization in organizations:
OrganizationUser.objects.create(user=operator, organization=organization)
return operator

The test expects the permission of the operator to be defined as a class attribute.

This is obsolete, because in more recent versions of OpenWISP we added two default auth.Group instances: operator and administrator.

  • update the test method to assign those groups
  • remove operator_permission_filters = []
  • remove get_operator_permissions

Open a pull request in each openwisp module to remove the operator_permission_filters and ensuring the new code works: https://github.com/search?q=org%3Aopenwisp+operator_permission_filters&type=Code

@nemesifier nemesifier added the GCI label Apr 17, 2020
@atb00ker atb00ker removed the GCI label Sep 23, 2020
@atb00ker atb00ker added the Hacktoberfest Easy issues for attracting Hacktoberfest participants. label Sep 23, 2020
@niteshsinha17
Copy link
Member

I am working on this Issue 😊

@niteshsinha17
Copy link
Member

I think I need some more time to work on this Issue. If someone wants to work on it can go ahead.

@lehone-hp
Copy link
Contributor

I will be working on this.

@lehone-hp
Copy link
Contributor

@nemesisdesign after removing get_operator_permissions and assigning the Administrator and Operator permissions, several tests keep failing with the output below.
Screenshot from 2021-01-12 10-43-29

Please how do I proceed from here?

@niteshsinha17
Copy link
Member

@lehone-hp This is happening because Operation does not have permission to access those pages that's why it is giving error Couldn't retrieve content. We may need to add permissions to the operator for it. Am I right @nemesisdesign ?

@niteshsinha17
Copy link
Member

If you will remove these lines then it will not show any error.

# ensure elements in visible list are visible to operator
for el in visible:
with self.subTest(el):
self.assertContains(
response, _f(el, select_widget), msg_prefix='[operator contains]'
)
# ensure elements in hidden list are not visible to operator
for el in hidden:
with self.subTest(el):
self.assertNotContains(
response,
_f(el, select_widget),
msg_prefix='[operator not-contains]',
)

But I don't think it's a solution. nemesisdesign can give a better solution for it.

pandafy pushed a commit that referenced this issue Jan 12, 2021
@nemesifier
Copy link
Member Author

@lehone-hp This is happening because Operation does not have permission to access those pages that's why it is giving error Couldn't retrieve content. We may need to add permissions to the operator for it. Am I right @nemesisdesign ?

I think this is correct.

@lehone-hp
Copy link
Contributor

Okay, I will assign the appropriate permissions and then open a PR

lehone-hp added a commit to lehone-hp/openwisp-users that referenced this issue Jan 13, 2021
…openwisp#106

- Update the _create_operator test method to assign default user groups
- Removed operator_permission_filters = []
- Remove get_operator_permissions

Fixes openwisp#106
lehone-hp added a commit to lehone-hp/openwisp-users that referenced this issue Jan 13, 2021
…openwisp#106

- Update the _create_operator test method to assign default user groups
- Removed operator_permission_filters = []
- Remove get_operator_permissions

Fixes openwisp#106
codesankalp pushed a commit to lehone-hp/openwisp-users that referenced this issue Mar 1, 2022
…openwisp#106

- Update the _create_operator test method to assign default user groups
- Removed operator_permission_filters = []
- Remove get_operator_permissions

Fixes openwisp#106
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 2, 2022
codesankalp added a commit to openwisp/openwisp-radius that referenced this issue Mar 2, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 7, 2022
codesankalp added a commit to openwisp/openwisp-radius that referenced this issue Mar 7, 2022
codesankalp added a commit to openwisp/openwisp-network-topology that referenced this issue Mar 7, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 7, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 7, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 8, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 8, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Mar 8, 2022
nemesifier pushed a commit to openwisp/openwisp-radius that referenced this issue Mar 8, 2022
nemesifier pushed a commit to openwisp/openwisp-controller that referenced this issue Mar 8, 2022
nemesifier pushed a commit to openwisp/openwisp-controller that referenced this issue Mar 8, 2022
codesankalp added a commit to openwisp/openwisp-controller that referenced this issue Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment