Skip to content

Commit

Permalink
Merge pull request #4 from roverdotcom/master
Browse files Browse the repository at this point in the history
Fixed handling of unicode params
  • Loading branch information
vrok committed Dec 23, 2014
2 parents 266b452 + 0ed28a8 commit 5ab4fe9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion panda/__init__.py
Expand Up @@ -86,7 +86,7 @@ def generate_signature(verb, request_uri, host, secret_key, params={}):


def urlescape(s):
s = unicode(s)
s = unicode(s).encode('utf-8')
return urllib.quote(s).replace("%7E", "~").replace(' ', '%20').replace('/', '%2F')


Expand Down
22 changes: 21 additions & 1 deletion panda/test.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import unittest, re
from nose.tools import *
import panda


class PropertiesTest(unittest.TestCase):
def setUp(self):
self.i = _panda_instance()
Expand Down Expand Up @@ -32,7 +34,8 @@ def test_api_url(self):
def test_https_api_url(self):
self.i.api_port = 443
eq_(self.i.api_url(), 'https://api.pandastream.com:443/v2')



class SignatureTest(unittest.TestCase):
def setUp(self):
self.i = panda.Panda(access_key='my_access_key', secret_key='my_secret_key', api_host='myapihost', api_port=85, cloud_id='my_cloud_id')
Expand Down Expand Up @@ -98,9 +101,26 @@ def test_signed_params_with_difficult_characters(self):
}
eq_(result, expectation)

def test_signed_params_with_unicode_characters(self):
result = self.i.signed_params(
'POST',
'/videos/upload.json',
{'file_name': u'original♥.mp4'},
'2014-12-22T17:54:11+00:00')
expectation = {
'access_key': "my_access_key",
'timestamp': "2014-12-22T17:54:11+00:00",
'cloud_id': 'my_cloud_id',
'signature': 'NBK3+4HtaolBLi0I1Ai9MEXQvCG+T96E7PEIKf4CMwM=',
'file_name': u'original♥.mp4'
}
eq_(result, expectation)


class TimestampTest(unittest.TestCase):
def test_timestamp_includes_timezone(self):
ok_(re.search(':\d\d(\.\d+)?(\+|-)\d\d:\d\d$', panda.generate_timestamp()))


def _panda_instance():
return panda.Panda(cloud_id='my-cloud-id', access_key='my-access-key', secret_key='my-secret-key')
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name='panda',
version='0.1.5',
version='0.1.6-dev',
description='A Python implementation of the Panda REST interface',
author='New Bamboo',
author_email='info@new-bamboo.co.uk',
Expand Down

0 comments on commit 5ab4fe9

Please sign in to comment.