Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Oct 12, 2013
1 parent c16af8f commit d054566
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions test_weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from flask import Flask
from flask_weixin import Weixin
from nose.tools import raises


class Base(object):
Expand Down Expand Up @@ -36,6 +37,18 @@ def setup_weixin(self):
)


class TestNoToken(Base):
def create_app(self):
app = Flask(__name__)
app.debug = True
app.secret_key = 'secret'
return app

@raises(RuntimeError)
def test_validate(self):
self.client.get(signature_url)


class TestSimpleWeixin(Base):
def test_invalid_get(self):
rv = self.client.get('/')
Expand Down Expand Up @@ -199,10 +212,10 @@ def print_all(**kwargs):
username, sender=sender, content='text reply'
)

self.weixin.register('*', print_all)
self.weixin.register('help', 'help me')
weixin.register('*', print_all)
weixin.register('help', 'help me')

@self.weixin.register('show')
@weixin.register('show')
def print_show(*args, **kwargs):
username = kwargs.get('sender')
sender = kwargs.get('receiver')
Expand All @@ -229,3 +242,15 @@ def test_show(self):
text = self.__doc__ % 'show'
rv = self.client.post('/', data=text)
assert b'show reply' in rv.data

@raises(RuntimeError)
def test_no_sender(self):
@self.weixin.register('send')
def print_send(*args, **kwargs):
username = kwargs.get('sender')
return self.weixin.reply(
username, sender=None, content='send reply'
)

text = self.__doc__ % 'send'
self.client.post('/', data=text)

0 comments on commit d054566

Please sign in to comment.