How to use test_paging method in autotest

Best Python code snippet using autotest_python

test_raw_article.py

Source:test_raw_article.py Github

copy

Full Screen

...38 raw_article.save()39 cls.raw_id_list.append(raw_article.id)4041 @tools.nottest42 def test_paging(self, response, query, page, page_size=20):43 """44 翻页功能测试4546 @param page: 页数47 @type page: int48 @param page_size: 每页条数49 @type page_size: int50 @param query: 查询条件51 @type querya: dict52 @return: None53 @rtype: None54 """55 tools.assert_equals(response.status_code, 200)56 json_resp = json.loads(response.data)57 article = RawArticle.objects(**query)58 length = len(article)59 list_len = page_size6061 tools.assert_equals(json_resp['data']['page_sum'], length//20+1)62 if page == json_resp['data']['page_sum']:63 list_len = length % page_size64 if list_len == 0:65 list_len = 206667 tools.assert_equals(len(json_resp['data']['list']), list_len)6869 tools.assert_equals(json_resp['data']['count'], length)70 tools.assert_equals(json_resp['data']['current_page'], page)7172 if page == 1:73 tools.assert_equals(json_resp['data']['list'][0].get(74 'id'), str(self.raw_id_list[-1]))75 tools.assert_is_not_none(json_resp['data']['list'][0].get('news'))76 tools.assert_is_not_none(77 json_resp['data']['list'][0].get('news_count'))7879 @tools.nottest80 def test_search(self, search_word):81 """82 输入搜索关键字,测试文章能否被检出8384 @param search_word: 输入的搜索关键字85 @tpye search_word: str86 @return: None87 @rtype: None88 """89 self.change_user_level(9)90 headers = {'Authorization': self.token}91 url = f'/api/v1/raw_article?search={search_word}'92 response = test_app.get(url, headers=headers)93 query = {94 'is_edited': False,95 'is_translated': True96 }97 self.test_paging(response, query, 1)9899 url = f'/api/v1/raw_article?search={search_word}&page=2'100 response = test_app.get(url, headers=headers)101 self.test_paging(response, query, 2)102103 url = '/api/v1/raw_article?search=a'104 response = test_app.get(url, headers=headers)105 json_resp = self.validate_response(response)106 tools.assert_equals(json_resp['data']['count'], 0)107108 if search_word != '测':109 self.test_search('测')110111 def test_language(self):112 """113 测试查询不同语言的文章114115 1、测试传入错误的语言格式查询116 2、测试查询英文文章,未存,返回值为0117 3、测试查询中文文章,检查返回值是否正确118 4、测试查询结果是否按照入库时间倒序119 5、测试查询结果的翻页功能120 """121 self.change_user_level(9)122 headers = {'Authorization': self.token}123 response = test_app.get('/api/v1/raw_article?language=CN',124 headers=headers)125 json_resp = self.validate_response(response)126 tools.assert_equals(json_resp['data']['count'], 0)127128 headers = {'Authorization': self.token}129 response = test_app.get('/api/v1/raw_article?language=en',130 headers=headers)131 json_resp = self.validate_response(response)132 tools.assert_equals(json_resp['data']['count'], 0)133134 headers = {'Authorization': self.token}135 response = test_app.get('/api/v1/raw_article?language=cn',136 headers=headers)137 json_resp = self.validate_response(response)138 query = {139 'is_edited': False,140 'is_translated': True,141 'language': RawArticleConstant.LANGUAGE_CN142 }143 self.test_paging(response, query, 1)144 tools.assert_equals(json_resp['data']['count'], 25)145 tools.assert_not_equals(json_resp['data']['list'][0],146 RawArticle.get_by_id(self.raw_id_list[0]).147 api_base_response())148 tools.assert_equals(json_resp['data']['list'][0],149 RawArticle.get_by_id(self.raw_id_list[-1]).150 api_base_response())151152 headers = {'Authorization': self.token}153 response = test_app.get('/api/v1/raw_article?language=cn&page=2',154 headers=headers)155 json_resp = self.validate_response(response)156 self.test_paging(response, query, 2)157158 def test_is_cluster(self):159 """160 测试查看聚类文章161162 1、测试查询聚类文章,返回值为0163 2、测试is_cluster不为Ture时是否默认查全部164 3、测试查询结果是否按照入库时间倒序165 4、测试查询结果的翻页功能166 """167 self.change_user_level(9)168 headers = {'Authorization': self.token}169 response = test_app.get('/api/v1/raw_article?is_cluster=true',170 headers=headers)171 json_resp = self.validate_response(response)172 tools.assert_equals(json_resp['data']['count'], 0)173174 headers = {'Authorization': self.token}175 response = test_app.get('/api/v1/raw_article?is_cluster=',176 headers=headers)177 json_resp = self.validate_response(response)178 query = {179 'is_edited': False,180 'is_translated': True181 }182 self.test_paging(response, query, 1)183 tools.assert_equals(json_resp['data']['count'], 25)184 tools.assert_not_equals(json_resp['data']['list'][0],185 RawArticle.get_by_id(self.raw_id_list[0]).186 api_base_response())187 tools.assert_equals(json_resp['data']['list'][0],188 RawArticle.get_by_id(self.raw_id_list[-1]).189 api_base_response())190191 headers = {'Authorization': self.token}192 response = test_app.get('/api/v1/raw_article?is_cluster&page=2',193 headers=headers)194 self.validate_response(response)195 self.test_paging(response, query, 2)196197 raw_article = RawArticle.objects().limit(3)198 for article in raw_article:199 article.news_count = 5200 article.save()201202 headers = {'Authorization': self.token}203 response = test_app.get('/api/v1/raw_article?is_cluster=true',204 headers=headers)205 json_resp = self.validate_response(response)206 tools.assert_equals(json_resp['data']['count'], 3)207 tools.assert_equals(json_resp['data']['list'][0],208 RawArticle.get_by_id(self.raw_id_list[2]).209 api_base_response())210 tools.assert_not_equals(json_resp['data']['list'][0],211 RawArticle.get_by_id(self.raw_id_list[0]).212 api_base_response())213214 def test_day(self):215 """216 测试传入日期,查询某天文章217218 1、测试传入没有文章的一天,返回值为0219 2、测试传入正确时间,检查返回值220 3、测试查询结果是否按照入库时间倒序221 4、测试查询结果的翻页功能222 """223 __time = datetime.now()224 day_str = __time.strftime('%Y%m%d')225 self.change_user_level(9)226 headers = {'Authorization': self.token}227 response = test_app.get('/api/v1/raw_article?day=20100101',228 headers=headers)229 json_resp = self.validate_response(response)230 tools.assert_equals(json_resp['data']['count'], 0)231232 response = test_app.get(f'api/v1/raw_article?day={day_str}',233 headers=headers)234 json_resp = self.validate_response(response)235 query = {236 'is_edited': False,237 'is_translated': True238 }239 self.test_paging(response, query, 1)240 tools.assert_equals(json_resp['data']['count'], 25)241 tools.assert_not_equals(json_resp['data']['list'][0],242 RawArticle.get_by_id(self.raw_id_list[1]).243 api_base_response())244 tools.assert_equals(json_resp['data']['list'][0],245 RawArticle.get_by_id(self.raw_id_list[-1]).246 api_base_response())247248 response = test_app.get(f'api/v1/raw_article?day={day_str}&page=2',249 headers=headers)250 json_resp = self.validate_response(response)251 self.test_paging(response, query, 2)252253 def test_raw_article_get_api(self):254 """255 测试raw_article的get接口,发送请求情况256 1、测试请求成功257 2、测试分页功能258 3、测试不加token认证259 4、测试token值260 5、测试查询详情261 6、测试用户权限262 7、测试搜索功能263 """264 # 测试请求成功 & 测试分页功能(page=1)265 self.change_user_level()266 headers = {'Authorization': self.token}267 response = test_app.get('/api/v1/raw_article', headers=headers)268 query = {269 'is_edited': False,270 'is_translated': True,271 'language': RawArticleConstant.LANGUAGE_CN272 }273 self.test_paging(response, query, 1)274275 # 测试请求成功 & 测试分页功能(page=2)276 headers = {'Authorization': self.token}277 response = test_app.get('/api/v1/raw_article?page=2&page_size=20',278 headers=headers)279 self.test_paging(response, query, 2)280281 # 测试请求所有文章成功 & 测试分页功能(page=1)282 headers = {'Authorization': self.token}283 response = test_app.get('/api/v1/raw_article', headers=headers)284 query = {285 'is_edited': False,286 'is_translated': True287 }288 self.test_paging(response, query, 1)289290 # 测试请求所有文章成功 & 测试分页功能(page=2)291 headers = {'Authorization': self.token}292 response = test_app.get('/api/v1/raw_article?page=2&page_size=20',293 headers=headers)294 self.test_paging(response, query, 2)295296 # 测试不加token认证 & 测试错误的token值297 self.test_api_jwt('/api/v1/user/raw_article', test_app.get)298299 # 测试order_by300 headers = {'Authorization': self.token}301 response = test_app.get('/api/v1/raw_article?order_by=added',302 headers=headers)303 json_resp = self.validate_response(response, 200)304 tools.assert_not_equals(json_resp['data']['list'][0],305 RawArticle.get_by_id(self.raw_id_list[-1]).306 api_base_response())307 tools.assert_equals(json_resp['data']['list'][0],308 RawArticle.get_by_id(self.raw_id_list[0]). ...

Full Screen

Full Screen

app_plot_chart.py

Source:app_plot_chart.py Github

copy

Full Screen

1import argparse2from utilities.mysql_connect import \3 find_fail_the_most_frequently, \4 find_individual_the_most_execution_time, \5 find_individual_the_most_average_execution_time, \6 find_the_most_avg_execution_time, \7 find_the_most_stdev, \8 find_individual_the_most_stdev, \9 find_take_the_most_time_in_pass_tests, \10 find_take_the_most_time_group_by_subname, \11 find_individual_the_most_stdev_and_average, \12 find_the_most_stdev_average, \13 find_individual_the_most_stdev_average_with_numpy, \14 find_one_subset_execution_time_among_build_numbers, \15 find_one_subset_execution_time_among_build_numbers_slaves, \16 find_status_by_single_test17parser = argparse.ArgumentParser(description='Find the slowest job from XCE Tests log')18parser.add_argument('-d', '--days', type = int, metavar='', default=182, required=False, help = 'last n days')19parser.add_argument('-s', '--size', type = int, metavar='', default=10, required=False, help='top list size')20parser.add_argument('-mff', '--most_fail_frequently', action="store_true", help='Find fail the most frequently')21parser.add_argument('-mt', '--most_time', action="store_true", help='Find take the most of time')22parser.add_argument('-ms', '--most_stdev',action="store_true", help='Find the most of standard deviation')23args = parser.parse_args()24if __name__ == '__main__':25 # -----------------------26 # single test27 # -----------------------28 # find_status_by_single_test('io/test_export.py::test_multiple_parquet_telecom_prefixed', args.size, args.days)29 find_status_by_single_test('%test_multiple_parquet_telecom_prefixed%', args.size, args.days)30 # -----------------------31 # compare single subtest32 # -----------------------33 # find_one_subset_execution_time_among_build_numbers( args.size, args.days, 'src/bin/tests/pyTestNew/test_paging.py::testGroupByPaging[False-queryModes2-97-1-10-19-599-17-intCol]' )34 # find_one_subset_execution_time_among_build_numbers_slaves( args.size, args.days, 'src/bin/tests/pyTestNew/test_paging.py::testGroupByPaging[False-queryModes2-97-1-10-19-599-17-intCol]', sort_by='delta', bar_color='red' )35 # find_one_subset_execution_time_among_build_numbers_slaves( args.size, args.days, 'src/bin/tests/pyTestNew/test_paging.py::testGroupByPaging[False-queryModes2-97-1-10-19-599-17-intCol]', sort_by='slave_host', bar_color='orange' )36 # find_one_subset_execution_time_among_build_numbers_slaves( args.size, args.days, 'src/bin/tests/pyTestNew/test_paging.py::testGroupByPaging[False-queryModes2-97-1-10-19-599-17-intCol]', sort_by='build_number', bar_color='green' )37 # find_one_subset_execution_time_among_build_numbers_slaves( args.size, args.days, 'src/bin/tests/pyTestNew/test_paging.py::testGroupByPaging[False-queryModes2-97-1-10-19-599-17-intCol]', sort_by='test_timestamp', bar_color='blue' )38 # find_one_subset_execution_time_among_build_numbers_slaves( args.size, args.days, 'io/test_export.py::test_multiple_parquet_telecom_prefixed', sort_by='test_timestamp', bar_color='blue' )39 # -----------------40 # two in one chart41 # -----------------42 # find_the_most_stdev_average( args.size, args.days )43 # find_individual_the_most_stdev_and_average( args.size, args.days )44 # -----------------45 # single subset46 # -----------------47 # find_individual_the_most_stdev_average_with_numpy( args.size, args.days )48 # -----------------49 # others50 # -----------------51 # find_fail_the_most_frequently( args.size, args.days )52 # find_individual_the_most_execution_time( args.size, args.days )53 # find_individual_the_most_average_execution_time( args.size, args.days )54 # find_individual_the_most_stdev( args.size, args.days )55 # find_the_most_stdev( args.size, args.days )56 #find_take_the_most_time_in_pass_tests( args.size, args.days )57 #find_take_the_most_time_group_by_subname( args.size, args.days )58 # find_the_most_avg_execution_time( args.size, args.days )59 exit()60 if args.most_fail_frequently: find_fail_the_most_frequently( args.size, args.days )61 if args.most_time: find_individual_the_most_execution_time( args.size, args.days )62 if args.most_stdev: find_the_most_stdev( args.size, args.days )...

Full Screen

Full Screen

test_calls.py

Source:test_calls.py Github

copy

Full Screen

...8AUTH = (ACCOUNT_SID, "token")9CALL_SID = "CA47e13748ed59a5733d2c1c1c69a83a28"10list_resource = Calls(BASE_URI, AUTH)11@patch("twilio.rest.resources.make_twilio_request")12def test_paging(mock):13 resp = create_mock_json("tests/resources/calls_list.json")14 mock.return_value = resp15 uri = "{}/Calls".format(BASE_URI)16 list_resource.list(started=date(2010,12,5))17 exp_params = {'StartTime': '2010-12-05'}18 mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)19@patch("twilio.rest.resources.make_twilio_request")20def test_paging(mock):21 resp = create_mock_json("tests/resources/calls_list.json")22 mock.return_value = resp23 uri = "{}/Calls".format(BASE_URI)24 list_resource.list(started_before=date(2010,12,5))25 exp_params = {'StartTime<': '2010-12-05'}26 mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)27@patch("twilio.rest.resources.make_twilio_request")28def test_get(mock):29 resp = create_mock_json("tests/resources/calls_instance.json")30 mock.return_value = resp31 uri = "{}/Calls/{}".format(BASE_URI, CALL_SID)32 r = list_resource.get(CALL_SID)33 mock.assert_called_with("GET", uri, auth=AUTH)34@patch("twilio.rest.resources.make_twilio_request")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful