Best Python code snippet using autotest_python
test_raw_article.py
Source:test_raw_article.py
...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]).
...
app_plot_chart.py
Source:app_plot_chart.py
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 )...
test_calls.py
Source:test_calls.py
...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")...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!