How to use test_version method in Molotov

Best Python code snippet using molotov_python

views_of_rex.py

Source:views_of_rex.py Github

copy

Full Screen

1#! /usr/bin/env python32# coding=utf-83"""4< For Rex Debug >5"""6from django.shortcuts import render,render_to_response7from django.http import HttpResponse,HttpResponseRedirect,HttpResponseNotFound8import json,time,threading,copy,os,re9from pprint import pprint as pp, pformat10from AcisDB import log11from AcisDB import vcore12import logging13mlogger = logging.getLogger(__name__).info14class RexExcelProvider(vcore.Provider):15 from .test_cookies_of_rex import (show_time_first_from_excel,16 show_time_second_from_excel,17 show_time_third_from_excel,18 show_time_fourth_from_excel)19 self_test = {20 "first" : show_time_first_from_excel,21 "second" : show_time_second_from_excel,22 "third" : show_time_third_from_excel,23 "fourth" : show_time_fourth_from_excel,24 }25 def __init__(self,platform = "SD55", test_version = "first"):26 self.platform = platform27 self.test_version = test_version28 def get_data(self):29 t = RexExcelProvider.self_test[self.test_version](self.platform)30 logger_to_excel = logging.getLogger(__name__ + '.from_excel')31 logger_to_excel.info(pformat(t))32 return t33 @property34 def formatted_rawdata(self):35 return self.get_data()36class RexJiraProvider(vcore.Provider):37 from .test_cookies_of_rex import (show_time_first_from_jira,38 show_time_second_from_jira,39 show_time_third_from_jira,40 show_time_fourth_from_jira,41 follow_second_excel_update_jira,42 follow_third_excel_update_jira ,43 follow_fourth_excel_update_jira,44 )45 self_test = {46 "first" : show_time_first_from_jira,47 "second" : show_time_second_from_jira,48 "third" : show_time_third_from_jira,49 "fourth" : show_time_fourth_from_jira,50 "follow01" : follow_second_excel_update_jira,51 "follow02" : follow_third_excel_update_jira ,52 "follow03" : follow_fourth_excel_update_jira,53 }54 def __init__(self, platform, test_version):55 self.platform = platform56 self.test_version = test_version57 def get_data(self):58 t = RexJiraProvider.self_test[self.test_version](self.platform)59 logger_to_jira = logging.getLogger(__name__ + '.from_jira')60 logger_to_jira.info(pformat(t))61 return t62 @property63 def formatted_rawdata(self):64 return self.get_data()65class ExcelProvider(vcore.Provider):66 from .test_cookies_of_rex import (67 test_get_excel_data_first,68 test_get_excel_data_second,69 test_get_excel_data_third,70 test_get_excel_data_fourth,71 )72 self_test = {73 "first" : test_get_excel_data_first,74 "second" : test_get_excel_data_second,75 "third" : test_get_excel_data_third,76 "fourth" : test_get_excel_data_fourth,77 }78 def __init__(self,platform = "SD55", test_version = "first"):79 self.platform = platform80 self.test_version = test_version81 def get_data(self):82 t = ExcelProvider.self_test[self.test_version](self.platform)83 logger_to_excel = logging.getLogger(__name__ + '.from_excel')84 logger_to_excel.info(pformat(t))85 return t86 @property87 def formatted_rawdata(self):88 """89 For Excel Data:90 >>> [91 >>> ...92 >>> {93 >>> "PLATFORM" : "",94 >>> "ERD_ID" : "",95 >>> "excel" : {96 >>> 'erd_id' : "",97 >>> 'category' : "",98 >>> 'title' : "",99 >>> 'description' : "",100 >>> 'product_priority' : "",101 >>> 'author' : "",102 >>> 'version' : "",103 >>> 'platform' : "",104 >>> }105 >>> ...106 >>> ]107 """108 return self.get_data()109class JiraProvider(vcore.Provider):110 from .test_cookies_of_rex import (111 test_get_jira_data_first,112 test_get_jira_data_second,113 test_get_jira_data_third,114 )115 self_test = {116 "first" : test_get_jira_data_first,117 "second" : test_get_jira_data_second,118 "third" : test_get_jira_data_third,119 }120 def __init__(self, platform, test_version):121 self.platform = platform122 self.test_version = test_version123 def get_data(self):124 t = JiraProvider.self_test[self.test_version](self.platform)125 logger_to_jira = logging.getLogger(__name__ + '.from_jira')126 logger_to_jira.info(pformat(t))127 return t128 @property129 def formatted_rawdata(self):130 """131 For JIRA Ticket Data:132 >>> [133 >>> ...134 >>> {135 >>> "PLATFORM" : "",136 >>> "ERD_ID" : "",137 >>> "jira" : {138 >>> 'HLD' : "",139 >>> 'status' : "",140 >>> 'l1_jira' : "",141 >>> 'l2_jira' : "",142 >>> 'bug_jiras' : "",143 >>> 'platform' : "",144 >>> 'workload' : "",145 >>> 'F_casetree' : [146 >>> ...147 >>> {148 >>> 'case_name' : "",149 >>> 'case_age' : "",150 >>> 'F_report_path': "",151 >>> },152 >>> ... ]153 >>> }154 >>> ...155 >>> ]156 """157 return self.get_data()158class JenkinsProvider(vcore.Provider):159 from .test_cookies_of_rex import (160 show_time_jenkins_test_01,161 show_time_jenkins_test_02,162 show_time_jenkins_test_03,163 show_time_jenkins_test_04,164 show_time_jenkins_test_05,165 show_time_jenkins_test_06,166 show_time_jenkins_test_07,167 )168 self_test = {169 "test01" : show_time_jenkins_test_01,170 "test02" : show_time_jenkins_test_02,171 "test03" : show_time_jenkins_test_03,172 "test04" : show_time_jenkins_test_04,173 "test05" : show_time_jenkins_test_05,174 "test06" : show_time_jenkins_test_06,175 "test07" : show_time_jenkins_test_07,176 }177 def __init__(self, platform, test_version):178 self.platform = platform179 self.test_version = test_version180 def get_data(self):181 t = JenkinsProvider.self_test[self.test_version](self.platform)182 logger_to_jenkins = logging.getLogger(__name__ + '.from_jenkins')183 logger_to_jenkins.info(pformat(t))184 # pp(t)185 # assert False,'hope'186 return t187 @property188 def formatted_rawdata(self):189 """190 For Jenkins Test Data:191 NOTE: For jenkins data, ONLY one element for list.192 >>> [{193 >>> "PLATFORM" : "",194 >>> "jenkins" : {195 >>> 'IR_casetree' : {196 >>> 'ACIS_A_S_Test_Temp_Volt' : {197 >>> 'fw_version' : "",198 >>> 'test_result' : "",199 >>> 'test_log' : "",200 >>> 'test_date' : "",201 >>> 'IR_report_path' : "",202 >>> },203 >>> 'ACIS_A_S_Test_Temp_ssss' : {204 >>> 'fw_version' : "",205 >>> 'test_result' : "",206 >>> 'test_log' : "",207 >>> 'test_date' : "",208 >>> 'IR_report_path' : "",209 >>> },210 >>> 'ACIS_A_S_Test_Temp_abcd' : {211 >>> 'fw_version' : "",212 >>> 'test_result' : "",213 >>> 'test_log' : "",214 >>> 'test_date' : "",215 >>> 'IR_report_path' : "",216 >>> },217 >>> ... ...218 >>> }219 >>> }220 >>> }]221 """222 return self.get_data()223class SubProvider(vcore.Provider):224 @property225 def formatted_rawdata(self):226 from .test_cookies_of_rex import random_gen_cookies227 return random_gen_cookies()228class IntegrationExtractor(vcore.Extractor):229 @property230 def UI_data(self):231 UI_out = []232 data = self._get_data()233 out = {}234 for case_name, vs in data['IR_casetree'].items():235 out['platform'] = data['platform']236 out['fw_version'] = data['fw_version']237 out['case_name'] = case_name238 out['erd_id'] = vs['erd_id']239 out['test_log'] = vs['test_log']240 out['test_date'] = vs['test_date']241 out['test_result'] = vs['test_result']242 out['IR_report_path'] = vs['IR_report_path']243 UI_out.append(out)244 out = {}245 return UI_out246class DefaultExtractor(vcore.Extractor):247 def is_vaild_ver(self, spec_ver):248 return True if type(spec_ver) == str and re.match('\d{2}.\d{2}', spec_ver) else False249 def ext_snapshot(self, platform , spec_ver = "max"):250 out = []251 data = self._get_data().pop(platform)252 for d in data:253 tmp_out = {}254 ERD_ID = d255 others = data[d]256 if not others['excel']: continue257 versions = sorted(list(others['excel'].keys()))258 sub_versions = []259 if spec_ver == "max":260 lastest_ver = max(versions)261 sub_versions = versions262 else:263 if not self.is_vaild_ver(spec_ver):264 sub_versions = versions265 lastest_ver = max(versions)266 else:267 if spec_ver in versions:268 sub_versions = versions[:versions.index(spec_ver) + 1]269 lastest_ver = spec_ver270 else:271 if spec_ver > max(versions):272 sub_versions = versions273 lastest_ver = max(versions)274 elif spec_ver < min(versions):275 sub_versions = []276 lastest_ver = ""277 else:278 for v in versions:279 if spec_ver < v:280 sub_versions = versions[:versions.index(v)]281 lastest_ver = versions[versions.index(v)-1]282 break283 # print("UI lastest version : <{}> for ERD : [{}]".format(lastest_ver, ERD_ID))284 if lastest_ver == "":285 continue286 print("versions : {}".format(versions))287 print("sub_versions : {}".format(sub_versions))288 tmp_out['version'] = {}289 for sv in sub_versions:290 if others['excel'][sv]['description'] == 'blank':291 tmp_out['version'][sv] = 'deactive'292 else:293 tmp_out['version'][sv] = 'active'294 print("output version dict: {}".format(tmp_out['version']))295 deep_excel = others['excel'][lastest_ver]296 deep_jira = others['jira'][lastest_ver]297 # excel part : ERD table partition298 tmp_out['erd_id'] = deep_excel['erd_id']299 tmp_out['platform'] = deep_excel['platform']300 tmp_out['author'] = deep_excel['author']301 tmp_out['category'] = deep_excel['category']302 tmp_out['product_priority'] = deep_excel['product_priority']303 tmp_out['title'] = deep_excel['title']304 tmp_out['description'] = deep_excel['description']305 # jira part : ERD table partition306 tmp_out['HLD'] = deep_jira['HLD']307 tmp_out['l1_jira'] = deep_jira['l1_jira']308 tmp_out['l2_jira'] = deep_jira['l2_jira']309 tmp_out['status'] = deep_jira['status']310 tmp_out['workload'] = deep_jira['workload']311 if deep_jira['bug_jiras']:312 tmp_out['bug_jiras'] = deep_jira['bug_jiras'].split(',')313 else:314 tmp_out['bug_jiras'] = []315 # jira part : TestCases table partition316 # Now Maybe 'case_age' NOT display317 tmp_out['case_name'] = list(deep_jira['F_casetree'].keys())318 tmp_out['F_report_path'] = []319 for dj in deep_jira['F_casetree']:320 tmp_out['F_report_path'].append(deep_jira['F_casetree'][dj]['F_report_path'])321 out.append(tmp_out)322 return out323def query_switch(request):324 if request.method == "GET":325 platform = request.GET.get('platform')326 action = request.GET.get('action')327 if action == 'ERD_table_version':328 print("recored query:\n{}\n{}\n{}".format(platform,action,request.GET.get('ErdTableVersion')))329 erd_table_version = request.GET.get('ErdTableVersion')330 de = DefaultExtractor([platform.upper()])331 vcore.splitter('pick_all', extractor = de )332 out = de.ext_snapshot(platform = platform.upper(), spec_ver = erd_table_version)333 return render(request, 'LigerUI/ACIS/rex_debug/rex_test_page.htm', {'cookies' : json.dumps(out)})334 elif action == 'integration_version':335 fw_version = request.GET.get('FirmwareVersion')336 ie = IntegrationExtractor([platform],fw_version = fw_version)337 vcore.splitter('pick_all', extractor = ie )338 return render(request, 'LigerUI/ACIS/integration_page.htm', {'cookies' : json.dumps(ie.UI_data)})339 else:340 return HttpResponseNotFound("<h2> Please input 'platform' and 'action' togather.</h2>")341 elif request.method == "POST":342 print("POST request, but do nothing.")343def rex_home(request):344 de = DefaultExtractor(['SD55'])345 vcore.splitter('pick_all', extractor = de )346 out = de.ext_snapshot('SD55')347 mlogger(pformat(out))348 return render(request, 'LigerUI/ACIS/rex_debug/rex_test_page.htm', {'cookies' : json.dumps(out)})349def ERD_9X28_index(request):350 de = DefaultExtractor(['9X28'])351 vcore.splitter('pick_all', extractor = de )352 out = de.ext_snapshot('9X28')353 pp(type(out))354 return render(request, 'LigerUI/ACIS/rex_debug/rex_test_page.htm', {'cookies' : json.dumps(out)})355def ERD_9X40_index(request):356 de = DefaultExtractor(['9X40'])357 vcore.splitter('pick_all', extractor = de )358 out = de.ext_snapshot('9X40')359 return render(request, 'LigerUI/ACIS/rex_debug/rex_test_page.htm', {'cookies' : json.dumps(out)})360def ERD_SD55_index(request):361 de = DefaultExtractor(['SD55'])362 vcore.splitter('pick_all', extractor = de )363 out = de.ext_snapshot('SD55')364 return render(request, 'LigerUI/ACIS/rex_debug/rex_test_page.htm', {'cookies' : json.dumps(out)})365def columns_data_select(request):366 return render(request, 'LigerUI/ACIS/columns_data_select.htm')367def help(request):368 return render(request, 'LigerUI/ACIS/help.htm', {})369def about(request):370 return render(request, 'LigerUI/ACIS/about.htm', {})371def query(request):372 return render(request, 'LigerUI/ACIS/query.htm', {})373def do_save_excel():374 vcore.splitter('save', provider = ExcelProvider())375def do_save_jira():376 vcore.splitter('save', provider = JiraProvider())377def do_save_jenkins():378 vcore.splitter('save', provider = JenkinsProvider())379def do_save_UI():380 pass381def do_save_excel_test1():382 vcore.splitter('save', provider = ExcelProvider(test_version = 'first'))383def do_save_excel_test2():384 vcore.splitter('save', provider = ExcelProvider(test_version = 'second'))385def do_save_excel_test3():386 vcore.splitter('save', provider = ExcelProvider(test_version = 'third'))387def do_save_excel_test4():388 vcore.splitter('save', provider = ExcelProvider(test_version = 'fourth'))389def do_save_excel_test1_o():390 vcore.splitter('save', provider = ExcelProvider(platform = '9X28', test_version = 'first'))391def do_save_excel_test2_o():392 vcore.splitter('save', provider = ExcelProvider(platform = '9X28', test_version = 'second'))393def do_save_excel_test3_o():394 vcore.splitter('save', provider = ExcelProvider(platform = '9X28', test_version = 'third'))395def do_save_excel_test4_o():396 vcore.splitter('save', provider = ExcelProvider(platform = '9X28', test_version = 'fourth'))397def do_save_jira_test1():398 vcore.splitter('save', provider = JiraProvider(platform = 'SD55', test_version = 'first'))399def do_save_jira_test2():400 vcore.splitter('save', provider = JiraProvider(platform = 'SD55', test_version = 'second'))401def do_save_jira_test3():402 vcore.splitter('save', provider = JiraProvider(platform = 'SD55', test_version = 'third'))403def do_save_jira_test1_o():404 vcore.splitter('save', provider = JiraProvider(platform = '9X28', test_version = 'first'))405def do_save_jira_test2_o():406 vcore.splitter('save', provider = JiraProvider(platform = '9X28', test_version = 'second'))407def do_save_jira_test3_o():408 vcore.splitter('save', provider = JiraProvider(platform = '9X28', test_version = 'third'))409def do_save_jenkins_test1():410 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'first'))411def do_save_jenkins_test2():412 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'second'))413def do_save_jenkins_test3():414 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'third'))415def do_save_jenkins_test1_o():416 vcore.splitter('save', provider = JenkinsProvider(platform = '9X28', test_version = 'first'))417def do_save_jenkins_test2_o():418 vcore.splitter('save', provider = JenkinsProvider(platform = '9X28', test_version = 'second'))419def do_save_jenkins_test3_o():420 vcore.splitter('save', provider = JenkinsProvider(platform = '9X28', test_version = 'third'))421supported_cmds = {422 'save_excel_data' : do_save_excel,423 'save_jira_data' : do_save_jira,424 'save_jenkins_data': do_save_jenkins,425 'save_UI_data' : do_save_UI,426 'save_excel_data_test1_SD55' : do_save_excel_test1,427 'save_excel_data_test2_SD55' : do_save_excel_test2,428 'save_excel_data_test3_SD55' : do_save_excel_test3,429 'save_excel_data_test4_SD55' : do_save_excel_test4,430 'save_excel_data_test1_9X28' : do_save_excel_test1_o,431 'save_excel_data_test2_9X28' : do_save_excel_test2_o,432 'save_excel_data_test3_9X28' : do_save_excel_test3_o,433 'save_excel_data_test4_9X28' : do_save_excel_test4_o,434 'save_jira_data_test1_SD55' : do_save_jira_test1,435 'save_jira_data_test2_SD55' : do_save_jira_test2,436 'save_jira_data_test3_SD55' : do_save_jira_test3,437 'save_jira_data_test1_9X28' : do_save_jira_test1_o,438 'save_jira_data_test2_9X28' : do_save_jira_test2_o,439 'save_jira_data_test3_9X28' : do_save_jira_test3_o,440 'save_jenkins_data_test1_SD55' : do_save_jenkins_test1,441 'save_jenkins_data_test2_SD55' : do_save_jenkins_test2,442 'save_jenkins_data_test3_SD55' : do_save_jenkins_test3,443 'save_jenkins_data_test1_9X28' : do_save_jenkins_test1_o,444 'save_jenkins_data_test2_9X28' : do_save_jenkins_test2_o,445 'save_jenkins_data_test3_9X28' : do_save_jenkins_test3_o,446}447def rex_commands(request):448 return render(request, 'LigerUI/ACIS/rex_debug/rex_debug_commands.htm', {'cmds' : list(supported_cmds.keys())})449def rex_actions_dispatcher(request):450 # Maybe only one.451 for name, cmd in request.GET.items():452 if name == "command":453 if cmd and cmd in supported_cmds:454 supported_cmds[cmd]()455 return HttpResponseRedirect("/rex_commands/")456def show_time_do_excel_save():457 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'first'))458def show_time_do_jira_save_first():459 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'first'))460def show_time_do_jira_save_second():461 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'second'))462def show_time_do_jira_save_third():463 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'third'))464def show_time_do_excel_second_update():465 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'second'))466 # vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow'))467def show_time_do_excel_third_update():468 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'third'))469 # vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow'))470def show_time_do_excel_fourth_update():471 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'fourth'))472 # vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow'))473def show_time_do_follow_excel():474 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow'))475def do_step_01():476 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'first'))477def do_step_02():478 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'first'))479def do_step_03():480 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'second'))481def do_step_04():482 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test01'))483def do_step_05():484 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'second'))485def do_step_06():486 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow01'))487def do_step_07():488 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test02'))489def do_step_08():490 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'third'))491def do_step_09():492 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test03'))493def do_step_10():494 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'third'))495def do_step_11():496 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow02'))497def do_step_12():498 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test04'))499def do_step_13():500 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'fourth'))501def do_step_14():502 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test05'))503def do_step_15():504 vcore.splitter('save', provider = RexExcelProvider(platform = 'SD55', test_version = 'fourth'))505def do_step_16():506 vcore.splitter('save', provider = RexJiraProvider(platform = 'SD55', test_version = 'follow03'))507def do_step_17():508 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test06'))509def do_step_18():510 vcore.splitter('save', provider = JenkinsProvider(platform = 'SD55', test_version = 'test07'))511show_supported_cmds = {512 'do_step_01' : do_step_01,513 'do_step_02' : do_step_02,514 'do_step_03' : do_step_03,515 'do_step_04' : do_step_04,516 'do_step_05' : do_step_05,517 'do_step_06' : do_step_06,518 'do_step_07' : do_step_07,519 'do_step_08' : do_step_08,520 'do_step_09' : do_step_09,521 'do_step_10' : do_step_10,522 'do_step_11' : do_step_11,523 'do_step_12' : do_step_12,524 'do_step_13' : do_step_13,525 'do_step_14' : do_step_14,526 'do_step_15' : do_step_15,527 'do_step_16' : do_step_16,528 'do_step_17' : do_step_17,529 'do_step_18' : do_step_18,530}531global_cmd = ""532def rex_show_actions_dispatcher(request):533 # assert False, "Rex >> {}".format(request.path)534 print("Hook: GET->{} , POST->{}, path->{}".format(request.GET,request.POST, request.path))535 global global_cmd536 for name, cmd in request.GET.items():537 if name == "command":538 if cmd and cmd in show_supported_cmds:539 show_supported_cmds[cmd]()540 global_cmd = cmd541 #return HttpResponseRedirect("/rex_commands/")542 return HttpResponseRedirect("/rex_prompt/")543def rex_prompt(request):544 global global_cmd545 return render(request, 'LigerUI/ACIS/rex_debug/prompt.htm', {'cmd' : global_cmd})546def rex_test_query(request):547 from ..vcore import Query548 #q = Query('integration_query_exactly', platform= 'SD55', fw_version="SWI9X28A_00.11.01.06", test_date="2019-02-03")549 # q = Query('integration_query_exactly', platform= 'SD55', fw_version="SWI9X28A_00.11.01.06", test_date="2019-01-03")550 # q = Query('night_regression_query', platform= 'SD55', test_date="2019-01-03")551 # q = Query('ERD_caselist_query', platform= 'SD55', ERD_ID="04.60.26")552 q = Query('casename_query', platform= 'SD55', casename = "test_case_03_alpha_02")553 q.do_query()...

Full Screen

Full Screen

test_deprecated.py

Source:test_deprecated.py Github

copy

Full Screen

1# Copyright (c) MONAI Consortium2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5# http://www.apache.org/licenses/LICENSE-2.06# Unless required by applicable law or agreed to in writing, software7# distributed under the License is distributed on an "AS IS" BASIS,8# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.9# See the License for the specific language governing permissions and10# limitations under the License.11import unittest12import warnings13from monai.utils import DeprecatedError, deprecated, deprecated_arg14class TestDeprecatedRC(unittest.TestCase):15 def setUp(self):16 self.test_version_rc = "0.6.0rc1"17 self.test_version = "0.6.0"18 self.next_version = "0.7.0"19 def test_warning(self):20 """Test deprecated decorator with `since` and `removed` set for an RC version"""21 @deprecated(since=self.test_version, removed=self.next_version, version_val=self.test_version_rc)22 def foo2():23 pass24 foo2() # should not raise any warnings25 def test_warning_milestone(self):26 """Test deprecated decorator with `since` and `removed` set for a milestone version"""27 @deprecated(since=self.test_version, removed=self.next_version, version_val=self.test_version)28 def foo2():29 pass30 self.assertWarns(DeprecationWarning, foo2)31 def test_warning_last(self):32 """Test deprecated decorator with `since` and `removed` set, for the last version"""33 @deprecated(since=self.test_version, removed=self.next_version, version_val=self.next_version)34 def foo3():35 pass36 self.assertRaises(DeprecatedError, foo3)37 def test_warning_beyond(self):38 """Test deprecated decorator with `since` and `removed` set, beyond the last version"""39 @deprecated(since=self.test_version_rc, removed=self.test_version, version_val=self.next_version)40 def foo3():41 pass42 self.assertRaises(DeprecatedError, foo3)43class TestDeprecated(unittest.TestCase):44 def setUp(self):45 self.test_version = "0.5.3+96.g1fa03c2.dirty"46 self.prev_version = "0.4.3+96.g1fa03c2.dirty"47 self.next_version = "0.6.3+96.g1fa03c2.dirty"48 def test_warning1(self):49 """Test deprecated decorator with just `since` set."""50 @deprecated(since=self.prev_version, version_val=self.test_version)51 def foo1():52 pass53 self.assertWarns(DeprecationWarning, foo1)54 def test_warning2(self):55 """Test deprecated decorator with `since` and `removed` set."""56 @deprecated(since=self.prev_version, removed=self.next_version, version_val=self.test_version)57 def foo2():58 pass59 self.assertWarns(DeprecationWarning, foo2)60 def test_except1(self):61 """Test deprecated decorator raises exception with no versions set."""62 @deprecated(version_val=self.test_version)63 def foo3():64 pass65 self.assertRaises(DeprecatedError, foo3)66 def test_except2(self):67 """Test deprecated decorator raises exception with `removed` set in the past."""68 @deprecated(removed=self.prev_version, version_val=self.test_version)69 def foo4():70 pass71 self.assertRaises(DeprecatedError, foo4)72 def test_class_warning1(self):73 """Test deprecated decorator with just `since` set."""74 @deprecated(since=self.prev_version, version_val=self.test_version)75 class Foo1:76 pass77 self.assertWarns(DeprecationWarning, Foo1)78 def test_class_warning2(self):79 """Test deprecated decorator with `since` and `removed` set."""80 @deprecated(since=self.prev_version, removed=self.next_version, version_val=self.test_version)81 class Foo2:82 pass83 self.assertWarns(DeprecationWarning, Foo2)84 def test_class_except1(self):85 """Test deprecated decorator raises exception with no versions set."""86 @deprecated(version_val=self.test_version)87 class Foo3:88 pass89 self.assertRaises(DeprecatedError, Foo3)90 def test_class_except2(self):91 """Test deprecated decorator raises exception with `removed` set in the past."""92 @deprecated(removed=self.prev_version, version_val=self.test_version)93 class Foo4:94 pass95 self.assertRaises(DeprecatedError, Foo4)96 def test_meth_warning1(self):97 """Test deprecated decorator with just `since` set."""98 class Foo5:99 @deprecated(since=self.prev_version, version_val=self.test_version)100 def meth1(self):101 pass102 self.assertWarns(DeprecationWarning, lambda: Foo5().meth1())103 def test_meth_except1(self):104 """Test deprecated decorator with just `since` set."""105 class Foo6:106 @deprecated(version_val=self.test_version)107 def meth1(self):108 pass109 self.assertRaises(DeprecatedError, lambda: Foo6().meth1())110 def test_arg_warn1(self):111 """Test deprecated_arg decorator with just `since` set."""112 @deprecated_arg("b", since=self.prev_version, version_val=self.test_version)113 def afoo1(a, b=None):114 pass115 afoo1(1) # ok when no b provided116 self.assertWarns(DeprecationWarning, lambda: afoo1(1, 2))117 def test_arg_warn2(self):118 """Test deprecated_arg decorator with just `since` set."""119 @deprecated_arg("b", since=self.prev_version, version_val=self.test_version)120 def afoo2(a, **kw):121 pass122 afoo2(1) # ok when no b provided123 self.assertWarns(DeprecationWarning, lambda: afoo2(1, b=2))124 def test_arg_except1(self):125 """Test deprecated_arg decorator raises exception with no versions set."""126 @deprecated_arg("b", version_val=self.test_version)127 def afoo3(a, b=None):128 pass129 self.assertRaises(DeprecatedError, lambda: afoo3(1, b=2))130 def test_arg_except2(self):131 """Test deprecated_arg decorator raises exception with `removed` set in the past."""132 @deprecated_arg("b", removed=self.prev_version, version_val=self.test_version)133 def afoo4(a, b=None):134 pass135 self.assertRaises(DeprecatedError, lambda: afoo4(1, b=2))136 def test_2arg_warn1(self):137 """Test deprecated_arg decorator applied twice with just `since` set."""138 @deprecated_arg("b", since=self.prev_version, version_val=self.test_version)139 @deprecated_arg("c", since=self.prev_version, version_val=self.test_version)140 def afoo5(a, b=None, c=None):141 pass142 afoo5(1) # ok when no b or c provided143 self.assertWarns(DeprecationWarning, lambda: afoo5(1, 2))144 self.assertWarns(DeprecationWarning, lambda: afoo5(1, 2, 3))145 def test_future(self):146 """Test deprecated decorator with `since` set to a future version."""147 @deprecated(since=self.next_version, version_val=self.test_version)148 def future1():149 pass150 with self.assertWarns(DeprecationWarning) as aw:151 future1()152 warnings.warn("fake warning", DeprecationWarning)153 self.assertEqual(aw.warning.args[0], "fake warning")154 def test_arg_except2_unknown(self):155 """156 Test deprecated_arg decorator raises exception with `removed` set in the past.157 with unknown version158 """159 @deprecated_arg("b", removed=self.prev_version, version_val="0+untagged.1.g3131155")160 def afoo4(a, b=None):161 pass162 self.assertRaises(DeprecatedError, lambda: afoo4(1, b=2))163 def test_arg_except3_unknown(self):164 """165 Test deprecated_arg decorator raises exception with `removed` set in the past.166 with unknown version and kwargs167 """168 @deprecated_arg("b", removed=self.prev_version, version_val="0+untagged.1.g3131155")169 def afoo4(a, b=None, **kwargs):170 pass171 self.assertRaises(DeprecatedError, lambda: afoo4(1, b=2))172 self.assertRaises(DeprecatedError, lambda: afoo4(1, b=2, c=3))173 def test_replacement_arg(self):174 """175 Test deprecated arg being replaced.176 """177 @deprecated_arg("b", new_name="a", since=self.prev_version, version_val=self.test_version)178 def afoo4(a, b=None):179 return a180 self.assertEqual(afoo4(b=2), 2)181 self.assertEqual(afoo4(1, b=2), 1) # new name is in use182 self.assertEqual(afoo4(a=1, b=2), 1) # prefers the new arg183 def test_replacement_arg1(self):184 """185 Test deprecated arg being replaced with kwargs.186 """187 @deprecated_arg("b", new_name="a", since=self.prev_version, version_val=self.test_version)188 def afoo4(a, *args, **kwargs):189 return a190 self.assertEqual(afoo4(b=2), 2)191 self.assertEqual(afoo4(1, b=2, c=3), 1) # new name is in use192 self.assertEqual(afoo4(a=1, b=2, c=3), 1) # prefers the new arg193 def test_replacement_arg2(self):194 """195 Test deprecated arg (with a default value) being replaced.196 """197 @deprecated_arg("b", new_name="a", since=self.prev_version, version_val=self.test_version)198 def afoo4(a, b=None, **kwargs):199 return a, kwargs200 self.assertEqual(afoo4(b=2, c=3), (2, {"c": 3}))201 self.assertEqual(afoo4(1, b=2, c=3), (1, {"c": 3})) # new name is in use202 self.assertEqual(afoo4(a=1, b=2, c=3), (1, {"c": 3})) # prefers the new arg203 self.assertEqual(afoo4(1, 2, c=3), (1, {"c": 3})) # prefers the new positional arg204if __name__ == "__main__":...

Full Screen

Full Screen

test_viewsets.py

Source:test_viewsets.py Github

copy

Full Screen

1from django.urls import reverse2from django_webtest import WebTest3from vng.design_rules.choices import DesignRuleChoices4from vng.utils.factories import UserFactory5from vng.api_authentication.tests.factories import CustomTokenFactory6from vng.design_rules.choices import DesignRuleChoices7from vng.design_rules.tests.factories import DesignRuleSessionFactory, DesignRuleTestOptionFactory, DesignRuleTestSuiteFactory, DesignRuleTestVersionFactory, DesignRuleResultFactory8class DesignRuleTestSuiteViewSetTests(WebTest):9 def test_view_is_protected(self):10 test_suite = DesignRuleTestSuiteFactory()11 url = reverse("api_v1_design_rules:test_suite-start-session", kwargs={"uuid": test_suite.uuid})12 self.app.post(url, status=401)13 def test_start_session(self):14 test_version = DesignRuleTestVersionFactory()15 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_03_20200709)16 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_09_20200117)17 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_16_20200709)18 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_20_20200709)19 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_48_20200709)20 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_51_20200709)21 token = CustomTokenFactory()22 test_suite = DesignRuleTestSuiteFactory()23 url = reverse("api_v1_design_rules:test_suite-start-session", kwargs={"uuid": test_suite.uuid})24 extra_environ = {25 'HTTP_AUTHORIZATION': 'Token {}'.format(token.key),26 }27 response = self.app.post(url, params={"test_version": test_version.id}, extra_environ=extra_environ)28 self.assertEqual(response.status_code, 201)29 def test_start_session_design_rule_test_version_does_not_exist(self):30 token = CustomTokenFactory()31 test_suite = DesignRuleTestSuiteFactory()32 url = reverse("api_v1_design_rules:test_suite-start-session", kwargs={"uuid": test_suite.uuid})33 extra_environ = {34 'HTTP_AUTHORIZATION': 'Token {}'.format(token.key),35 }36 response = self.app.post(url, params={"test_version": 1}, extra_environ=extra_environ, status=400)37 self.assertEqual(response.status_code, 400)38 self.assertEqual(response.json, {"test_version": ['Invalid pk "1" - object does not exist.']})39 def test_start_session_test_version_not_active(self):40 test_version = DesignRuleTestVersionFactory(is_active=False)41 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_03_20200709)42 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_09_20200117)43 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_16_20200709)44 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_20_20200709)45 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_48_20200709)46 DesignRuleTestOptionFactory(test_version=test_version, rule_type=DesignRuleChoices.api_51_20200709)47 token = CustomTokenFactory()48 test_suite = DesignRuleTestSuiteFactory()49 url = reverse("api_v1_design_rules:test_suite-start-session", kwargs={"uuid": test_suite.uuid})50 extra_environ = {51 'HTTP_AUTHORIZATION': 'Token {}'.format(token.key),52 }53 response = self.app.post(url, params={"test_version": test_version.id}, extra_environ=extra_environ, status=400)54 self.assertEqual(response.status_code, 400)55 self.assertEqual(response.json, {"test_version": ['The test version "{}" is inactive.'.format(str(test_version))]})56class DesignRuleSessionViewSetTests(WebTest):57 def test_shield(self):58 session = DesignRuleSessionFactory()59 url = reverse("api_v1_design_rules:design_rule-shield", kwargs={"uuid": session.uuid})60 self.app.get(url)61 def test_shield_100(self):62 session = DesignRuleSessionFactory(percentage_score=100)63 url = reverse("api_v1_design_rules:design_rule-shield", kwargs={"uuid": session.uuid})64 response = self.app.get(url)65 def test_retreive_session(self):66 token = CustomTokenFactory()67 session = DesignRuleSessionFactory(percentage_score=100)68 DesignRuleResultFactory(success=True, design_rule=session, rule_type=DesignRuleChoices.api_03_20200709)69 extra_environ = {70 'HTTP_AUTHORIZATION': 'Token {}'.format(token.key),71 }72 url = reverse("api_v1_design_rules:session-detail", kwargs={"uuid": session.uuid})73 response = self.app.get(url, extra_environ=extra_environ)74 self.assertEqual(response.json['results'], [{75 'errors': '', 'rule_type': 'api_03', 'success': True,76 "url": "https://docs.geostandaarden.nl/api/API-Designrules/#api-03-only-apply-default-http-operations",77 "description": "A RESTful API is an application programming interface that supports the default HTTP operations GET, PUT, POST, PATCH and DELETE."...

Full Screen

Full Screen

test_s3.py

Source:test_s3.py Github

copy

Full Screen

1import json2from unittest import TestCase3from uuid import uuid44import os5from boto3 import Session6from api import api7from api.config import TestingConfig8sess = Session(9 region_name='eu-west-2',10 aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'),11 aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY')12)13MODEL_BUCKET_NAME = TestingConfig().TWC_BUCKET_NAME14from api.utils.aws import get_models, save_model, MODEL_ROOT_NAME, \15 OverwriteFailure, get_status, set_model, ModelNotFound, STATUS_FILE_NAME, get_current_model, NoModelsFound16test_version = 120591825029317class TestS3Client(TestCase):18 delete = {'Objects': [19 {'Key': MODEL_ROOT_NAME + str(test_version)},20 {'Key': MODEL_ROOT_NAME + str(test_version+1)},21 {'Key': STATUS_FILE_NAME}22 ]}23 def setUp(self):24 api.app.config.from_object('api.config.TestingConfig')25 self.app = api.app.test_client()26 self.s3 = sess.resource('s3')27 bucket = self.s3.Bucket(MODEL_BUCKET_NAME)28 try:29 bucket.delete_objects(Delete=self.delete)30 bucket.delete()31 except:32 pass33 try:34 self.s3.Bucket(MODEL_BUCKET_NAME).create(CreateBucketConfiguration={'LocationConstraint': 'eu-west-2'})35 except:36 pass37 def tearDown(self):38 bucket = self.s3.Bucket(MODEL_BUCKET_NAME)39 bucket.delete_objects(Delete=self.delete)40 self.s3.Bucket(MODEL_BUCKET_NAME).delete()41 def test_get_models(self):42 with api.app.app_context():43 models = get_models()44 print(models)45 def test_save_models(self):46 with api.app.app_context():47 save_model('Hello', test_version)48 models = get_models()49 self.assertTrue(test_version in models)50 def test_overwrite_model(self):51 with api.app.app_context():52 save_model('Hello', test_version)53 with self.assertRaises(OverwriteFailure):54 save_model('Hello', test_version)55 def test_get_status(self):56 with api.app.app_context():57 get_status()58 def test_set_status(self):59 with api.app.app_context():60 with self.assertRaises(ModelNotFound):61 set_model(test_version)62 save_model('Hello', test_version)63 set_model(test_version)64 self.assertEqual(get_status()[-1]['current_version'], test_version)65 def test_get_current_model(self):66 with api.app.app_context():67 with self.assertRaises(NoModelsFound):68 get_current_model()69 save_model('Hello', test_version)70 save_model('Hello')71 # no status set yet, should get latest model72 self.assertEqual(get_current_model(), MODEL_ROOT_NAME + str(test_version+1))73 set_model(test_version)74 # status now set to previous, should get that model75 self.assertEqual(get_current_model(), MODEL_ROOT_NAME + str(test_version))76 def test_api_set_status(self):77 with api.app.app_context():78 save_model('hi', version=test_version)79 save_model('hi')80 self.assertEqual(get_current_model(), MODEL_ROOT_NAME + str(test_version + 1))81 self.app.put('/status', headers={'content-type': 'application/json'},82 data=json.dumps({'version': test_version}))83 with api.app.app_context():84 self.assertEqual(get_current_model(), MODEL_ROOT_NAME + str(test_version))85 def test_get_models(self):86 with api.app.app_context():87 save_model('hi', version=test_version)88 save_model('hi')89 response = self.app.get('/models')90 self.assertEqual(len(json.loads(response.data.decode('utf-8'))), 2)91 def test_get_status(self):92 with api.app.app_context():93 save_model('hi', version=test_version)94 save_model('hi')95 set_model(test_version+1)96 set_model(test_version)97 response = self.app.get('/status')98 data = json.loads(response.data.decode('utf-8'))99 self.assertEqual(len(data), 2)...

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 Molotov 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