<s> from __future__ import absolute_import , unicode_literals <EOL> import time <EOL> import unittest <EOL> from wechatpy . replies import TextReply <EOL> class ReplyTestCase ( unittest . TestCase ) : <EOL> def test_reply_init_ok ( self ) : <EOL> reply = TextReply ( source = '<STR_LIT>' , target = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . source ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . target ) <EOL> self . assertTrue ( isinstance ( reply . time , int ) ) <EOL> def test_reply_render ( self ) : <EOL> timestamp = int ( time . time ( ) ) <EOL> reply = TextReply ( <EOL> source = '<STR_LIT>' , <EOL> target = '<STR_LIT>' , <EOL> time = timestamp , <EOL> content = '<STR_LIT:test>' <EOL> ) <EOL> r = reply . render ( ) <EOL> self . assertTrue ( r . startswith ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( r . endswith ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( '<STR_LIT>' in r ) <EOL> self . assertTrue ( '<STR_LIT>' in r ) <EOL> self . assertTrue ( '<STR_LIT>' in r ) <EOL> self . assertTrue ( '<STR_LIT>' in r ) <EOL> create_time = '<STR_LIT>' . format ( time = timestamp ) <EOL> self . assertTrue ( create_time in r ) <EOL> def test_image_reply_properties ( self ) : <EOL> from wechatpy . replies import ImageReply <EOL> reply = ImageReply ( image = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . image ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> reply . media_id = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , reply . image ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> def test_voice_reply_properties ( self ) : <EOL> from wechatpy . replies import VoiceReply <EOL> reply = VoiceReply ( voice = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . voice ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> reply . media_id = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , reply . voice ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> def test_video_reply_properties ( self ) : <EOL> from wechatpy . replies import VideoReply <EOL> reply = VideoReply ( ) <EOL> reply . media_id = '<STR_LIT>' <EOL> reply . title = '<STR_LIT:test>' <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . title ) <EOL> reply = VideoReply ( <EOL> media_id = '<STR_LIT>' , <EOL> title = '<STR_LIT:test>' <EOL> ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . media_id ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . title ) <EOL> def test_music_reply_properties ( self ) : <EOL> from wechatpy . replies import MusicReply <EOL> reply = MusicReply ( ) <EOL> reply . thumb_media_id = '<STR_LIT>' <EOL> reply . title = '<STR_LIT:test>' <EOL> reply . description = '<STR_LIT:test>' <EOL> reply . music_url = '<STR_LIT>' <EOL> reply . hq_music_url = None <EOL> self . assertEqual ( '<STR_LIT>' , reply . thumb_media_id ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . title ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . description ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . music_url ) <EOL> self . assertTrue ( reply . hq_music_url is None ) <EOL> reply = MusicReply ( <EOL> thumb_media_id = '<STR_LIT>' , <EOL> title = '<STR_LIT:test>' , <EOL> description = '<STR_LIT:test>' , <EOL> music_url = '<STR_LIT>' , <EOL> hq_music_url = None <EOL> ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . thumb_media_id ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . title ) <EOL> self . assertEqual ( '<STR_LIT:test>' , reply . description ) <EOL> self . assertEqual ( '<STR_LIT>' , reply . music_url ) <EOL> self . assertTrue ( reply . hq_music_url is None ) <EOL> def test_multi_article_reply ( self ) : <EOL> from wechatpy . replies import ArticlesReply <EOL> article = { '<STR_LIT:title>' : '<STR_LIT:test>' , '<STR_LIT:url>' : '<STR_LIT>' } <EOL> r1 = ArticlesReply ( ) <EOL> r1 . add_article ( article ) <EOL> r2 = ArticlesReply ( ) <EOL> self . assertTrue ( r1 . render ( ) != r2 . render ( ) ) </s>
