Commit 5e37f6de authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

owners_client: Always use slashes as separators.

Change-Id: I6a74971878e5a1abaf6d8f5db20d0387c1abf308
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2701392
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent b44d6781
......@@ -208,6 +208,8 @@ class GerritClient(OwnersClient):
self._owners_cache = {}
def ListOwners(self, path):
# Always use slashes as separators.
path = path.replace(os.sep, '/')
if path not in self._owners_cache:
# GetOwnersForFile returns a list of account details sorted by order of
# best reviewer for path. If owners have the same score, the order is
......
......@@ -26,28 +26,6 @@ dave = 'dave@example.com'
emily = 'emily@example.com'
def _get_owners():
return {
"code_owners": [
{
"account": {
"email": 'approver@example.com'
}
},
{
"account": {
"email": 'reviewer@example.com'
},
},
{
"account": {
"email": 'missing@example.com'
},
}
]
}
class DepotToolsClientTest(unittest.TestCase):
def setUp(self):
self.repo = filesystem_mock.MockFileSystem(files={
......@@ -80,17 +58,39 @@ class DepotToolsClientTest(unittest.TestCase):
class GerritClientTest(unittest.TestCase):
def setUp(self):
self.client = owners_client.GerritClient('host', 'project', 'branch')
mock.patch(
'gerrit_util.GetOwnersForFile',
return_value={
"code_owners": [
{
"account": {
"email": 'approver@example.com'
}
},
{
"account": {
"email": 'reviewer@example.com'
},
},
{
"account": {
"email": 'missing@example.com'
},
}
]
}).start()
self.addCleanup(mock.patch.stopall)
@mock.patch('gerrit_util.GetOwnersForFile', return_value=_get_owners())
def testListOwners(self, _get_owners_mock):
def testListOwners(self):
self.assertEquals(
['approver@example.com', 'reviewer@example.com', 'missing@example.com'],
self.client.ListOwners('bar/everyone/foo.txt'))
self.client.ListOwners(os.path.join('bar', 'everyone', 'foo.txt')))
# Result should be cached.
self.assertEquals(
['approver@example.com', 'reviewer@example.com', 'missing@example.com'],
self.client.ListOwners('bar/everyone/foo.txt'))
self.client.ListOwners(os.path.join('bar', 'everyone', 'foo.txt')))
# Always use slashes as separators.
gerrit_util.GetOwnersForFile.assert_called_once_with(
'host', 'project', 'branch', 'bar/everyone/foo.txt')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment