def test_1baidu_search(self, data): self.home_page.sleep(1) self.home_page.search_input(data.get("name")) # 调用页面对象中的方法 self.home_page.send_submit_btn() # 调用页面对象类中的点击搜索按钮方法 self.home_page.sleep(1) self.home_page.take_screenshot(data.get("name")) # 调用基类截图方法 self.home_page.back() self.assertIn(data.get("name"), self.home_page.get_title(), msg='和预期不一样')
def test_video_worker(self, data): """ Tests video worker object is created with correct values. """ VW = VideoWorker(**data) # Verify that workdir has correct value job_id = data.get('jobid', None) expected_workdir = data.get( 'workdir', os.path.join(ENCODE_WORK_DIR, job_id) if job_id else ENCODE_WORK_DIR) self.assertEqual(VW.workdir, expected_workdir)
def test_get_arg_values_standalone(self, data): """ Arguments.get_arg_values() standalone call test """ opt = Options.__new__(Options) args = argparse.Namespace() args.host = '' args.version = data.get('version') args.update = data.get('update') args.examples = data.get('examples') setattr(opt, '_Options__standalone', ["version", "update", "examples"]) setattr(opt, 'args', args) actual = opt.get_arg_values() self.assertTrue(isinstance(actual, dict)) self.assertTrue(1 == len(actual))
def test_get_arg_values_standalone(self, data): """ Arguments.get_arg_values() standalone call test """ opt = Options.__new__(Options) args = argparse.Namespace() args.host = '' args.version = data.get('version') args.update = data.get('update') args.examples = data.get('examples') args.docs = data.get('docs') setattr(opt, '_Options__standalone', ["version", "update", "examples","docs"]) setattr(opt, 'args', args) actual = opt.get_arg_values() self.assertTrue(isinstance(actual, dict)) self.assertTrue(1 == len(actual))
def test_get_arg_values(self, data): """ Arguments.get_arg_values() test """ opt = Options.__new__(Options) args = argparse.Namespace() args.host = data.get('host') args.port = data.get('port') args.scan = data.get('scan') args.version = False args.update = False args.examples = False setattr(opt, '_Options__standalone', ["version", "update", "examples"]) setattr(opt, 'args', args) actual = opt.get_arg_values() self.assertTrue(isinstance(actual, dict))
def test_get_arg_values(self, data): """ Arguments.get_arg_values() test """ opt = Options.__new__(Options) args = argparse.Namespace() args.host = data.get('host') args.port = data.get('port') args.scan = data.get('scan') args.version = False args.update = False args.examples = False args.docs = False setattr(opt, '_Options__standalone', ["version", "update", "examples", "docs"]) setattr(opt, 'args', args) actual = opt.get_arg_values() self.assertTrue(isinstance(actual, dict))
def test_login(self, case): """登陆""" global TestResult # 全局变量 global token # 执行测试 method = case['Method'] url = case['Url'] param = eval(case['Params']) # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format(case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param,verify=False) data=resp.json() print(data) print(data.get('code')) if data.get('code')==1: return data = resp.json()['data'] print(data) if token is None: # 判断token是否为空 token = data.get("token") print(token) #return token message= resp.json()["code"] print(message) #print(type(message)) try: print(type(case['ExpectedResult'])) self.assertEqual(str(case['ExpectedResult']), str(message)) TestResult = 'pass' except AssertionError as e: TestResult = 'failed' My_log.error('测试执行过程中出错,错误是:{}'.format(e)) raise e finally: # 写回结果 self.T.write_back(case['CaseId'] + 1, 9, message) self.T.write_back(case['CaseId'] + 1, 10, TestResult) My_log.info('测试结果是:{}'.format(TestResult)) # http发送请求拿回的实际结果
def test_case(self, case): global TestResult # 全局变量 global token # 执行测试 method = case['Method'] url = case['Url'] param = eval(case['Params']) # 发起测试 My_log.info('------正在测试{}模块里的第{}条测试用例:{}'.format( case['Module'], case['CaseId'], case['Title'])) My_log.info('测试数据是{}'.format(case)) resp = HttpRequests().http_request(method, url, param, verify=False) data = resp.json() print(data) print(data.get('code')) if data.get('code') == 1: return data = resp.json()['data'] print(data) if token is None: # 判断token是否为空 token = data.get("token") print(token)
def test_engine_intake(self, data, mock_valid, mock_exists, mock_logger, mock_get_bucket, mock_conn): """ Test that `_engine_intake` method works correctly. """ # Setup test data. self.VW.VideoObject.valid = data.get('valid_video', self.VW.VideoObject.valid) self.VW.VideoObject.mezz_extension = '.mp4' self.VW.source_file = data.get('source_file', self.VW.source_file) # Mock s3 bucket and key bucket = Mock(get_key=Mock(return_value=Mock())) # `bucket.get_key` returns None. if data.get('mock_get_bucket_key', False): bucket = Mock(get_key=Mock(return_value=None)) mock_exists.return_value = data.get('path_exists', True) mock_conn.return_value = None mock_get_bucket.return_value = bucket mock_valid.return_value = data.get('validate_valid', False) # Throw S3ResponseError on `s3connection.get_bucket` if not data.get('mock_get_bucket', True): mock_get_bucket.side_effect = S3ResponseError( 403, 'Forbidden', 'Dummy S3ResponseError.') # Add dummy s3 bucket info to settings. worker_settings.update({ 'aws_storage_bucket': 'dummy-aws_storage_bucket', }) self.VW.settings = worker_settings self.VW._engine_intake() if data.get('error_message', ''): mock_logger.assert_called_with(data.get('error_message')) else: self.assertEqual(self.VW.VideoObject.valid, data.get('validate_valid', False))
def test_send_val_data(self, data, mock_logger, mock_get, mock_post, mock_put): """ Tests `send_val_data` method works correctly. """ get_status_code = data.get('get_status_code', 200) post_status_code = data.get('post_status_code', 201) expected_error_message = data.get('error_message', '') response_data = json.dumps({ 'courses': [{ 'dummy-course-id': 'dummy-video-image.jpeg' }], 'encoded_videos': [{ 'url': 'https://testurl.mp4', 'file_size': 8499040, 'bitrate': 131, 'profile': 'override', }] }) mock_get.return_value = Mock(status_code=get_status_code, text=response_data, content=response_data) mock_post.return_value = Mock(status_code=post_status_code, text=response_data, content=response_data) mock_put.return_value = Mock(status_code=post_status_code, text=response_data, content=response_data) communicate_api = self.setup_api( VideoObject=self.Video, val_video_status=self.val_video_status, val_token=data.get('val_token', None), val_id=data.get('val_id', None), course_url=data.get('course_url', []), ) response = communicate_api.send_val_data() if not data.get('val_token', None): self.assertFalse(mock_get.called) self.assertFalse(mock_post.called) self.assertFalse(response) if expected_error_message: self.assertTrue(mock_get.called) if get_status_code == 404: self.assertFalse(mock_put.called) self.assertTrue(mock_post.called) if get_status_code == 200: self.assertFalse(mock_post.called) self.assertTrue(mock_put.called) mock_logger.error.assert_called_with(expected_error_message)
def test_send_val_data(self, data, mock_logger, mock_client): """ Tests `send_val_data` method works correctly. """ get_status_code = data.get('get_status_code', 200) post_status_code = data.get('post_status_code', 201) expected_error_message = data.get('error_message', '') response_data = json.dumps({ 'courses': [{ 'dummy-course-id': 'dummy-video-image.jpeg' }], 'encoded_videos': [{ 'url': 'https://testurl.mp4', 'file_size': 8499040, 'bitrate': 131, 'profile': 'override', }] }) mock_client.get.return_value = Mock(status_code=get_status_code, text=response_data, content=response_data) mock_client.post.return_value = Mock(status_code=post_status_code, text=response_data, content=response_data) mock_client.put.return_value = Mock(status_code=post_status_code, text=response_data, content=response_data) communicate_api = self.setup_api( VideoObject=self.Video, val_video_status=self.val_video_status, val_token=data.get('val_token', None), val_id=data.get('val_id', None), course_url=data.get('course_url', []), ) response = communicate_api.send_val_data() expected_url_id = data.get('val_id', None) or self.Video.veda_id mock_client.assert_called_with( 'GET', WORKER_SETTINGS['val_api_url'] + '/' + expected_url_id + '/')