|
2 | 2 | import unittest
|
3 | 3 |
|
4 | 4 | from nose.tools import assert_equal, assert_true
|
5 |
| -from six import b |
| 5 | +from six import b, u |
6 | 6 |
|
7 | 7 | from twilio.util import RequestValidator
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class ValidationTest(unittest.TestCase):
|
11 | 11 |
|
12 |
| - def test_validation(self): |
| 12 | + def setUp(self): |
13 | 13 | token = "1c892n40nd03kdnc0112slzkl3091j20"
|
14 |
| - validator = RequestValidator(token) |
| 14 | + self.validator = RequestValidator(token) |
15 | 15 |
|
16 |
| - uri = "http://www.postbin.org/1ed898x" |
17 |
| - params = { |
| 16 | + self.uri = "http://www.postbin.org/1ed898x" |
| 17 | + self.params = { |
18 | 18 | "AccountSid": "AC9a9f9392lad99kla0sklakjs90j092j3",
|
19 | 19 | "ApiVersion": "2010-04-01",
|
20 | 20 | "CallSid": "CAd800bb12c0426a7ea4230e492fef2a4f",
|
@@ -43,7 +43,20 @@ def test_validation(self):
|
43 | 43 | "ToZip": "94612",
|
44 | 44 | }
|
45 | 45 |
|
| 46 | + def test_compute_signature_bytecode(self): |
46 | 47 | expected = b("fF+xx6dTinOaCdZ0aIeNkHr/ZAA=")
|
| 48 | + signature = self.validator.compute_signature(self.uri, |
| 49 | + self.params, |
| 50 | + utf=False) |
| 51 | + assert_equal(signature, expected) |
| 52 | + |
| 53 | + def test_compute_signature_unicode(self): |
| 54 | + expected = u("fF+xx6dTinOaCdZ0aIeNkHr/ZAA=") |
| 55 | + signature = self.validator.compute_signature(self.uri, |
| 56 | + self.params, |
| 57 | + utf=True) |
| 58 | + assert_equal(signature, expected) |
47 | 59 |
|
48 |
| - assert_equal(validator.compute_signature(uri, params), expected) |
49 |
| - assert_true(validator.validate(uri, params, expected)) |
| 60 | + def test_validation(self): |
| 61 | + expected = "fF+xx6dTinOaCdZ0aIeNkHr/ZAA=" |
| 62 | + assert_true(self.validator.validate(self.uri, self.params, expected)) |
0 commit comments