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 setUp(self): config = MagicMock() test_package_name = 'com.this.is.a.test' test_package_version = '11' test_package_version_code = 16 apkf = MagicMock() apkf.package = MagicMock(return_value=test_package_name) apkf.get_androidversion_name = MagicMock(return_value=test_package_version) apkf.get_androidversion_code = MagicMock(return_value=test_package_version_code) apkf.is_valid_APK = MagicMock(return_value=True) apkf.get_min_sdk_version = MagicMock(return_value=23) self.test_apk = Apk(config, MagicMock(), apkf)
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)
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
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' } } )
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'))
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)
class ApkTest(unittest.TestCase): def setUp(self): config = MagicMock() test_package_name = 'com.this.is.a.test' test_package_version = '11' test_package_version_code = 16 apkf = MagicMock() apkf.package = MagicMock(return_value=test_package_name) apkf.get_androidversion_name = MagicMock( return_value=test_package_version) apkf.get_androidversion_code = MagicMock( return_value=test_package_version_code) apkf.is_valid_APK = MagicMock(return_value=True) apkf.get_min_sdk_version = MagicMock(return_value=23) self.test_apk = Apk(config, MagicMock(), apkf) def test_apk_is_valid(self): self.assertIsNone(self.test_apk.validate()) def test_apk_content_type(self): self.assertEqual(self.test_apk.get_content_type(), 'application/vnd.android.package-archive') def test_apk_type(self): self.assertEqual(self.test_apk.get_type(), 'apk') def test_apk_pretty_type(self): self.assertEqual(self.test_apk.get_pretty_type(), 'App') def test_apk_sub_type(self): self.assertIsNone(self.test_apk.get_sub_type()) def test_apk_name(self): self.assertEqual(self.test_apk.get_name(), self.test_apk.apk.get_package()) def test_apk_version(self): self.assertEqual(self.test_apk.get_version(), self.test_apk.apk.get_androidversion_code()) def test_apk_meta_data(self): meta_data = { 'apk': { 'versionName': self.test_apk.apk.get_androidversion_name(), 'versionCode': self.test_apk.apk.get_androidversion_code(), 'packageName': self.test_apk.apk.get_package() }, } self.assertEqual(self.test_apk.get_registry_meta_data(), meta_data) def test_apk_v1_signed(self): mock_config = MagicMock() apk = Apk.parse(mock_config, os.path.join(__tests_root__, 'res', 'v1.apk')) self.assertIsNotNone(apk) def test_apk_v2_signed(self): mock_config = MagicMock() apk = Apk.parse(mock_config, os.path.join(__tests_root__, 'res', 'v2.apk')) self.assertIsNotNone(apk) 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) def test_apk_unsigned(self): mock_config = MagicMock() with self.assertRaises(click.Abort): Apk.parse(mock_config, os.path.join(__tests_root__, 'res', 'unsigned.apk')) 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'))