WeChatPayTestCase.test_calculate_signature_hmac()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 1
dl 0
loc 11
rs 9.95
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
from __future__ import absolute_import, unicode_literals
3
import unittest
4
5
6
class WeChatPayTestCase(unittest.TestCase):
7
8
    def test_calculate_signature(self):
9
        from wechatpy.pay import calculate_signature
10
11
        api_key = '192006250b4c09247ec02edce69f6a2d'
12
        params = {
13
            'test1': 'test1',
14
            'test2': 'test2',
15
        }
16
        expected = '1E3A8D73B5A4AEE787C0F68B5DAB8520'
17
        sign = calculate_signature(params, api_key)
18
        self.assertEqual(expected, sign)
19
20
    def test_calculate_signature_hmac(self):
21
        from wechatpy.pay import calculate_signature_hmac
22
23
        api_key = '192006250b4c09247ec02edce69f6a2d'
24
        params = {
25
            'test1': 'test1',
26
            'test2': 'test2',
27
        }
28
        expected = 'EDAC6D70D2FDF5A2382F8204FC96A1918017E46ACC5297F565ED1A7610ACF659'
29
        sign = calculate_signature_hmac(params, api_key)
30
        self.assertEqual(expected, sign)
31
32
    def test_dict_to_xml(self):
33
        from wechatpy.pay import dict_to_xml
34
35
        params = {
36
            'test1': 'test1',
37
            'test2': 'test2',
38
        }
39
        sign = '1E3A8D73B5A4AEE787C0F68B5DAB8520'
40
        expected = (
41
            '<xml>\n<test1><![CDATA[test1]]></test1>\n'
42
            '<test2><![CDATA[test2]]></test2>\n'
43
            '<sign><![CDATA[1E3A8D73B5A4AEE787C0F68B5DAB8520]]></sign>\n</xml>'
44
        )
45
        xml = dict_to_xml(params, sign)
46
        self.assertEqual(expected, xml)
47