def test_success_sends_message_to_room(self, hipchatMock):
        notifier = HipchatNotifier("token", 123)

        notifier.announce_pipeline_success(Mock(name="pipeline"), [MockCommit("commit")])

        self.assert_one_message_posted(hipchatCallsTo(hipchatMock),
                                       Matches(lambda m: m["parameters"]["room_id"] == 123))
    def test_from_name_must_be_less_than_15_characters(self, hipchatMock):
        notifier = HipchatNotifier("token", 123)

        notifier.announce_pipeline_success(Mock(), [])
        notifier.announce_step_failure(Mock(), [])

        calls = hipchatCallsTo(hipchatMock)
        self.assertLess(len(calls[0][1]["parameters"]["from"]), 15)
        self.assertLess(len(calls[1][1]["parameters"]["from"]), 15)
    def test_success_sends_message_describing_passed_commits(self, hipchatMock):
        notifier = HipchatNotifier("token", 123)

        notifier.announce_pipeline_success(Mock(name="pipeline"),
                                           [MockCommit("commit1"), MockCommit("commit2")])

        isExpectedMessage = lambda m: ("failed" not in m and
                                       "commit1" in m and
                                       "commit2" in m)
        self.assert_one_message_posted(hipchatCallsTo(hipchatMock),
                                    Matches(lambda m: isExpectedMessage(m["parameters"]["message"])))