def test_encoded_id_with_specified_chaff_values(self): encoded_id = int_str(chaffify(self.user.id, 12345)) self.assertEqual( dechaffify(str_int(encoded_id), 12345), self.user.id ) # with non-matching chaff with self.assertRaises(ValueError): dechaffify(str_int(encoded_id), 1234)
def test_encoded_id_with_specified_keyspaces(self): encoded_id = int_str(chaffify(self.user.id), 'abcdefghisjkl') self.assertEqual( dechaffify(str_int(encoded_id, 'abcdefghisjkl')), self.user.id ) # with non-matching keyspaces with self.assertRaises(ValueError): dechaffify(str_int(encoded_id, 'abcdefghisjk'))
def user_disclaimer(request, encoded_user_id): user_id = dechaffify(str_int(encoded_user_id)) disclaimer = OnlineDisclaimer.objects.get(user__id=user_id) ctx = {'disclaimer': disclaimer, 'encoded_user_id': encoded_user_id} return TemplateResponse( request, "studioadmin/user_disclaimer.html", ctx )
def get_object(self): encoded_user_id = self.kwargs.get('encoded_user_id') user_id = dechaffify(str_int(encoded_user_id)) return get_object_or_404(OnlineDisclaimer, user__id=user_id)
def dispatch(self, *args, **kwargs): encoded_user_id = self.kwargs.get('encoded_user_id') user_id = dechaffify(str_int(encoded_user_id)) self.user = User.objects.get(id=user_id) return super(DisclaimerDeleteView, self).dispatch(*args, **kwargs)
def test_encoded_id_with_defaults(self): encoded_id = int_str(chaffify(self.user.id)) self.assertEqual(dechaffify(str_int(encoded_id)), self.user.id)