def test_shared_event_detail(self): """ Make Other User the owner of the source host and then: 1. Make sure that User hasn't access to the event 2. Share source host with User and check if he has access to the event. """ other_user = User.objects.create_user('other', '*****@*****.**', 'otherpassword') other_user.save() self.source_host.user = other_user self.source_host.save() url = '/event/%i/' % self.event.pk response = self.client.get(url) self.assertEqual(response.status_code, 404) grant_access(self.source_host, self.user) url = '/event/%i/' % self.event.pk response = self.client.get(url) self.assertEqual(response.status_code, 200) self.source_host.user = self.user self.source_host.save()
def share(request, object_type, object_id): model = Network if object_type == 'network' else Host obj, edit = get_object_or_forbidden(model, object_id, request.user) user_id = request.POST.get('share') if user_id: user = User.objects.get(pk=user_id) grant_access(obj, user) return share_list(request, object_type, object_id)
def test_user_network_share(self): grant_access(self.net, self.other_user) access = user_has_access(self.net, self.other_user) self.assertEqual(access, True) access = user_can_edit(self.net, self.other_user) self.assertEqual(access, True) revoke_edit(self.net, self.other_user) access = user_can_edit(self.net, self.other_user) self.assertEqual(access, False) revoke_access(self.net, self.other_user) access = user_has_access(self.net, self.other_user) self.assertEqual(access, False)