async def test_empty_commits(loop): data = data_with_commits.copy() del data['commits'] smtp = FakeSMTP(hostname='localhost', port=1025, loop=loop) client = aiohttp.ClientSession(loop=loop) request = make_request('POST', '/', data=data, loop=loop) event = mailer.PushEvent(client, smtp, request) with pytest.raises(mailer.ResponseExit) as exc: await event.process() assert str(exc.value) == 'There is no commit to be processed.'
async def test_invalid_branch_name(loop): data = data_with_commits.copy() data['ref'] = 'refs/heads/invalid' smtp = FakeSMTP(hostname='localhost', port=1025, loop=loop) client = aiohttp.ClientSession(loop=loop) request = make_request('POST', '/', data=data, loop=loop) event = mailer.PushEvent(client, smtp, request) with pytest.raises(mailer.ResponseExit) as exc: await event.process() assert str(exc.value) == 'Invalid branch name.'
async def test_wrong_content_type(loop): smtp = FakeSMTP(hostname='localhost', port=1025, loop=loop) client = aiohttp.ClientSession(loop=loop) request = make_request( 'POST', '/', headers={'content-type': 'application/octet-stream'}) event = mailer.PushEvent(client, smtp, request) with pytest.raises(mailer.ResponseExit) as exc: await event.process() assert str( exc.value ) == 'can only accept application/json, not application/octet-stream'
async def test_github_as_committer(loop): data = data_with_commits.copy() data['commits'][0]['committer'] = { 'name': 'GitHub', 'email': '*****@*****.**', 'username': '******', } smtp = FakeSMTP(hostname='localhost', port=1025, loop=loop) client = aiohttp.ClientSession(loop=loop) request = make_request('POST', '/', data=data, loop=loop) event = mailer.PushEvent(client, smtp, request) resp = await event.process() assert resp == 'Ok' assert len(smtp.sent_mails) == 1 mail = smtp.sent_mails[0] assert mail['From'] == 'cbiggles <*****@*****.**>'
async def test_send_email(loop): smtp = FakeSMTP(hostname='localhost', port=1025, loop=loop) client = aiohttp.ClientSession(loop=loop) request = make_request('POST', '/', data=data_with_commits, loop=loop) event = mailer.PushEvent(client, smtp, request) resp = await event.process() assert resp == 'Ok' assert len(smtp.sent_mails) == 1 mail = smtp.sent_mails[0] assert mail['From'] == 'Berker Peksag <*****@*****.**>' assert mail['To'] == '*****@*****.**' assert mail['Subject'] == 'Update .gitignore' assert '(cherry picked from commit 9d9ed0e5cceef45fd63dc1f7b3fe6e695da16e83)' not in mail[ 'Subject'] body = mail.get_body().as_string() # TODO: We probably need a FakeDiff object to avoid making HTTP requests. assert diff in body