def test_url_representation_decode(self): """Test the url_representation_decode functionality""" result, verification_hash = utils.url_representation_decode( OPEN_DATA_ENCODED) self.assertDictEqual(result, OPEN_DATA) self.assertEqual(verification_hash, OPEN_DATA_HASH)
def test_roundtrip(self): """Test that an identical dictionary can be encoded and decoded""" test_dict = { 'special_char': '%##!@#9813&&&&', 'email': '*****@*****.**' } code, verification_hash = utils.url_representation_encode(test_dict) # Decode the data, verify we can reverse the process decoded_data, decoded_hash = utils.url_representation_decode(code) self.assertEqual(decoded_hash, verification_hash) self.assertDictEqual(decoded_data, test_dict)
def get(self, request, *args, **kwargs): """Handler for all GET requests""" result, verification_hash = url_representation_decode( self.kwargs['encoded_data']) # Bail if our hash of the data doesn't match the hash in the name if verification_hash != self.kwargs['request_hash']: raise Http404 # Require an email (e), unique key (k) and timestamp (t) in the url necessary_keys = ['e', 'k', 't'] if not all([key in result for key in necessary_keys]): raise Http404 create_open(result, request.META) return HttpResponse(BASE64_TRANS_GIF.decode('base64'), content_type='image/gif')
def get(self, request, *args, **kwargs): """Handler for all GET requests""" result, verification_hash = url_representation_decode( self.kwargs['encoded_data']) # Bail if our hash of the data doesn't match the hash in the name if verification_hash != self.kwargs['request_hash']: raise Http404 # Require an email (e), unique key (k) and timestamp (t) in the url necessary_keys = ['e', 'k', 't'] if not all([key in result for key in necessary_keys]): raise Http404 create_open(result, request.META) return HttpResponse( BASE64_TRANS_GIF.decode('base64'), content_type='image/gif' )