elastic-recheck/elastic_recheck/tests/unit/test_graph.py
Joe Gordon 1981ff7b5f Add open reviews to elastic-recheck status page
List open gerrit reviews on the elastic_recheck status page. Listing the
reviews here can help us prioritize reviews of them. Currently one has
to manually dig through the launchpad notes for gerrit review links,
this automates that process.

Instead of looking for jenkins comments in launchpad about open patches,
directly query gerrit for open patches related to the bug on hand. Since
gerrit only supports string matching and not regex for messages, just
look for the bug number in the commit message. Our bug numbers are long
enough that it unlikely the number will come up in other cases.

Change-Id: Ida2144ccc5f0fdf91e2bd70714de80c83f4c1200
2014-08-08 14:38:16 -07:00

38 lines
1.4 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from elastic_recheck.cmd import graph
from elastic_recheck.tests import unit
class FakeResponse(object):
def __init__(self, response_text):
super(FakeResponse, self).__init__()
# magic gerrit prefix
self.text = ")]}'\n" + response_text
class TestGraphCmd(unit.UnitTestCase):
def test_get_open_reviews_empty(self):
with mock.patch('requests.get') as mock_get:
mock_get.return_value = FakeResponse("[]\n")
self.assertEqual(graph.get_open_reviews('1353131'), [])
def test_get_open_reviews(self):
with mock.patch('requests.get') as mock_get:
with open('elastic_recheck/tests/unit/samples/'
'gerrit-bug-query.json') as f:
mock_get.return_value = FakeResponse(f.read())
self.assertEqual(graph.get_open_reviews('1288393'), [113009])