示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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')
示例#6
0
    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'
        )