testsuite: Add tests for encrypt bot in contrib_bots.
Remove previous unittest file for encrypt bot. Add new test file which is in accordance with the test-suite famework developed for contrib_bots.
This commit is contained in:
parent
a52269cbe2
commit
b1573babcb
38
contrib_bots/bots/encrypt/test_encrypt.py
Normal file
38
contrib_bots/bots/encrypt/test_encrypt.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
our_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
# For dev setups, we can find the API in the repo itself.
|
||||||
|
if os.path.exists(os.path.join(our_dir, '..')):
|
||||||
|
sys.path.insert(0, '..')
|
||||||
|
from bots_test_lib import BotTestCase
|
||||||
|
|
||||||
|
class TestEncryptBot(BotTestCase):
|
||||||
|
bot_name = "encrypt"
|
||||||
|
|
||||||
|
def test_bot(self):
|
||||||
|
self.assert_bot_output(
|
||||||
|
{'content': "Please encrypt this", 'type': "private", 'sender_email': "foo@gmail.com"},
|
||||||
|
"Encrypted/Decrypted text: Cyrnfr rapelcg guvf"
|
||||||
|
)
|
||||||
|
self.assert_bot_output(
|
||||||
|
{'content': "Let\'s Do It", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
|
||||||
|
"Encrypted/Decrypted text: Yrg\'f Qb Vg"
|
||||||
|
)
|
||||||
|
self.assert_bot_output(
|
||||||
|
{'content': "", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
|
||||||
|
"Encrypted/Decrypted text: "
|
||||||
|
)
|
||||||
|
self.assert_bot_output(
|
||||||
|
{'content': "me&mom together..!!", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
|
||||||
|
"Encrypted/Decrypted text: zr&zbz gbtrgure..!!"
|
||||||
|
)
|
||||||
|
self.assert_bot_output(
|
||||||
|
{'content': "foo bar", 'type': "stream", 'display_recipient': "foo", 'subject': "foo"},
|
||||||
|
"Encrypted/Decrypted text: sbb one"
|
||||||
|
)
|
|
@ -1,33 +0,0 @@
|
||||||
from . import encrypt
|
|
||||||
|
|
||||||
def test():
|
|
||||||
for cmd, expected_response in sample_conversation():
|
|
||||||
message = {'content': cmd, 'subject': 'foo',
|
|
||||||
'display_recipient': 'bar'}
|
|
||||||
|
|
||||||
class ClientDummy(object):
|
|
||||||
def __init__(self):
|
|
||||||
self.output = ''
|
|
||||||
|
|
||||||
def send_message(self, params):
|
|
||||||
self.output = params['content']
|
|
||||||
handler = encrypt.EncryptHandler()
|
|
||||||
client_dummy = ClientDummy()
|
|
||||||
handler.handle_message(message, client_dummy, '')
|
|
||||||
if client_dummy.output != expected_response:
|
|
||||||
raise AssertionError('''
|
|
||||||
cmd: %s
|
|
||||||
expected: %s
|
|
||||||
but got : %s
|
|
||||||
''' % (cmd, expected_response, client_dummy.output))
|
|
||||||
|
|
||||||
def sample_conversation():
|
|
||||||
return [
|
|
||||||
('@encrypt Please encrypt this', 'Encrypted/Decrypted text: Cyrnfr rapelcg guvf'),
|
|
||||||
('@encrypt Let\'s Do It', 'Encrypted/Decrypted text: Yrg\'f Qb Vg'),
|
|
||||||
('@encrypt ', 'Encrypted/Decrypted text: '),
|
|
||||||
('@encrypt me&mom together..!!', 'Encrypted/Decrypted text: zr&zbz gbtrgure..!!'),
|
|
||||||
]
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test()
|
|
Loading…
Reference in a new issue