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 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]))
Пример #9
0
    def test_send_email(self, mock_smtp_constructor):
        mock_smtp = mock.Mock()
        mock_smtp_constructor.return_value = mock_smtp

        subject = "subject"
        content = "content"
        dest = set(("*****@*****.**", "*****@*****.**"))

        mail_sender = mail.MailSender()
        mail_sender.dest = dest
        mail_sender.send_email(subject, content)

        mock_smtp_constructor.assert_called_once_with("localhost")

        expected_email = MIMEText(content, "plain", "utf-8")
        expected_email["Subject"] = "[gicowa] %s" % (subject)
        expected_email["From"] = "*****@*****.**"
        expected_email["To"] = ", ".join(dest)
        mock_smtp.sendmail.assert_called_once_with("*****@*****.**", dest,
                                                   expected_email.as_string())
 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()