~matt-goodall/pkgme-service/celery-dev-control

« back to all changes in this revision

Viewing changes to src/djpkgme/tests/test_tasks.py

  • Committer: Tarmac
  • Author(s): Ricardo Kirkner
  • Date: 2014-11-19 18:10:31 UTC
  • mfrom: (192.3.1 override-frameworks)
  • Revision ID: tarmac-20141119181031-elhiek7trso6pva2
[r=james-w] reviewer tools are now always enabled

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
19
18
import mock
20
19
from mock import ANY, Mock, patch
58
57
    PkgmeObjectFactory,
59
58
    TestCaseWithMocks,
60
59
    )
61
 
from djpkgme.tests.helpers import FakeResponse, patch_settings
 
60
from djpkgme.tests.helpers import FakeResponse
62
61
 
63
62
 
64
63
class TestIndent(TestCase):
1050
1049
 
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)
1057
1052
 
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)
1118
1113
 
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)
1125
1119
 
1126
1120
        mock_run_checks.assert_called_once_with(package_path)
1127
1121
 
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)
1134
 
 
1135
 
        self.assertFalse(mock_run_checks.called)
1136
 
 
1137
1122
    @patch('djpkgme.tasks.subprocess.check_output')
1138
1123
    def test_run_click_check(self, mock_call):
1139
1124
        job = ClickPackageReviewJob()
1308
1293
 
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'),
1324
 
                                unpacked_path)
1325
 
 
1326
 
        mock_tempdir.return_value = self.make_tempdir_fixture_mock(
1327
 
            tempdir.path)
1328
 
 
1329
 
        with patch_settings(CLICK_REVIEWERS_TOOLS_ENABLED=False):
1330
 
            job = ClickPackageReviewJob()
1331
 
            results = job.run(metadata, logger)
1332
 
 
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']))
1340
 
 
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())
1363
1316
            "error": {}
1364
1317
        })
1365
1318
 
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)
1369
1321
 
1370
1322
        mock_call.assert_any_call(
1371
1323
            ['dpkg-deb', '-R', downloaded_path, unpacked_path],