def test_private_bundle_mbox_token_auth(self): self.client.logout() # create tokens for both users for user in [self.user, self.other_user]: view_utils.regenerate_token(user) def _get_auth_string(user): return 'Token {}'.format(str(user.profile.token)) # Check we can view as owner auth_string = _get_auth_string(self.user) response = self.client.get(self.url, HTTP_AUTHORIZATION=auth_string) self.assertEqual(response.status_code, 200) self.assertContains(response, self.patches[0].name) # Check we can't view as another user auth_string = _get_auth_string(self.other_user) response = self.client.get(self.url, HTTP_AUTHORIZATION=auth_string) self.assertEqual(response.status_code, 404)
def generate_token(request): utils.regenerate_token(request.user) return HttpResponseRedirect(reverse('user-profile'))