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 setup(self): self.sut = Author() self.sut.name = "Bob Dole" self.sut.email = "*****@*****.**"
class TestAuthorClass: def setup(self): self.sut = Author() self.sut.name = "Bob Dole" self.sut.email = "*****@*****.**" def test_name_and_email_in_constructor_works_and_eq_works(self): self.sut2 = Author("Bob Dole", "*****@*****.**") eq_(self.sut, self.sut2) def test_add_commit(self): self.sut.add_commit() eq_(1, self.sut.commits) self.sut.add_commit() eq_(2, self.sut.commits) def test_add_commit_with_ticket(self): self.sut.add_commit_with_ticket() eq_(1, self.sut.commits_with_tickets) self.sut.add_commit_with_ticket() eq_(2, self.sut.commits_with_tickets) def test_add_commit_formatted_correctly(self): self.sut.add_commit_formatted_correctly() eq_(1, self.sut.commits_formatted_correctly) self.sut.add_commit_formatted_correctly() eq_(2, self.sut.commits_formatted_correctly) def test_str_works_correctly(self): expected = "\n".join([ "### Bob Dole <*****@*****.**>", "#### Commits", " - total: 0", " - with ticket number: 0", " - formatted correctly: 0", "" ]) eq_(expected, str(self.sut))