def test_output(self): mock_stdout = MockPrint() out = output.Output(mock_stdout.do_print) out.print_function = mock_stdout.do_print out.echoed = "" out.echo("hello") out.echo("hi") self.assertEqual(out.echoed, mock_stdout.printed)
def test_persist(self, mock_github_constructor, mock_save): mock_github_constructor.return_value = self.__mock_github mock_stdout = MockPrint() cli = gcw.Cli(("--persist", "lastrepocommits", "mySubscription1", "since", "2015", "10", "11", "20", "08", "00"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() mock_save.assert_called_once_with()
def test_credentials(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github mock_stdout = MockPrint() cli = gcw.Cli(("--credentials", "myUsername1:myPassword", "watchlist", "myUsername2"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() mock_github_constructor.assert_called_once_with( "myUsername1", "myPassword")
def test_repo_doesnt_exist(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github self.__mock_github.get_repo = mock.Mock( side_effect=github.GithubException(404, "data")) mock_stdout = MockPrint() cli = gcw.Cli(("lastrepocommits", "mySubscription1", "since", "2015", "10", "11", "20", "08", "00"), mail.MailSender(), output.Output(mock_stdout.do_print)) with self.assertRaises(github.GithubException): cli.run()
def test_user_doesnt_exist(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github self.__mock_github.get_user.side_effect = github.GithubException( 404, "data") mock_stdout = MockPrint() cli = gcw.Cli(("--credentials", "myUsername1:myPassword", "watchlist", "myUsername2"), mail.MailSender(), output.Output(mock_stdout.do_print)) with self.assertRaises(github.GithubException): cli.run()
def test_watchlist(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github mock_stdout = MockPrint() cli = gcw.Cli(("watchlist", "myUsername"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() expected = "watchlist myUsername\n" \ + "\033[31mmySubscription1\033[0m\n" \ + "\033[31mmySubscription2\033[0m\n" \ + "\033[31mmySubscription3\033[0m\n" actual = mock_stdout.printed self.assertEqual(actual, expected)
def test_no_email_sent(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github self.__mock_github_user.get_subscriptions.return_value = () mock_stdout = MockPrint() cli = gcw.Cli(("--no-color", "--mailto", "*****@*****.**", "watchlist", "myUsername"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() expected = "watchlist myUsername\n" \ + "No e-mail sent.\n" actual = mock_stdout.printed self.assertEqual(actual, expected)
def test_lastrepocommits(self, mock_github_constructor): mock_github_constructor.return_value = self.__mock_github mock_stdout = MockPrint() cli = gcw.Cli(("--no-color", "lastrepocommits", "mySubscription1", "since", "2015", "10", "11", "20", "08", "00"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() expected = "lastrepocommits mySubscription1 since 2015-10-11 20:08:00\n" \ + "Last commit pushed on 2015-10-11 20:22:24\n" \ + "Committed on myDate - myCommitter - myMessage\n" actual = mock_stdout.printed self.assertEqual(actual, expected)
def __init__(self): self._output = output.Output(MockPrint().do_print) self._memory = lambda: None # ~ object with no properties (yet) self._memory.timestamps = { "my_command my_argument1": { "YYYY": 2015, "MM": 10, "DD": 11, "hh": 20, "mm": 22, "ss": 24 } } self.last_result = None
def test_mailto(self, mock_github_constructor, mock_send_email): mock_github_constructor.return_value = self.__mock_github mock_stdout = MockPrint() cli = gcw.Cli(("--no-color", "--mailto", "*****@*****.**", "watchlist", "myUsername"), mail.MailSender(), output.Output(mock_stdout.do_print)) cli.run() mock_send_email.assert_called_once_with( "watchlist.", """\ watchlist myUsername mySubscription1 mySubscription2 mySubscription3 Sent from %s. """ % (os.uname()[1]))
def test_help(self): mock_stdout = MockPrint() cli = gcw.Cli(("--help", ), mail.MailSender(), output.Output(mock_stdout.do_print)) with self.assertRaises(SystemExit): cli.run()