Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (53 sloc) 2.788 kb
c7e8c93 @alexjg Basic merchant functionality implemented
alexjg authored
1 # coding: utf-8
2
3 import unittest
4
5
6 from gocardless import utils
7
8
9 class PercentEncodeTestCase(unittest.TestCase):
10
11 def test_works_with_empty_strings(self):
12 self.assertEqual(utils.percent_encode(u""), u"")
13
14 def test_doesnt_encode_lowercase_alpha_characters(self):
15 self.assertEqual(utils.percent_encode(u"abcxyz"), u"abcxyz")
16
17 def test_doesnt_encode_uppercase_alpha_characters(self):
18 self.assertEqual(utils.percent_encode(u"ABCXYZ"), u"ABCXYZ")
19
20 def test_doesnt_encode_digits(self):
21 self.assertEqual(utils.percent_encode(u"1234567890"), u"1234567890")
22
23 def test_doesnt_encode_unreserved_non_alphanum_chars(self):
24 self.assertEqual(utils.percent_encode(u"-._~"), u"-._~")
25
26 def test_encodes_non_ascii_alpha_characters(self):
27 self.assertEqual(utils.percent_encode(u"å"), u"%C3%A5")
28
29 def test_encodes_reserved_ascii_characters(self):
30 self.assertEqual(utils.percent_encode(u" !\"#$%&'()"),
31 u"%20%21%22%23%24%25%26%27%28%29")
32 self.assertEqual(utils.percent_encode(u"*+,/{|}:;"),
33 u"%2A%2B%2C%2F%7B%7C%7D%3A%3B")
34 self.assertEqual(utils.percent_encode(u"<=>?@[\\]^`"),
35 u"%3C%3D%3E%3F%40%5B%5C%5D%5E%60")
36
37 def test_encodes_other_non_ascii_characters(self):
38 self.assertEqual(utils.percent_encode(u"支払い"),
39 u"%E6%94%AF%E6%89%95%E3%81%84")
40
41
42 class SignatureTestCase(unittest.TestCase):
43 def setUp(self):
44 self.secret = '5PUZmVMmukNwiHc7V/TJvFHRQZWZumIpCnfZKrVYGpuAdkCcEfv3LIDSrsJ+xOVH'
45 self.api_key = ''
46 self.client_id = '4jqkF9tirkr3zfWCgEKxLDy3UmF1sWpHPVm8X69yiB7Lqb63usVOPzrm0jEepc5R'
47
48 def test_hmac(self):
49 # make sure our signature function
50 # works correctly
51 sig = utils.generate_signature({"foo": "bar", "example": [1, "a"]},self.secret)
52 self.assertEqual(sig, '5a9447aef2ebd0e12d80d80c836858c6f9c13219f615ef5d135da408bcad453d')
848d2b4 @alexjg Added webhook validation
alexjg authored
53
54 def test_validate_signature(self):
55 params = {"key1":"val1", "key2":"val2"}
56 sig = utils.generate_signature(params, self.secret)
57 params["signature"] = sig
58 self.assertTrue(utils.signature_valid(params, self.secret))
59 params["signature"] = "123482494523435"
60 self.assertFalse(utils.signature_valid(params, self.secret))
c7e8c93 @alexjg Basic merchant functionality implemented
alexjg authored
61
62
63 class CamelizeTestCase(unittest.TestCase):
64 def test_camelize_multi_word(self):
65 teststr = "camelize_this_please"
66 expected = "CamelizeThisPlease"
67 self.assertEqual(expected, utils.camelize(teststr))
68
69
70 class SingularizeTestCase(unittest.TestCase):
71 def test_singularize(self):
72 to_singularize = "PreAuthorisations"
73 expected = "PreAuthorisation"
74 self.assertEqual(expected, utils.singularize(to_singularize))
75
76
Something went wrong with that request. Please try again.