Changeset View
Changeset View
Standalone View
Standalone View
contrib/buildbot/test/test_phabricator.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# | # | ||||
# Copyright (c) 2020 The Bitcoin ABC developers | # Copyright (c) 2020 The Bitcoin ABC developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
from base64 import b64encode | from base64 import b64encode | ||||
import mock | import mock | ||||
import os | import os | ||||
import unittest | import unittest | ||||
from phabricator import Result | |||||
from phabricator_wrapper import BITCOIN_ABC_PROJECT_PHID, BITCOIN_ABC_REPO | from phabricator_wrapper import BITCOIN_ABC_PROJECT_PHID, BITCOIN_ABC_REPO | ||||
import test.mocks.phabricator | import test.mocks.phabricator | ||||
class PhabricatorTests(unittest.TestCase): | class PhabricatorTests(unittest.TestCase): | ||||
def setUp(self): | def setUp(self): | ||||
self.phab = test.mocks.phabricator.instance() | self.phab = test.mocks.phabricator.instance() | ||||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Lines | def test_get_file_content_from_master(self): | ||||
# Too huge | # Too huge | ||||
configure_file_content_query(too_huge=True) | configure_file_content_query(too_huge=True) | ||||
with self.assertRaisesRegex(AssertionError, "is oversized or took too long to download"): | with self.assertRaisesRegex(AssertionError, "is oversized or took too long to download"): | ||||
self.phab.get_file_content_from_master(path) | self.phab.get_file_content_from_master(path) | ||||
assert_file_commit_and_file_searched() | assert_file_commit_and_file_searched() | ||||
# Check the file content can be retrieved | # Check the file content can be retrieved | ||||
expected_content = b'Some nice content' | expected_content = b'Some nice content' | ||||
self.phab.file.download.return_value = Result( | result = test.mocks.phabricator.Result([]) | ||||
b64encode(expected_content)) | result.response = b64encode(expected_content) | ||||
self.phab.file.download.return_value = result | |||||
configure_file_content_query() | configure_file_content_query() | ||||
file_content = self.phab.get_file_content_from_master(path) | file_content = self.phab.get_file_content_from_master(path) | ||||
assert_file_commit_and_file_searched() | assert_file_commit_and_file_searched() | ||||
self.phab.file.download.assert_called_with(phid=file_phid) | self.phab.file.download.assert_called_with(phid=file_phid) | ||||
self.assertEqual(file_content, expected_content) | self.assertEqual(file_content, expected_content) | ||||
# With later calls the content is returned directly thanks to the cache | # With later calls the content is returned directly thanks to the cache | ||||
self.phab.diffusion.filecontentquery.reset_mock() | self.phab.diffusion.filecontentquery.reset_mock() | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |