Skip to content

Commit

Permalink
Merge pull request #3081 from rodrigc/py3-fix3
Browse files Browse the repository at this point in the history
Py3 fix3
  • Loading branch information
tardyp committed Mar 27, 2017
2 parents 4dfe134 + e90587f commit 771cf06
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 38 deletions.
3 changes: 1 addition & 2 deletions master/buildbot/test/integration/test_trigger.py
Expand Up @@ -22,12 +22,11 @@

from buildbot.test.util.integration import RunMasterBase


# This integration test creates a master and worker environment,
# with two builders and a trigger step linking them

expectedOutputRegex = \
r"""\*\*\* BUILD 1 \*\*\* ==> finished \(success\)
r"""\*\*\* BUILD 1 \*\*\* ==> finished \(success\)
\*\*\* STEP shell \*\*\* ==> 'echo hello' \(success\)
log:stdio \({loglines}\)
\*\*\* STEP trigger \*\*\* ==> triggered trigsched \(success\)
Expand Down
1 change: 0 additions & 1 deletion master/buildbot/test/unit/test_reporters_mail.py
Expand Up @@ -19,7 +19,6 @@
import base64
import copy
import sys

from email import charset

from mock import Mock
Expand Down
78 changes: 73 additions & 5 deletions master/buildbot/test/unit/test_www_hooks_github.py
@@ -1,3 +1,4 @@
# coding: utf-8
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
Expand All @@ -16,13 +17,16 @@
from __future__ import absolute_import
from __future__ import print_function
from future.utils import PY3
from future.utils import string_types
from future.utils import text_type

import hmac
from calendar import timegm
from hashlib import sha1
from io import BytesIO
from io import StringIO

from twisted.internet import defer
from twisted.python.compat import NativeStringIO
from twisted.trial import unittest

from buildbot.test.fake.web import FakeRequest
Expand Down Expand Up @@ -131,6 +135,56 @@
}
"""

gitJsonPayloadTagUnicode = u"""
{
"before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
"repository": {
"url": "http://github.com/defunkt/github",
"html_url": "http://github.com/defunkt/github",
"name": "github",
"full_name": "defunkt/github",
"description": "You're lookin' at it.",
"watchers": 5,
"forks": 2,
"private": 1,
"owner": {
"email": "julian.rueth@fsfe.org",
"name": "Julian Rüth"
}
},
"commits": [
{
"id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
"distinct": true,
"url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
"author": {
"name": "Julian Rüth",
"email": "julian.rueth@fsfe.org",
"username": "saraedum"
},
"message": "okay i give in",
"timestamp": "2008-02-15T14:57:17-08:00",
"added": ["filepath.rb"]
},
{
"id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
"url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
"author": {
"name": "Julian Rüth",
"email": "julian.rueth@fsfe.org",
"username": "saraedum"
},
"message": "update pricing a tad",
"timestamp": "2008-02-15T14:36:34-08:00",
"modified": ["modfile"],
"removed": ["removedFile"]
}
],
"after": "de8251ff97ee194a289832576287d6f8ad74e3d0",
"ref": "refs/tags/v1.0.0"
}
"""

gitJsonPayloadNonBranch = """
{
"before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
Expand Down Expand Up @@ -332,14 +386,17 @@ def _prepare_request(event, payload, _secret=None, headers=None):

request = FakeRequest()

request.uri = "/change_hook/github"
request.method = "GET"
request.uri = b"/change_hook/github"
request.method = b"GET"
request.received_headers = {
_HEADER_EVENT: event
}

if isinstance(payload, str):
request.content = NativeStringIO(payload)
if isinstance(payload, string_types):
if isinstance(payload, text_type):
request.content = StringIO(payload)
elif isinstance(payload, bytes):
request.content = BytesIO(payload)
request.received_headers[_HEADER_CT] = _CT_JSON

if _secret is not None:
Expand Down Expand Up @@ -407,6 +464,17 @@ def test_git_with_push_tag(self):
"Fred Flinstone <fred@flinstone.org>")
self.assertEqual(change["branch"], "v1.0.0")

@defer.inlineCallbacks
def test_git_with_push_tag_unicode(self):
self.request = _prepare_request('push', gitJsonPayloadTagUnicode)
yield self.request.test_render(self.changeHook)

self.assertEqual(len(self.changeHook.master.addedChanges), 2)
change = self.changeHook.master.addedChanges[0]
self.assertEqual(change["author"],
u"Julian Rüth <julian.rueth@fsfe.org>")
self.assertEqual(change["branch"], "v1.0.0")

# Test 'base' hook with attributes. We should get a json string
# representing a Change object as a dictionary. All values show be set.
@defer.inlineCallbacks
Expand Down
32 changes: 16 additions & 16 deletions master/buildbot/test/unit/test_www_hooks_gitlab.py
Expand Up @@ -175,42 +175,42 @@ def check_changes_push_event(self, r, project='', codebase=None):
@defer.inlineCallbacks
def testGitWithChange(self):
self.request = FakeRequest(content=gitJsonPayload)
self.request.uri = "/change_hook/gitlab"
self.request.method = "POST"
self.request.uri = b"/change_hook/gitlab"
self.request.method = b"POST"
res = yield self.request.test_render(self.changeHook)
self.check_changes_push_event(res)

@defer.inlineCallbacks
def testGitWithChange_WithProjectToo(self):
self.request = FakeRequest(content=gitJsonPayload)
self.request.uri = "/change_hook/gitlab"
self.request.uri = b"/change_hook/gitlab"
self.request.args = {'project': ['MyProject']}
self.request.method = "POST"
self.request.method = b"POST"
res = yield self.request.test_render(self.changeHook)
self.check_changes_push_event(res, project="MyProject")

@defer.inlineCallbacks
def testGitWithChange_WithCodebaseToo(self):
self.request = FakeRequest(content=gitJsonPayload)
self.request.uri = "/change_hook/gitlab"
self.request.uri = b"/change_hook/gitlab"
self.request.args = {'codebase': ['MyCodebase']}
self.request.method = "POST"
self.request.method = b"POST"
res = yield self.request.test_render(self.changeHook)
self.check_changes_push_event(res, codebase="MyCodebase")

@defer.inlineCallbacks
def testGitWithChange_WithPushTag(self):
self.request = FakeRequest(content=gitJsonPayloadTag)
self.request.uri = "/change_hook/gitlab"
self.request.uri = b"/change_hook/gitlab"
self.request.args = {'codebase': ['MyCodebase']}
self.request.method = "POST"
self.request.method = b"POST"
res = yield self.request.test_render(self.changeHook)
self.check_changes_tag_event(res, codebase="MyCodebase")

def testGitWithNoJson(self):
self.request = FakeRequest()
self.request.uri = "/change_hook/gitlab"
self.request.method = "POST"
self.request.uri = b"/change_hook/gitlab"
self.request.method = b"POST"
d = self.request.test_render(self.changeHook)

def check_changes(r):
Expand All @@ -225,8 +225,8 @@ def check_changes(r):
def test_event_property(self):
self.request = FakeRequest(content=gitJsonPayload)
self.request.received_headers[_HEADER_EVENT] = "Push Hook"
self.request.uri = "/change_hook/gitlab"
self.request.method = "POST"
self.request.uri = b"/change_hook/gitlab"
self.request.method = b"POST"
yield self.request.test_render(self.changeHook)
self.assertEqual(len(self.changeHook.master.addedChanges), 2)
change = self.changeHook.master.addedChanges[0]
Expand All @@ -245,9 +245,9 @@ def setUp(self):
@defer.inlineCallbacks
def test_missing_secret(self):
self.request = FakeRequest(content=gitJsonPayloadTag)
self.request.uri = "/change_hook/gitlab"
self.request.uri = b"/change_hook/gitlab"
self.request.args = {'codebase': ['MyCodebase']}
self.request.method = "POST"
self.request.method = b"POST"
yield self.request.test_render(self.changeHook)
expected = b'Invalid secret'
self.assertEqual(self.request.written, expected)
Expand All @@ -257,7 +257,7 @@ def test_missing_secret(self):
def test_valid_secret(self):
self.request = FakeRequest(content=gitJsonPayload)
self.request.received_headers[_HEADER_GITLAB_TOKEN] = self._SECRET
self.request.uri = "/change_hook/gitlab"
self.request.method = "POST"
self.request.uri = b"/change_hook/gitlab"
self.request.method = b"POST"
yield self.request.test_render(self.changeHook)
self.assertEqual(len(self.changeHook.master.addedChanges), 2)
8 changes: 4 additions & 4 deletions master/buildbot/test/unit/test_www_hooks_gitorious.py
Expand Up @@ -76,8 +76,8 @@ def setUp(self):
def testGitWithChange(self):
changeDict = {"payload": [gitJsonPayload]}
self.request = FakeRequest(changeDict)
self.request.uri = "/change_hook/gitorious"
self.request.method = "POST"
self.request.uri = b"/change_hook/gitorious"
self.request.method = b"POST"
d = self.request.test_render(self.changeHook)

def check_changes(r):
Expand Down Expand Up @@ -107,8 +107,8 @@ def check_changes(r):

def testGitWithNoJson(self):
self.request = FakeRequest()
self.request.uri = "/change_hook/gitorious"
self.request.method = "GET"
self.request.uri = b"/change_hook/gitorious"
self.request.method = b"GET"
d = self.request.test_render(self.changeHook)

def check_changes(r):
Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/unit/test_www_hooks_poller.py
Expand Up @@ -39,8 +39,8 @@ def poll(self):
@defer.inlineCallbacks
def setUpRequest(self, args, options=True, activate=True):
self.request = FakeRequest(args=args)
self.request.uri = "/change_hook/poller"
self.request.method = "GET"
self.request.uri = b"/change_hook/poller"
self.request.method = b"GET"
www = self.request.site.master.www
self.master = master = self.request.site.master = fakemaster.make_master(
testcase=self, wantData=True)
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/www/hooks/github.py
Expand Up @@ -203,7 +203,7 @@ def _process_change(self, payload, user, repo, repo_url, project, event):
log.msg("New revision: {}".format(commit['id'][:8]))

change = {
'author': '{} <{}>'.format(commit['author']['name'],
'author': u'{} <{}>'.format(commit['author']['name'],
commit['author']['email']),
'files': files,
'comments': commit['message'],
Expand Down
20 changes: 13 additions & 7 deletions smokes/mydashboard.py
Expand Up @@ -5,7 +5,6 @@
import time

import requests

from flask import Flask
from flask import render_template

Expand All @@ -16,14 +15,17 @@

@mydashboardapp.route("/index.html")
def main():
# This code fetches build data from the data api, and give it to the template
# This code fetches build data from the data api, and give it to the
# template
builders = mydashboardapp.buildbot_api.dataGet("/builders")

builds = mydashboardapp.buildbot_api.dataGet("/builds", limit=20)

# properties are actually not used in the template example, but this is how you get more properties
# properties are actually not used in the template example, but this is
# how you get more properties
for build in builds:
build['properties'] = mydashboardapp.buildbot_api.dataGet(("builds", build['buildid'], "properties"))
build['properties'] = mydashboardapp.buildbot_api.dataGet(
("builds", build['buildid'], "properties"))

# Example on how to use requests to get some info from other web servers
code_frequency_url = "https://api.github.com/repos/buildbot/buildbot/stats/code_frequency"
Expand All @@ -46,13 +48,17 @@ def main():
graph_data=graph_data)

# Here we assume c['www']['plugins'] has already be created earlier.
# Please see the web server documentation to understand how to configure the other parts.
# Please see the web server documentation to understand how to configure
# the other parts.
c['www']['plugins']['wsgi_dashboards'] = [ # This is a list of dashboards, you can create several
{
'name': 'mydashboard', # as used in URLs
'caption': 'My Dashboard', # Title displayed in the UI'
'app': mydashboardapp,
'order': 5, # priority of the dashboard in the left menu (lower is higher in the menu)
'icon': 'area-chart' # available icon list can be found at http://fontawesome.io/icons/
# priority of the dashboard in the left menu (lower is higher in the
# menu)
'order': 5,
# available icon list can be found at http://fontawesome.io/icons/
'icon': 'area-chart'
}
]

0 comments on commit 771cf06

Please sign in to comment.