~ricardokirkner/pkgme-service/crt-473

« back to all changes in this revision

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

[r=james-w] Detect whether the scanned package is a Snappy package, and return the is_snappy flag to SCA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
import sys
10
10
import tarfile
11
11
import traceback
 
12
import yaml
12
13
 
13
14
from celery.exceptions import MaxRetriesExceededError
14
15
from devportalbinary.metadata import MetadataBackend
757
758
        with open(os.path.join(debian_dir, 'control'), 'w') as f:
758
759
            f.write(control_content)
759
760
 
 
761
    def make_snappy_manifest(self, manifest_content, directory, raw=False):
 
762
        meta_dir = os.path.join(directory, 'meta')
 
763
        if not os.path.exists(meta_dir):
 
764
            os.mkdir(meta_dir)
 
765
        with open(os.path.join(meta_dir, 'package.yaml'), 'w') as f:
 
766
            if raw:
 
767
                content = manifest_content
 
768
            else:
 
769
                content = yaml.dump(manifest_content, default_flow_style=False)
 
770
            f.write(content)
 
771
 
760
772
    def test_get_package_architectures(self):
761
773
        job = ClickPackageInfoJob()
762
774
        tempdir = self.useFixture(TempDir()).path
956
968
 
957
969
        self.assertFalse(mock_process_unpacked.called)
958
970
 
959
 
    @patch('djpkgme.tasks.subprocess.check_output')
960
 
    @patch('djpkgme.tasks.TempDir')
961
 
    def test_integration(self, mock_tempdir, mock_call):
 
971
    def _assert_integration_succeeds(self, mock_tempdir, mock_call, snappy):
962
972
        tempdir = self.useFixture(TempDir())
963
973
        downloaded_path = os.path.join(tempdir.path,
964
974
                                       'apackage_1.0_amd64.click')
973
983
            name=package_fullname,
974
984
            icon='path/to/icon.png'),
975
985
            unpacked_path)
 
986
        if snappy:
 
987
            self.make_snappy_manifest(dict(
 
988
                name=package_fullname,
 
989
                icon='path/to/icon.png'),
 
990
                unpacked_path)
976
991
        self.make_control_file('Architecture: all', unpacked_path)
977
992
 
978
993
        mock_tempdir.return_value = self.make_tempdir_fixture_mock(
984
999
        mock_call.assert_called_with(
985
1000
            ['dpkg-deb', '-R', downloaded_path, unpacked_path],
986
1001
            stderr=subprocess.STDOUT)
987
 
        self.assertEqual(2, len(results))
988
 
        checks, metadata = results
 
1002
        self.assertEqual(3, len(results))
 
1003
        checks, metadata, extra_info = results
989
1004
        # there are no errors
990
1005
        self.assertEqual(0, len(checks['warn']))
991
1006
        self.assertEqual(0, len(checks['error']))
1000
1015
                'filename': 'icon.png',
1001
1016
                'data': None,
1002
1017
            }}, metadata)
 
1018
        # and that the package isn't a snap
 
1019
        self.assertEqual(snappy, extra_info['is_snap'])
 
1020
 
 
1021
    @patch('djpkgme.tasks.subprocess.check_output')
 
1022
    @patch('djpkgme.tasks.TempDir')
 
1023
    def test_integration(self, mock_tempdir, mock_call):
 
1024
        self._assert_integration_succeeds(mock_tempdir, mock_call, False)
 
1025
 
 
1026
    @patch('djpkgme.tasks.subprocess.check_output')
 
1027
    @patch('djpkgme.tasks.TempDir')
 
1028
    def test_snappy_integration(self, mock_tempdir, mock_call):
 
1029
        self._assert_integration_succeeds(mock_tempdir, mock_call, False)
1003
1030
 
1004
1031
 
1005
1032
class TestClickPackageReviewJob(ClickPackageJobTestCase):