def test_run_command(self, mock_open): slaps = ['slap {nick} once', 'slap {nick} twice'] with StringIO() as stringio: stringio.write(slaps[0] + '\n') stringio.write(slaps[1]) stringio.seek(0) mock_open.return_value = stringio mtype, resp = slap.run_command(None, 'foo') self.assertEqual(mtype, 'groupchat') self.assertIn(resp, ['/me ' + s.format(nick='foo') for s in slaps]) # args = /path/to/slaps.txt args, kwargs = mock_open.call_args self.assertIn('slaps.txt', args[0])
def test_run_command_without_nick(self, mock_open): mtype, resp = slap.run_command(None) self.assertEqual(mtype, 'groupchat') self.assertEqual(resp, 'You have to provide a nick name')