14
14
from devportalbinary.metadata import MetadataBackend
15
15
from devportalbinary.testing import LibdepFixture
16
16
from django.conf import settings
17
from django.test.utils import override_settings
18
17
from fixtures import TempDir
20
19
from mock import ANY, Mock, patch
1051
1050
def setUp(self):
1052
1051
super(TestClickPackageReviewJobIntegration, self).setUp()
1053
patched_settings = override_settings(
1054
CLICK_REVIEWERS_TOOLS_ENABLED=False)
1055
patched_settings.enable()
1056
self.addCleanup(patched_settings.disable)
1058
1053
p = patch('djpkgme._version._sourcecode_versions', {
1059
1054
'click-reviewers-tools': 'r42'})
1116
1111
status='error', text=explanation)
1117
1112
self.assertEqual(result, expected_result)
1119
def test_process_click_package_with_reviewers_tools_enabled(self):
1114
def test_process_click_package_with_reviewers_tools(self):
1120
1115
package_path = '/path/to/unpacked'
1121
1116
job = ClickPackageReviewJob()
1122
1117
with patch.object(job, 'click_run_checks') as mock_run_checks:
1123
with patch_settings(CLICK_REVIEWERS_TOOLS_ENABLED=True):
1124
job.process_click_package(package_path)
1118
job.process_click_package(package_path)
1126
1120
mock_run_checks.assert_called_once_with(package_path)
1128
def test_process_click_package_with_reviewers_tools_disabled(self):
1129
package_path = '/path/to/unpacked'
1130
job = ClickPackageReviewJob()
1131
with patch.object(job, 'click_run_checks') as mock_run_checks:
1132
with patch_settings(CLICK_REVIEWERS_TOOLS_ENABLED=False):
1133
job.process_click_package(package_path)
1135
self.assertFalse(mock_run_checks.called)
1137
1122
@patch('djpkgme.tasks.subprocess.check_output')
1138
1123
def test_run_click_check(self, mock_call):
1139
1124
job = ClickPackageReviewJob()
1309
1294
@patch('djpkgme.tasks.subprocess.check_output')
1310
1295
@patch('djpkgme.tasks.TempDir')
1311
def test_integration_without_reviewer_tools(
1312
self, mock_tempdir, mock_call):
1313
tempdir = self.useFixture(TempDir())
1314
downloaded_path = os.path.join(tempdir.path,
1315
'apackage_1.0_amd64.click')
1316
unpacked_path = os.path.join(tempdir.path, 'unpacked')
1317
os.mkdir(unpacked_path)
1318
package_fullname = 'apackage'
1319
metadata = dict(package_fullname=package_fullname, version='1.0',
1320
architecture='amd64',
1321
package_url='http://example.org/download')
1322
logger = logging.getLogger()
1323
self.make_manifest_file(dict(name=package_fullname, version='1.0'),
1326
mock_tempdir.return_value = self.make_tempdir_fixture_mock(
1329
with patch_settings(CLICK_REVIEWERS_TOOLS_ENABLED=False):
1330
job = ClickPackageReviewJob()
1331
results = job.run(metadata, logger)
1333
mock_call.assert_any_call(
1334
['dpkg-deb', '-R', downloaded_path, unpacked_path],
1335
stderr=subprocess.STDOUT)
1336
self.assertEqual(3, len(results.keys()))
1337
self.assertEqual(3, len(results['info']))
1338
self.assertEqual(0, len(results['warn']))
1339
self.assertEqual(0, len(results['error']))
1341
@patch('djpkgme.tasks.subprocess.check_output')
1342
@patch('djpkgme.tasks.TempDir')
1343
1296
def test_integration_with_reviewer_tools(
1344
1297
self, mock_tempdir, mock_call):
1345
1298
tempdir = self.useFixture(TempDir())
1366
with patch_settings(CLICK_REVIEWERS_TOOLS_ENABLED=True):
1367
job = ClickPackageReviewJob()
1368
results = job.run(metadata, logger)
1319
job = ClickPackageReviewJob()
1320
results = job.run(metadata, logger)
1370
1322
mock_call.assert_any_call(
1371
1323
['dpkg-deb', '-R', downloaded_path, unpacked_path],