def test_attribute_error(self): cli.client.get_run = mock.MagicMock(return_value=None) result = runner.invoke(cli.result, ['arn']) self.assertEqual(result.exit_code, -1) cli.client.get_run = mock.MagicMock(return_value={'run': {'status': 'COMPLETED'}}) cli.client.list_jobs = mock.MagicMock(return_value=None) result = runner.invoke(cli.result, ['arn']) self.assertEqual(result.exit_code, -1)
def test_list(self, mocked_print): items = ['devices', 'projects', 'groups', 'uploads', 'runs'] for pos, item in enumerate(items): cli.client = mock.MagicMock() if pos > 1: with mock.patch('click.prompt') as mocked_click: result = runner.invoke(cli.list, [item]) self.assertTrue(mocked_click.called) else: result = runner.invoke(cli.list, [item]) self.assertTrue(mocked_print.called) self.assertEqual(result.exit_code, 0)
def test_valid_result(self): cli.client.get_run = mock.MagicMock(return_value={'run': {'status': 'COMPLETED'}}) cli.client.list_jobs = mock.MagicMock(return_value={'jobs': [ {'arn': 'arn:aws:devicefarm:us-west-2:xxx', 'name': 'LG Nexus 5', 'unneded_key1': 'value1'}, {'arn': 'arn:aws:devicefarm:us-west-2:xxx', 'name': 'Samsung Galaxy S7 Edge', 'unneded_key2': 'value2'} ]}) cli.client.list_artifacts = mock.MagicMock(return_value={'artifacts': [ {'type': 'result-xml', 'url': 'https://xml', 'unneded_key1': 'value1'}, {'type': 'video', 'url': 'https://video', 'unneded_key2': 'value2'} ]}) result = runner.invoke(cli.result, ['arn']) self.assertEqual(result.exit_code, 0) result = runner.invoke(cli.result, ['arn', '--json-output', '--result-only']) self.assertEqual(result.exit_code, 0)
def test_url_path(self): with mock.patch('urllib.request.urlopen'): cli.client.create_upload = mock.MagicMock(return_value={'upload': {'url': 'https://test', 'arn': 'arn'}}) requests.put = mock.MagicMock() result = runner.invoke(cli.upload, ['-n', 'test_upload', '-p', 'test_project', '-t', 'ANDROID_APP', '-f', 'https://app.apk']) self.assertEqual(result.exit_code, 0)
def test_delete(self): cli.client = mock.MagicMock() arguments = ['project', 'upload', 'group', 'run'] for a in arguments: delete_operation = runner.invoke(cli.delete, [a, 'arn:aws:devicefarm:us-west-2:xxx']) self.assertEqual(delete_operation.exit_code, 0)
def test_pull_attempts(self): cli.client.get_run = mock.MagicMock(return_value={'run': {'status': 'IN PROGRESS'}}) total_attempts = 2 with mock.patch('time.sleep') as mocked_sleep: self.assertFalse(mocked_sleep.called) result = runner.invoke(cli.result, ['arn', '-a', total_attempts, '-d', 0.5]) self.assertTrue(mocked_sleep.called) self.assertEqual(total_attempts, mocked_sleep.call_count) self.assertEqual(result.exit_code, 0)
def test_multiple_devices(self): cli.client.create_device_pool = mock.MagicMock( return_value={'devicePool': { 'arn': 'arn' }}) result = runner.invoke(cli.group, [ '-n', 'test_group', '-p', 'test_project', '-d', 'device1', '-d', 'device2' ]) self.assertEqual(result.exit_code, 0)
def test_schedule_test(self): cli.client.schedule_run = mock.MagicMock( return_value={'run': { 'key1': 'value1' }}) result = runner.invoke(cli.run, [ '-n', 'test_run', '-p', 'test_project', '-a', 'app_id', '-r', 'APPIUM_PYTHON', '-t', 'test_id', '-g', 'group_id' ]) self.assertEqual(result.exit_code, 0)
def test_invalid_type(self): result = runner.invoke(cli.upload, [ '-n', 'test_upload', '-p', 'test_project', '-f', 'app.apk', '-t', 'invalidtype' ]) self.assertEqual(result.exit_code, 2)
def test_empty_status(self): cli.client.get_run = mock.MagicMock(return_value={'run': {'status': None}}) result = runner.invoke(cli.result, ['arn']) self.assertEqual(result.exit_code, 0)
def test_create_project(self): cli.client.create_project = mock.MagicMock(return_value={'project': {'arn': 'value'}}) result = runner.invoke(cli.create, ['my_project']) self.assertEqual(result.exit_code, 0)