Beispiel #1
0
    def _locate_apps(self):
        apps = []
        apks = self._locate_files(self.working_dir, '.apk')

        for apk in apks:
            with self._error_swallower():
                Apk.parse(self.config, apk)
                apps.append(apk)

        return self._make_paths_presentable(apps)
    def test_apk_registers_successfully(self):
        apk_file1 = os.path.join(__tests_root__, 'res', 'v1.apk')
        apk_file2 = os.path.join(__tests_root__, 'res', 'v1and2.apk')
        command = RegisterApkCommand(self.config, [apk_file1, apk_file2])

        command.run()

        self.config.api.upload_artifact.assert_has_calls([
            call(apk_file1, Apk.parse(self.config, apk_file1)),
            call(apk_file2, Apk.parse(self.config, apk_file2))
        ], any_order=True)
    def test_project_registers_successfully(self):
        self.config.endpoints_store.__getitem__ = MagicMock(return_value='https://google.com')
        self.config.api.get_build = MagicMock(return_value={'data': {'status': 'COMPLETED'}})
        simple_project = os.path.join(__tests_root__, 'res', 'simple-project')
        apk_file = os.path.join(__tests_root__, 'res', 'simple-project', 'v1.apk')
        working_dir = tempfile.mkdtemp()
        config_file = os.path.join(working_dir, 'mason.yml')
        command = RegisterProjectCommand(self.config, simple_project, working_dir)

        command.run()

        self.config.api.upload_artifact.assert_has_calls([
            call(apk_file, Apk.parse(self.config, apk_file)),
            call(config_file, OSConfig.parse(self.config, config_file))
        ])
        self.config.api.start_build.assert_called_with('project-id2', '2', None)
Beispiel #4
0
    def prepare_apk(self, binary):
        apk = Apk.parse(self.config, binary)

        is_in_project_mode = getattr(self.config, 'project_mode', None)
        if is_in_project_mode:
            try:
                apk_artifact = self.config.api.get_artifact(
                    apk.get_type(), apk.get_name(), apk.get_version())
            except ApiError as e:
                self.config.logger.debug(e, exc_info=True)
                apk_artifact = {}

            checksum = apk_artifact.get('checksum') or {}
            if checksum.get('sha1') == hash_file(binary, 'sha1'):
                apk.already_registered = True

        return apk
Beispiel #5
0
    def test__upload_artifact__apk_requests_are_correct(self):
        apk_file = os.path.join(__tests_root__, 'res/v1.apk')
        artifact = Apk.parse(MagicMock(), apk_file)
        self.handler.get = MagicMock(return_value={
            'signed_request': 'signed_request',
            'url': 'signed_url'
        })

        self.api.upload_artifact(apk_file, artifact)

        self.handler.get.assert_called_with(
            'url_root/mason-test/com.supercilex.test/384866?type=apk&noContentType=true',
            headers={
                'Content-Type': 'application/json',
                'Content-MD5': 'QrDVanEnOLaXIgSL3ut67g==',
                'Authorization': 'Bearer Foobar'
            }
        )
        self.handler.put.assert_called_with(
            'signed_request',
            apk_file,
            headers={
                'Content-MD5': 'QrDVanEnOLaXIgSL3ut67g=='
            }
        )
        self.handler.post.assert_called_with(
            'url_root/mason-test',
            headers={'Content-Type': 'application/json', 'Authorization': 'Bearer Foobar'},
            json={
                'name': 'com.supercilex.test',
                'version': '384866',
                'customer': 'mason-test',
                'url': 'signed_url',
                'type': 'apk',
                'checksum': {'sha1': '891544e59702a6138962a9a2728cb2527fb77554'},
                'apk': {
                    'versionName': '0.1.0-4-g0f30bf8-dirty',
                    'versionCode': '384866',
                    'packageName': 'com.supercilex.test'
                }
            }
        )
Beispiel #6
0
    def test_apk_debug_signed(self):
        mock_config = MagicMock()

        with self.assertRaises(click.Abort):
            Apk.parse(mock_config,
                      os.path.join(__tests_root__, 'res', 'debug.apk'))
Beispiel #7
0
    def test_apk_v1_and_v2_signed(self):
        mock_config = MagicMock()
        apk = Apk.parse(mock_config,
                        os.path.join(__tests_root__, 'res', 'v1and2.apk'))

        self.assertIsNotNone(apk)