def __to_commit(self, commit_str):
     commit_list = commit_str.split(SEP, 6)
     commit = Commit()
     commit.cid = commit_list[0]
     commit.name = commit_list[1]
     commit.email = commit_list[2]
     commit.date = commit_list[3]
     commit.subject = commit_list[4]
     commit.body = commit_list[5]
     commit.props = self.props
     return commit
    def setup(self, mock_props):
        mock_props.ticket_pattern = 'TIK-1111'
        mock_props.ticket_url = 'http://tikurl/'
        mock_props.repo_web_url = 'http://repourl/'

        self.sut = Commit()
        self.sut.cid = 'abcdef1234567890'
        self.sut.name = 'Bob Dole'
        self.sut.email = '*****@*****.**'
        self.sut.date = '01/02/03'
        self.sut.subject = 'TIK-1111 - The commit subject'
        self.sut.body = 'This is the body\nthis is more of the body\nand more'
        self.sut.props = mock_props
Пример #3
0
def parse_request(payload):
    """Parses POST requst from Github and
    returns list of Commit objects.
    """
    payload = json.loads(payload, encoding='utf-8')
    commits = []
    for commitInfo in payload['commits']:
        author = Author(name=str(commitInfo['author']['name']),
                        email=str(commitInfo['author']['email']))
        commit = Commit(commitId=str(commitInfo['id']),
                        author=author,
                        message=str(commitInfo['message']),
                        date=str(commitInfo['timestamp']),
                        url=str(commitInfo['url']))
        commits.append(commit)
    return commits
    def test_eq_works_as_expected(self):
        sut1 = self.sut
        sut2 = Commit()
        sut2.cid = sut1.cid

        eq_(sut1, sut2)
class TestCommitClass:

    @mock.patch('lib.properties.Properties')
    def setup(self, mock_props):
        mock_props.ticket_pattern = 'TIK-1111'
        mock_props.ticket_url = 'http://tikurl/'
        mock_props.repo_web_url = 'http://repourl/'

        self.sut = Commit()
        self.sut.cid = 'abcdef1234567890'
        self.sut.name = 'Bob Dole'
        self.sut.email = '*****@*****.**'
        self.sut.date = '01/02/03'
        self.sut.subject = 'TIK-1111 - The commit subject'
        self.sut.body = 'This is the body\nthis is more of the body\nand more'
        self.sut.props = mock_props

    def test_to_str_formats_output_as_expected(self):
        expected = "\n".join([
            "### [TIK-1111](http://tikurl/TIK-1111) - The commit subject",
            "",
            " - __commit:__ [abcdef1234567890](http://repourl/commit/abcdef1234567890)",
            " - __author:__ Bob Dole <*****@*****.**>",
            " - __date:__ 01/02/03",
            "",
            "> This is the body",
            "> this is more of the body",
            "> and more",
            ""
        ])

        eq_(expected, str(self.sut))

    def test_is_formatted_correctly_returns_true(self):
        ok_(self.sut.is_formatted_correctly())

    def test_is_formatted_correctly_returns_false(self):
        self.sut.subject = "This subject is way too damn long! It just keeps going!"
        ok_(not self.sut.is_formatted_correctly())

        self.sut.subject = "This is a shorter subject"
        self.sut.body = ""
        ok_(not self.sut.is_formatted_correctly())

    def test_has_ticket_reference_returns_as_expected(self):
        ok_(self.sut.has_ticket_reference())

        self.sut.subject = "This is a subject"
        ok_(not self.sut.has_ticket_reference())

        self.sut.body = "This is a body with a ticket reference TIK-1111 in it"
        ok_(self.sut.has_ticket_reference)

    def test_get_ticket_number_returns_as_expected(self):
        eq_("TIK-1111", self.sut.get_ticket_number())

        self.sut.subject = "This is a subject"
        assert_is_none(self.sut.get_ticket_number())

        self.sut.body = "This is a body with a ticket reference TIK-1111 in it"
        eq_("TIK-1111", self.sut.get_ticket_number())

    def test_eq_works_as_expected(self):
        sut1 = self.sut
        sut2 = Commit()
        sut2.cid = sut1.cid

        eq_(sut1, sut2)

    def test_hash_works_as_expected(self):
        eq_(hash("abcdef1234567890"), hash(self.sut))
 def to_commit(self, email, subj, body):
     ct = Commit()
     ct.email = email
     ct.subject = subj
     ct.body = body
     return ct