contrib_bots: Restructure bots to follow a consistent structure.
Now all the bots that are stored in contrib_bots are in the same file/directory format. The format is specified here #3427. Add tests.py file for encrypt_bot as well. Fixes #3427.
| 
		 Before Width: | Height: | Size: 287 KiB After Width: | Height: | Size: 287 KiB  | 
| 
		 Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 180 KiB  | 
| 
		 Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB  | 
| 
		 Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB  | 
							
								
								
									
										33
									
								
								contrib_bots/bots/encrypt_bot/tests.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
import encrypt_bot
 | 
			
		||||
 | 
			
		||||
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_bot.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()
 | 
			
		||||