Issues (41)

tests/test_create_reply.py (2 issues)

1
# -*- coding: utf-8 -*-
2
from __future__ import absolute_import, unicode_literals
3
import unittest
4
import six
5
6
7
from wechatpy.replies import TextReply, create_reply
8
9
10
class CreateReplyTestCase(unittest.TestCase):
11
12
    def test_create_reply_with_text_not_render(self):
13
        text = 'test'
14
        reply = create_reply(text, render=False)
15
        self.assertEqual('text', reply.type)
16
        self.assertEqual(text, reply.content)
17
        reply.render()
18
19
    def test_create_reply_with_text_render(self):
20
        text = 'test'
21
        reply = create_reply(text, render=True)
22
        self.assertTrue(isinstance(reply, six.text_type))
23
24
    def test_create_reply_with_message(self):
25
        from wechatpy.messages import TextMessage
26
27
        msg = TextMessage({
28
            'FromUserName': 'user1',
29
            'ToUserName': 'user2',
30
        })
31
        reply = create_reply('test', msg, render=False)
32
33
        self.assertEqual('user1', reply.target)
34
        self.assertEqual('user2', reply.source)
35
        reply.render()
36
37
    def test_create_reply_with_reply(self):
38
        _reply = TextReply(content='test')
39
        reply = create_reply(_reply, render=False)
40
41
        self.assertEqual(_reply, reply)
42
        reply.render()
43
44 View Code Duplication
    def test_create_reply_with_articles(self):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
45
        articles = [
46
            {
47
                'title': 'test 1',
48
                'description': 'test 1',
49
                'image': 'http://www.qq.com/1.png',
50
                'url': 'http://www.qq.com/1'
51
            },
52
            {
53
                'title': 'test 2',
54
                'description': 'test 2',
55
                'image': 'http://www.qq.com/2.png',
56
                'url': 'http://www.qq.com/2'
57
            },
58
            {
59
                'title': 'test 3',
60
                'description': 'test 3',
61
                'image': 'http://www.qq.com/3.png',
62
                'url': 'http://www.qq.com/3'
63
            },
64
        ]
65
        reply = create_reply(articles, render=False)
66
        self.assertEqual('news', reply.type)
67
        reply.render()
68
69 View Code Duplication
    def test_create_reply_with_more_than_ten_articles(self):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
70
        articles = [
71
            {
72
                'title': 'test 1',
73
                'description': 'test 1',
74
                'image': 'http://www.qq.com/1.png',
75
                'url': 'http://www.qq.com/1'
76
            },
77
            {
78
                'title': 'test 2',
79
                'description': 'test 2',
80
                'image': 'http://www.qq.com/2.png',
81
                'url': 'http://www.qq.com/2'
82
            },
83
            {
84
                'title': 'test 3',
85
                'description': 'test 3',
86
                'image': 'http://www.qq.com/3.png',
87
                'url': 'http://www.qq.com/3'
88
            },
89
            {
90
                'title': 'test 4',
91
                'description': 'test 4',
92
                'image': 'http://www.qq.com/4.png',
93
                'url': 'http://www.qq.com/4'
94
            },
95
            {
96
                'title': 'test 5',
97
                'description': 'test 5',
98
                'image': 'http://www.qq.com/5.png',
99
                'url': 'http://www.qq.com/5'
100
            },
101
            {
102
                'title': 'test 6',
103
                'description': 'test 6',
104
                'image': 'http://www.qq.com/6.png',
105
                'url': 'http://www.qq.com/6'
106
            },
107
            {
108
                'title': 'test 7',
109
                'description': 'test 7',
110
                'image': 'http://www.qq.com/7.png',
111
                'url': 'http://www.qq.com/7'
112
            },
113
            {
114
                'title': 'test 8',
115
                'description': 'test 8',
116
                'image': 'http://www.qq.com/8.png',
117
                'url': 'http://www.qq.com/8'
118
            },
119
            {
120
                'title': 'test 9',
121
                'description': 'test 9',
122
                'image': 'http://www.qq.com/9.png',
123
                'url': 'http://www.qq.com/9'
124
            },
125
            {
126
                'title': 'test 10',
127
                'description': 'test 10',
128
                'image': 'http://www.qq.com/10.png',
129
                'url': 'http://www.qq.com/10'
130
            },
131
            {
132
                'title': 'test 11',
133
                'description': 'test 11',
134
                'image': 'http://www.qq.com/11.png',
135
                'url': 'http://www.qq.com/11'
136
            },
137
        ]
138
        self.assertRaises(AttributeError, create_reply, articles)
139
140
    def test_create_empty_reply(self):
141
        from wechatpy.replies import EmptyReply
142
143
        reply = create_reply('')
144
        self.assertTrue(isinstance(reply, EmptyReply))
145
146
        reply = create_reply(None)
147
        self.assertTrue(isinstance(reply, EmptyReply))
148
149
        reply = create_reply(False)
150
        self.assertTrue(isinstance(reply, EmptyReply))
151