Exemplo n.º 1
0
    def start_server(self, instance):
        try:
            self.server = Server(int(self.port.text), self.output_log,
                                 socket.gethostbyname(socket.gethostname()))
            #self.server = Server(int(self.port.text), self.output_log, '192.168.1.32')
        except ValueError:
            self.output_log.add_text('invalid character')
            return
        self.thread = threading.Thread(target=self.server.run)
        self.thread.daemon = True
        self.thread.start()
        self.output_log.add_text("Server started")
        close_server_button = Button(text='Close Server',
                                     size_hint=(0.3, 0.1),
                                     pos_hint={
                                         'top': 0.2,
                                         'right': 0.4
                                     },
                                     color=(0, 0, 1, 5))
        close_server_button.bind(on_press=self.close_server)
        self.output_log.parent.add_widget(close_server_button)

        self.popup.dismiss()
Exemplo n.º 2
0
 def setUp(self):
     self.t = Server()
     self.t.start()
Exemplo n.º 3
0
class SendEmailGithubTests(unittest.TestCase):

    def setUp(self):
        self.t = Server()
        self.t.start()

    def test_ignore_get(self):
        rv = requests.get('http://*****:*****@patch("smtplib.SMTP")
    def test_w3c_tr_published(self, mock_smtp):
        data = io.open("tests/trpublished-notif.json").read()
        rv = requests.post('http://*****:*****@localhost": "tests/trpublished-notif.msg"}
        instance = mock_smtp.return_value
        self.assert_operation_results(rv, instance, refs)



    def do_gh_operation(self, operation, jsonf, refs, mock_smtp):
        data = io.open(jsonf).read()
        rv = requests.post('http://*****:*****@localhost")
            self.assertIn(args[1][0], refs)
            msg = io.open(refs[args[1][0]]).read()

            self.maxDiff = None
            import email
            sent_email = email.message_from_string(args[2])
            sent_headers = args[2].split("\n\n")[0]
            sent_body = sent_email.get_payload(decode=True)
            ref_headers = msg.split("\n\n")[0]
            ref_body = "\n".join(msg.split("\n\n")[1:])
            self.assertMultiLineEqual(sent_headers, ref_headers)
            self.assertMultiLineEqual(sent_body, ref_body)

    @patch("smtplib.SMTP")
    def test_repo_created_notif(self, mock_smtp):
        self.do_gh_operation("repository", "tests/repo-created.json", {"dom@localhost": "tests/repo-created.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_repo_deleted_notif(self, mock_smtp):
        self.do_gh_operation("repository", "tests/repo-deleted.json", {"dom@localhost": "tests/repo-deleted.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_push_notif(self, mock_smtp):
        self.do_gh_operation("push", "tests/push-notif.json", {"dom@localhost": "tests/push-notif.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_issue_notif(self, mock_smtp):
        self.do_gh_operation("issues", "tests/issue-notif.json", {"dom@localhost": "tests/issue-notif.msg", "log@localhost": "tests/issue-notif-log.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_issue_comment_notif(self, mock_smtp):
        self.do_gh_operation("issue_comment", "tests/issue-comment-notif.json", {"dom@localhost": "tests/issue-comment-notif.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_pull_request_comment_notif(self, mock_smtp):
        self.do_gh_operation("issue_comment", "tests/pull_request-comment-notif.json", {"dom@localhost": "tests/pull_request-comment-notif.msg"}, mock_smtp)


    @patch("smtplib.SMTP")
    def test_pull_notif(self, mock_smtp):
        self.do_gh_operation("pull_request", "tests/pull-notif.json", {"dom@localhost": "tests/pull-notif.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_pull_closed_notif(self, mock_smtp):
        self.do_gh_operation("pull_request", "tests/pull-merged.json", {"dom@localhost": "tests/pull-merged.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_pull_labeled_notif(self, mock_smtp):
        self.do_gh_operation("pull_request", "tests/pull-labeled.json", {"dom@localhost": "tests/pull-labeled.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_unavailable_template(self, mock_smtp):
        data = io.open("tests/push-notif.json").read()
        rv = requests.post('http://localhost:8000/', headers={'X-GitHub-Event': "foobar"}, data=data)
        instance = mock_smtp.return_value
        self.assertEqual(rv.status_code, 500)
        self.assertEqual(instance.sendmail.call_count, 0)

    def tearDown(self):
        self.t.terminate()
Exemplo n.º 4
0
 def setUp(self):
     self.t = Server()
     self.t.start()
Exemplo n.º 5
0
class SendEmailGithubTests(unittest.TestCase):
    def setUp(self):
        self.t = Server()
        self.t.start()

    def test_ignore_get(self):
        rv = requests.get("http://*****:*****@localhost")
            self.assertIn(args[1][0], refs)
            msg = io.open(refs[args[1][0]]).read()

            self.maxDiff = None
            import email

            sent_email = email.message_from_string(args[2])
            sent_headers = args[2].split("\n\n")[0]
            sent_body = sent_email.get_payload(decode=True)
            ref_headers = msg.split("\n\n")[0]
            ref_body = "\n".join(msg.split("\n\n")[1:])
            self.assertMultiLineEqual(sent_headers, ref_headers)
            self.assertMultiLineEqual(sent_body, ref_body)

    @patch("smtplib.SMTP")
    def test_push_notif(self, mock_smtp):
        self.do_operation("push", "tests/push-notif.json", {"dom@localhost": "tests/push-notif.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_issue_notif(self, mock_smtp):
        self.do_operation(
            "issues",
            "tests/issue-notif.json",
            {"dom@localhost": "tests/issue-notif.msg", "log@localhost": "tests/issue-notif-log.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP")
    def test_issue_comment_notif(self, mock_smtp):
        self.do_operation(
            "issue_comment",
            "tests/issue-comment-notif.json",
            {"dom@localhost": "tests/issue-comment-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP")
    def test_pull_request_comment_notif(self, mock_smtp):
        self.do_operation(
            "issue_comment",
            "tests/pull_request-comment-notif.json",
            {"dom@localhost": "tests/pull_request-comment-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP")
    def test_pull_notif(self, mock_smtp):
        self.do_operation("pull_request", "tests/pull-notif.json", {"dom@localhost": "tests/pull-notif.msg"}, mock_smtp)

    @patch("smtplib.SMTP")
    def test_pull_labeled_notif(self, mock_smtp):
        self.do_operation(
            "pull_request", "tests/pull-labeled.json", {"dom@localhost": "tests/pull-labeled.msg"}, mock_smtp
        )

    @patch("smtplib.SMTP")
    def test_unavailable_template(self, mock_smtp):
        data = io.open("tests/push-notif.json").read()
        rv = requests.post("http://localhost:8000/", headers={"X-GitHub-Event": "foobar"}, data=data)
        instance = mock_smtp.return_value
        import sys

        self.assertEqual(rv.status_code, 500)
        self.assertEqual(instance.sendmail.call_count, 0)

    def tearDown(self):
        self.t.terminate()
Exemplo n.º 6
0
class ServerSetupContent(RelativeLayout):
    def __init__(self, popup, output_log):
        super(ServerSetupContent, self).__init__()
        self.server = None
        self.output_log = output_log

        self.port = TextInput(multiline=False,
                              size_hint=(0.4, 0.2),
                              pos_hint={
                                  'center_x': 0.75,
                                  'center_y': 0.75
                              },
                              font_size=42)
        self.port.bind(on_text_validate=self.start_server)
        self.add_widget(self.port)

        self.port_label = Label(text='Enter port to run on:',
                                font_name='Arial',
                                pos_hint={
                                    'center_x': 0.28,
                                    'center_y': 0.75
                                },
                                font_size=36)
        self.add_widget(self.port_label)

        self.start_button = Button(text='Start',
                                   size_hint=(0.7, 0.2),
                                   pos_hint={
                                       'center_x': 0.5,
                                       'center_y': 0.35
                                   })
        self.start_button.bind(on_press=self.start_server)
        self.add_widget(self.start_button)

        # Button to close popup
        self.popup = popup
        self.close = Button(text="Close",
                            size_hint=(0.7, 0.2),
                            pos_hint={
                                'center_x': 0.5,
                                'y': 0.025
                            })
        self.close.bind(on_press=self.popup.dismiss)
        self.add_widget(self.close)

    def start_server(self, instance):
        try:
            self.server = Server(int(self.port.text), self.output_log,
                                 socket.gethostbyname(socket.gethostname()))
            #self.server = Server(int(self.port.text), self.output_log, '192.168.1.32')
        except ValueError:
            self.output_log.add_text('invalid character')
            return
        self.thread = threading.Thread(target=self.server.run)
        self.thread.daemon = True
        self.thread.start()
        self.output_log.add_text("Server started")
        close_server_button = Button(text='Close Server',
                                     size_hint=(0.3, 0.1),
                                     pos_hint={
                                         'top': 0.2,
                                         'right': 0.4
                                     },
                                     color=(0, 0, 1, 5))
        close_server_button.bind(on_press=self.close_server)
        self.output_log.parent.add_widget(close_server_button)

        self.popup.dismiss()

    def close_server(self, instance):
        instance.parent.remove_widget(instance)
        self.server.close_server()
        self.server = None
Exemplo n.º 7
0
class SendEmailGithubTests(unittest.TestCase):
    def setUp(self):
        self.t = Server()
        self.t.start()

    @staticmethod
    def read_file(filename):
        with io.open(filename) as filehandle:
            contents = filehandle.read()
        return contents

    def test_ignore_get(self):
        rv = requests.get("http://*****:*****@patch("smtplib.SMTP", autospec=True)
    def test_w3c_tr_published(self, mock_smtp):
        data = self.read_file("tests/trpublished-notif.json")
        rv = requests.post(
            "http://*****:*****@localhost": "tests/trpublished-notif.msg"}
        self.assert_operation_results(
            rv, mock_smtp.return_value.__enter__.return_value.sendmail, refs)

    def do_gh_operation(self, operation, jsonf, refs, mock_smtp):
        with io.open(jsonf) as filehandle:
            data = filehandle.read()
        rv = requests.post("http://*****:*****@localhost")
            self.assertIn(args[1][0], refs)
            msg = self.read_file(refs[args[1][0]])
            self.maxDiff = None
            import email

            sent_email = email.message_from_string(args[2],
                                                   policy=email.policy.default)
            sent_headers = args[2].split("\n\n")[0]
            sent_body = sent_email.get_content()
            ref_headers = msg.split("\n\n")[0]
            ref_body = "\n".join(msg.split("\n\n")[1:])
            self.assertMultiLineEqual(sent_headers, ref_headers)
            self.assertMultiLineEqual(sent_body, ref_body)

    @patch("smtplib.SMTP", autospec=True)
    def test_repo_created_notif(self, mock_smtp):
        self.do_gh_operation(
            "repository",
            "tests/repo-created.json",
            {"dom@localhost": "tests/repo-created.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_repo_transferred_notif(self, mock_smtp):
        self.do_gh_operation(
            "repository",
            "tests/repo-transferred.json",
            {"dom@localhost": "tests/repo-transferred.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_repo_deleted_notif(self, mock_smtp):
        self.do_gh_operation(
            "repository",
            "tests/repo-deleted.json",
            {"dom@localhost": "tests/repo-deleted.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_push_notif(self, mock_smtp):
        self.do_gh_operation(
            "push",
            "tests/push-notif.json",
            {"dom@localhost": "tests/push-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_issue_notif(self, mock_smtp):
        self.do_gh_operation(
            "issues",
            "tests/issue-notif.json",
            {
                "dom@localhost": "tests/issue-notif.msg",
                "log@localhost": "tests/issue-notif-log.msg",
            },
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_issue_comment_notif(self, mock_smtp):
        self.do_gh_operation(
            "issue_comment",
            "tests/issue-comment-notif.json",
            {"dom@localhost": "tests/issue-comment-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_pull_request_comment_notif(self, mock_smtp):
        self.do_gh_operation(
            "issue_comment",
            "tests/pull_request-comment-notif.json",
            {"dom@localhost": "tests/pull_request-comment-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_pull_notif(self, mock_smtp):
        self.do_gh_operation(
            "pull_request",
            "tests/pull-notif.json",
            {"dom@localhost": "tests/pull-notif.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_pull_closed_notif(self, mock_smtp):
        self.do_gh_operation(
            "pull_request",
            "tests/pull-merged.json",
            {"dom@localhost": "tests/pull-merged.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_pull_labeled_notif(self, mock_smtp):
        self.do_gh_operation(
            "pull_request",
            "tests/pull-labeled.json",
            {"dom@localhost": "tests/pull-labeled.msg"},
            mock_smtp,
        )

    @patch("smtplib.SMTP", autospec=True)
    def test_unavailable_template(self, mock_smtp):
        data = self.read_file("tests/push-notif.json")
        rv = requests.post("http://localhost:8000/",
                           headers={"X-GitHub-Event": "foobar"},
                           data=data)
        instance = mock_smtp.return_value
        self.assertEqual(rv.status_code, 500)
        self.assertEqual(instance.call_count, 0)

    def tearDown(self):
        self.t.terminate()