How to use get_access_token method in tempest

Best Python code snippet using tempest_python

fa.py

Source:fa.py Github

copy

Full Screen

...21print(f'------ Start of {script} -------')22print(f'ENVIRONMENT: {env}')23print('------ Create FS 1 -------')24fs_ocid_1 = create_fs(25 token=get_access_token(host),26 host=host,27 x_operation_id=get_x_operation_id(get_access_token(host), host),28 ocid=create_ei(29 token=get_access_token(host),30 host=host,31 x_operation_id=get_x_operation_id(get_access_token(host), host),32 payload=ei,33 idno='001'34 ),35 payload=fs)36print(f'OCID: {fs_ocid_1}')37print('------ Create FS 2 -------')38fs_ocid_2 = create_fs(39 token=get_access_token(host),40 host=host,41 x_operation_id=get_x_operation_id(get_access_token(host), host),42 ocid=create_ei(43 token=get_access_token(host),44 host=host,45 x_operation_id=get_x_operation_id(get_access_token(host), host),46 payload=ei,47 idno='001'48 ),49 payload=fs)50print(f'OCID: {fs_ocid_2}')51print('------ Create FS 3 -------')52fs_ocid_3 = create_fs(53 token=get_access_token(host),54 host=host,55 x_operation_id=get_x_operation_id(get_access_token(host), host),56 ocid=create_ei(57 token=get_access_token(host),58 host=host,59 x_operation_id=get_x_operation_id(get_access_token(host), host),60 payload=ei,61 idno='002'62 ),63 payload=fs)64print(f'OCID: {fs_ocid_3}')65print(f'------ Create PN with pmd {pn_pmd_1} -------')66pn_1 = create_pn(host=host,67 pmd=pn_pmd_1,68 token=get_access_token(host),69 fs_ocid=fs_ocid_1,70 x_operation_id=get_x_operation_id(get_access_token(host), host),71 payload=pn_fa)72print(f'CPID: {pn_1[0]}'73 f' OCID: {pn_1[1]}'74 f' X-TOKEN: {pn_1[2]}')75print(f'------ Create PN with pmd {pn_pmd_2} -------')76pn_2 = create_pn(host=host,77 pmd=pn_pmd_2,78 token=get_access_token(host),79 fs_ocid=fs_ocid_2,80 x_operation_id=get_x_operation_id(get_access_token(host), host),81 payload=pn_fa)82print(f'CPID: {pn_2[0]}'83 f' OCID: {pn_2[1]}'84 f' X-TOKEN: {pn_2[2]}')85print(f'------ Create PN with pmd {pn_pmd_3} -------')86pn_3 = create_pn(host=host,87 pmd=pn_pmd_3,88 token=get_access_token(host),89 fs_ocid=fs_ocid_3,90 x_operation_id=get_x_operation_id(get_access_token(host), host),91 payload=pn_fa)92print(f'CPID: {pn_3[0]}'93 f' OCID: {pn_3[1]}'94 f' X-TOKEN: {pn_3[2]}')95print('------ Create AP -------')96ap = create_ap(host=host,97 token=get_access_token(host),98 x_operation_id=get_x_operation_id(get_access_token(host), host),99 payload=ap,100 pmd=ap_pmd)101print(f'CPID: {ap[0]}'102 f' OCID: {ap[1]}'103 f' X-TOKEN: {ap[2]}')104print(f'------ Do outsourcing PN with {pn_pmd_1} -------')105do_outsourcing_pn_1 = do_outsourcing_pn(host=host,106 token=get_access_token(host),107 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),108 pn_cpid=pn_1[0],109 pn_ocid=pn_1[1],110 pn_x_token=pn_1[2],111 ap_cpid=ap[0],112 ap_ocid=ap[1])113print(do_outsourcing_pn)114print(f'------ Do outsourcing PN with {pn_pmd_2} -------')115do_outsourcing_pn_2 = do_outsourcing_pn(host=host,116 token=get_access_token(host),117 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),118 pn_cpid=pn_2[0],119 pn_ocid=pn_2[1],120 pn_x_token=pn_2[2],121 ap_cpid=ap[0],122 ap_ocid=ap[1])123print(do_outsourcing_pn_2)124print(f'------ Do outsourcing PN with {pn_pmd_3} -------')125do_outsourcing_pn_3 = do_outsourcing_pn(host=host,126 token=get_access_token(host),127 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),128 pn_cpid=pn_3[0],129 pn_ocid=pn_3[1],130 pn_x_token=pn_3[2],131 ap_cpid=ap[0],132 ap_ocid=ap[1])133print(do_outsourcing_pn_3)134print(f'------ Do relation AP with pmd: {pn_pmd_1} -------')135do_relation_ap_pn_1 = do_relation_ap(host=host,136 token=get_access_token(host),137 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),138 pn_cpid=pn_1[0],139 pn_ocid=pn_1[1],140 ap_x_token=ap[2],141 ap_cpid=ap[0],142 ap_ocid=ap[1])143print(do_relation_ap_pn_1)144print(f'------ Do relation AP with pmd: {pn_pmd_2} -------')145do_relation_ap_pn_2 = do_relation_ap(host=host,146 token=get_access_token(host),147 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),148 pn_cpid=pn_2[0],149 pn_ocid=pn_2[1],150 ap_x_token=ap[2],151 ap_cpid=ap[0],152 ap_ocid=ap[1])153print(do_relation_ap_pn_2)154print(f'------ Do relation AP with pmd: {pn_pmd_3} -------')155do_relation_ap_pn_3 = do_relation_ap(host=host,156 token=get_access_token(host),157 x_operation_id=get_x_operation_id(token=get_access_token(host), host=host),158 pn_cpid=pn_3[0],159 pn_ocid=pn_3[1],160 ap_x_token=ap[2],161 ap_cpid=ap[0],162 ap_ocid=ap[1])163print(do_relation_ap_pn_3)164print('------ Update AP -------')165update_ap_after_relation = update_ap(166 host=host,167 token=get_access_token(host),168 x_operation_id=get_x_operation_id(get_access_token(host), host),169 ap_cpid=ap[0],170 ap_ocid=ap[1],171 ap_x_token=ap[2],172 payload=up_ap173)174print(update_ap_after_relation)175print('------ Create FE -------')176fe = create_fe(177 host=host,178 token=get_access_token(host),179 x_operation_id=get_x_operation_id(get_access_token(host), host),180 ap_cpid=ap[0],181 ap_ocid=ap[1],182 ap_x_token=ap[2],183 payload=fe_auction,184 auction=auc185)186print(f'OCID: {fe}')187time.sleep(2)188print('------ Create Submission 1 -------')189submission_1 = create_submission(190 host=host,191 token=get_access_token(host),192 x_operation_id=get_x_operation_id(get_access_token(host), host),193 ap_cpid=ap[0],194 fe_ocid=fe,195 payload=sub_1196)197print(f'ID: {submission_1[0]}, X-TOKEN: {submission_1[1]}')198print('------ Create Submission 2 -------')199submission_2 = create_submission(200 host=host,201 token=get_access_token(host),202 x_operation_id=get_x_operation_id(get_access_token(host), host),203 ap_cpid=ap[0],204 fe_ocid=fe,205 payload=sub_2206)207print(f'ID: {submission_2[0]}, X-TOKEN: {submission_2[1]}')208print('------ Create Submission 3 -------')209submission_3 = create_submission(210 host=host,211 token=get_access_token(host),212 x_operation_id=get_x_operation_id(get_access_token(host), host),213 ap_cpid=ap[0],214 fe_ocid=fe,215 payload=sub_3216)217print(f'ID: {submission_3[0]}, X-TOKEN: {submission_3[1]}')218print('------ Create Submission 4 -------')219submission_4 = create_submission(220 host=host,221 token=get_access_token(host),222 x_operation_id=get_x_operation_id(get_access_token(host), host),223 ap_cpid=ap[0],224 fe_ocid=fe,225 payload=sub_4226)227print(f'ID: {submission_4[0]}, X-TOKEN: {submission_4[1]}')228time.sleep(20)229print('------ QUALIFICATIONS -------')230qualifications = get_qualifications_from_public_point(fe)231print(qualifications)232time.sleep(2)233print('------ DO CONSIDERATION AND QUALIFICATION 1 -------')234do_cons_1 = do_consideration_and_qualification(235 host=host,236 token=get_access_token(host),237 x_operation_id=get_x_operation_id(get_access_token(host), host),238 ap_cpid=ap[0],239 fe_ocid=fe,240 qualifications=qualifications,241 payload=active_qualification242)243print(do_cons_1)244time.sleep(2)245print('------ DO CONSIDERATION AND QUALIFICATION 2 -------')246do_cons_2 = do_consideration_and_qualification(247 host=host,248 token=get_access_token(host),249 x_operation_id=get_x_operation_id(get_access_token(host), host),250 ap_cpid=ap[0],251 fe_ocid=fe,252 qualifications=qualifications,253 payload=active_qualification254)255print(do_cons_2)256time.sleep(2)257print('------ DO CONSIDERATION AND QUALIFICATION 3 -------')258do_cons_3 = do_consideration_and_qualification(259 host=host,260 token=get_access_token(host),261 x_operation_id=get_x_operation_id(get_access_token(host), host),262 ap_cpid=ap[0],263 fe_ocid=fe,264 qualifications=qualifications,265 payload=active_qualification266)267print(do_cons_3)268time.sleep(2)269print('------ DO CONSIDERATION AND QUALIFICATION 4 -------')270do_cons_4 = do_consideration_and_qualification(271 host=host,272 token=get_access_token(host),273 x_operation_id=get_x_operation_id(get_access_token(host), host),274 ap_cpid=ap[0],275 fe_ocid=fe,276 qualifications=qualifications,277 payload=active_qualification278)279print(do_cons_4)280time.sleep(5)281print('------ DO QUALIFICATION PROTOCOL -------')282qualification_protocol = do_qualification_protocol(283 host=host,284 token=get_access_token(host),285 x_operation_id=get_x_operation_id(get_access_token(host), host),286 ap_cpid=ap[0],287 fe_ocid=fe,288 ap_x_token=ap[2]289)290print(f'CONTRACT ID: {qualification_protocol[0]}, CONTRACT TOKEN: {qualification_protocol[1]}')291print('------ COMPLETE QUALIFICATION -------')292complete_qualification = complete_qualification(293 host=host,294 token=get_access_token(host),295 x_operation_id=get_x_operation_id(get_access_token(host), host),296 ap_cpid=ap[0],297 fe_ocid=fe,298 ap_x_token=ap[2]299)300print(complete_qualification)301time.sleep(2)302print('------ ISSUING FC -------')303issuing_fc = issuing_fc(304 host=host,305 token=get_access_token(host),306 x_operation_id=get_x_operation_id(get_access_token(host), host),307 ap_cpid=ap[0],308 fe_ocid=fe,309 contract_id=qualification_protocol[0],310 ap_x_token=ap[2],311 payload=issuing312)313print(f'BUYER: REQUEST ID: {issuing_fc[0]}, REQUEST TOKEN: {issuing_fc[1]}')314time.sleep(2)315print('------ BUYER CONFIRMATION RESPONSE -------')316buyer_create_confirmation_response = create_confirmation_response(317 host=host,318 token=get_access_token(host),319 x_operation_id=get_x_operation_id(get_access_token(host), host),320 cpid=ap[0],321 ocid=fe,322 entity='contract',323 entity_id=qualification_protocol[0],324 response_id=issuing_fc[0],325 x_token=issuing_fc[1],326 role='buyer',327 payload=confirmation_response328)329print(f'BUYER CONFIRMATION REQUEST ID: {buyer_create_confirmation_response}')330time.sleep(1)331print('------ BUYER NEXT CONFIRMATION STEP -------')332buyer_next_confirmation_step = next_confirmation_step(333 host=host,334 token=get_access_token(host),335 x_operation_id=get_x_operation_id(get_access_token(host), host),336 cpid=ap[0],337 ocid=fe,338 entity='contract',339 entity_id=qualification_protocol[0],340 x_token=qualification_protocol[1],341 role='buyer',342)343buyer_next_confirmation_step = buyer_next_confirmation_step['data']['outcomes']['requests']344print(f'INVITED CANDIDATES REQUESTS: {buyer_next_confirmation_step}')345print('------ INVITED CANDIDATES CONFIRMATION RESPONSES -------')346num = 0347for i in buyer_next_confirmation_step:348 if num == 3:349 break350 else:351 create_confirmation_response(352 host=host,353 token=get_access_token(host),354 x_operation_id=get_x_operation_id(get_access_token(host), host),355 cpid=ap[0],356 ocid=fe,357 entity='contract',358 entity_id=qualification_protocol[0],359 response_id=i['id'],360 x_token=i['X-TOKEN'],361 role='invitedCandidate',362 payload=confirmation_response_invited_candidate363 )364 num = num + 1365 print(f'PARTICIPANT {num} --- DONE')366time.sleep(1)367print('------ INVITED CANDIDATES NEXT CONFIRMATION STEP -------')368inv_cand_next_confirmation_step = next_confirmation_step(369 host=host,370 token=get_access_token(host),371 x_operation_id=get_x_operation_id(get_access_token(host), host),372 cpid=ap[0],373 ocid=fe,374 entity='contract',375 entity_id=qualification_protocol[0],376 x_token=qualification_protocol[1],377 role='invitedCandidate',378)379time.sleep(1)380print('------ CREATE PCR ------')381pcr = create_pcr(382 host=host,383 token=get_access_token(host),384 x_operation_id=get_x_operation_id(get_access_token(host), host),385 x_token=ap[2],386 cpid=ap[0],387 ocid=fe,388 payload=pcr_full_no_catalogue_items_no_auction_no_criteria389)390print('------ CREATE BID IN PCR - 1 ------')391bid_1 = create_bid(392 host=host,393 token=get_access_token(host),394 x_operation_id=get_x_operation_id(get_access_token(host), host),395 cpid=ap[0],396 ocid=pcr[0],397 lot_id=pcr[1],398 item_id=pcr[2],399 payload=bid_1400)401print('------ CREATE BID IN PCR - 2 ------')402bid_2 = create_bid(403 host=host,404 token=get_access_token(host),405 x_operation_id=get_x_operation_id(get_access_token(host), host),406 cpid=ap[0],407 ocid=pcr[0],408 lot_id=pcr[1],409 item_id=pcr[2],410 payload=bid_2411)412print('------ CREATE BID IN PCR - 3 ------')413bid_3 = create_bid(414 host=host,415 token=get_access_token(host),416 x_operation_id=get_x_operation_id(get_access_token(host), host),417 cpid=ap[0],418 ocid=pcr[0],419 lot_id=pcr[1],420 item_id=pcr[2],421 payload=bid_3422)423print('------ CREATE BID IN PCR - 4 ------')424bid_4 = create_bid(425 host=host,426 token=get_access_token(host),427 x_operation_id=get_x_operation_id(get_access_token(host), host),428 cpid=ap[0],429 ocid=pcr[0],430 lot_id=pcr[1],431 item_id=pcr[2],432 payload=bid_4433)434print('------ AWARDS -------')435time.sleep(25)436awards = get_awards_for_pcr(pcr[0])437print('AWARD 1 :', awards[0])438print('AWARD 2 :', awards[1])439print('AWARD 3 :', awards[2])440print('AWARD 4 :', awards[3])441print('------ AWARD CONSIDERATION ------')442awards_consideration(443 host=host,444 token=get_access_token(host),445 cpid=ap[0],446 ocid=pcr[0],447 awards=awards448)449print('------- UPDATE AWARD ------')450update_award_pcr(451 host=host,452 token=get_access_token(host),453 cpid=ap[0],454 ocid=pcr[0],455 awards=awards,456 payload=update_award457)458print('------- EVALUATE AWARD ------')459evaluate_award_pcr(460 host=host,461 token=get_access_token(host),462 cpid=ap[0],463 ocid=pcr[0],464 awards=awards,465 payload=evaluate_award466)467print('------ PCR PROTOCOL ------')468contracts = pcr_protocol_do(469 host=host,470 x_operation_id=get_x_operation_id(get_access_token(host), host),471 token=get_access_token(host),472 cpid=ap[0],473 ocid=pcr[0],474 lot_id=pcr[1],475 x_token=pcr[3]476)477print('------ CONTRACTS ------')478print(contracts[0])479print(contracts[1])480print(contracts[2])481print(contracts[3])482print('------ GET REQUESTS ------')483requests = get_contract_response_id_x_token(484 ocid=pcr[0]485)486print(requests)487print('------ CREATE CONFIRMATION RESPONSE USER 1 ------')488create_confirmation_response(489 host=host,490 token=get_access_token(host),491 x_operation_id=get_x_operation_id(get_access_token(host), host),492 cpid=ap[0],493 ocid=pcr[0],494 entity='contract',495 entity_id=contracts[0]['id'],496 response_id=requests[0]['data']['outcomes']['requests'][0]['id'],497 x_token=requests[0]['data']['outcomes']['requests'][0]['X-TOKEN'],498 role='supplier',499 payload=confirmation_response_invited_candidate500 )501print('------ CREATE CONFIRMATION RESPONSE USER 2 ------')502create_confirmation_response(503 host=host,504 token=get_access_token(host),505 x_operation_id=get_x_operation_id(get_access_token(host), host),506 cpid=ap[0],507 ocid=pcr[0],508 entity='contract',509 entity_id=contracts[1]['id'],510 response_id=requests[1]['data']['outcomes']['requests'][0]['id'],511 x_token=requests[1]['data']['outcomes']['requests'][0]['X-TOKEN'],512 role='supplier',513 payload=confirmation_response_invited_candidate514 )515print('------ CREATE CONFIRMATION RESPONSE USER 3 ------')516create_confirmation_response(517 host=host,518 token=get_access_token(host),519 x_operation_id=get_x_operation_id(get_access_token(host), host),520 cpid=ap[0],521 ocid=pcr[0],522 entity='contract',523 entity_id=contracts[2]['id'],524 response_id=requests[2]['data']['outcomes']['requests'][0]['id'],525 x_token=requests[2]['data']['outcomes']['requests'][0]['X-TOKEN'],526 role='supplier',527 payload=confirmation_response_invited_candidate528 )529print('------ CREATE CONFIRMATION RESPONSE USER 4 ------')530create_confirmation_response(531 host=host,532 token=get_access_token(host),533 x_operation_id=get_x_operation_id(get_access_token(host), host),534 cpid=ap[0],535 ocid=pcr[0],536 entity='contract',537 entity_id=contracts[3]['id'],538 response_id=requests[3]['data']['outcomes']['requests'][0]['id'],539 x_token=requests[3]['data']['outcomes']['requests'][0]['X-TOKEN'],540 role='supplier',541 payload=confirmation_response_invited_candidate542 )543print('------ NEXT CONFIRMATION STEP -1 -------')544next_confirmation_step(545 host=host,546 token=get_access_token(host),547 x_operation_id=get_x_operation_id(get_access_token(host), host),548 cpid=ap[0],549 ocid=pcr[0],550 entity='contract',551 entity_id=contracts[0]['id'],552 x_token=contracts[0]['X-TOKEN'],553 role='supplier',554)555print('------ NEXT CONFIRMATION STEP -2 -------')556next_confirmation_step(557 host=host,558 token=get_access_token(host),559 x_operation_id=get_x_operation_id(get_access_token(host), host),560 cpid=ap[0],561 ocid=pcr[0],562 entity='contract',563 entity_id=contracts[1]['id'],564 x_token=contracts[1]['X-TOKEN'],565 role='supplier',566)567print('------ NEXT CONFIRMATION STEP -3 -------')568next_confirmation_step(569 host=host,570 token=get_access_token(host),571 x_operation_id=get_x_operation_id(get_access_token(host), host),572 cpid=ap[0],573 ocid=pcr[0],574 entity='contract',575 entity_id=contracts[2]['id'],576 x_token=contracts[2]['X-TOKEN'],577 role='supplier',578)579print('------ NEXT CONFIRMATION STEP -4 -------')580next_confirmation_step(581 host=host,582 token=get_access_token(host),583 x_operation_id=get_x_operation_id(get_access_token(host), host),584 cpid=ap[0],585 ocid=pcr[0],586 entity='contract',587 entity_id=contracts[3]['id'],588 x_token=contracts[3]['X-TOKEN'],589 role='supplier',590)591print('------ APPLY CONFIRMATION - 1 -------')592apply_confirmation(593 host=host,594 token=get_access_token(host),595 x_operation_id=get_x_operation_id(get_access_token(host), host),596 cpid=ap[0],597 ocid=pcr[0],598 entity='contract',599 entity_id=contracts[0]['id'],600 x_token=contracts[0]['X-TOKEN']601)602print('------ APPLY CONFIRMATION - 2 -------')603apply_confirmation(604 host=host,605 token=get_access_token(host),606 x_operation_id=get_x_operation_id(get_access_token(host), host),607 cpid=ap[0],608 ocid=pcr[0],609 entity='contract',610 entity_id=contracts[1]['id'],611 x_token=contracts[1]['X-TOKEN']612)613print('------ APPLY CONFIRMATION - 3 -------')614apply_confirmation(615 host=host,616 token=get_access_token(host),617 x_operation_id=get_x_operation_id(get_access_token(host), host),618 cpid=ap[0],619 ocid=pcr[0],620 entity='contract',621 entity_id=contracts[2]['id'],622 x_token=contracts[2]['X-TOKEN']623)624print('------ APPLY CONFIRMATION - 4 -------')625apply_confirmation(626 host=host,627 token=get_access_token(host),628 x_operation_id=get_x_operation_id(get_access_token(host), host),629 cpid=ap[0],630 ocid=pcr[0],631 entity='contract',632 entity_id=contracts[3]['id'],633 x_token=contracts[3]['X-TOKEN']634)635# print('------ CREATE RFQ -------')636# rfq = create_rfq(637# host=host,638# token=get_access_token(host),639# x_operation_id=get_x_operation_id(get_access_token(host), host),640# x_token=pn_1[2],641# ap_cpid=ap[0],642# cpid=pn_1[0],643# ocid=pn_1[1],644# pcr_ocid=pcr[0],645# payload=create_rfq_data,646# lot_id=pcr[1],647# item_id=pcr[2]648# )...

Full Screen

Full Screen

test_movies.py

Source:test_movies.py Github

copy

Full Screen

1import json2from datetime import date3from src.castingagency.api.models.movie import Movie4def test_add_movie(test_app, test_database, get_access_token):5 client = test_app.test_client()6 access_token = get_access_token['access_token']7 resp = client.post(8 "/movies",9 headers={"Authorization": f"Bearer {access_token}"},10 data=json.dumps(11 {"title": "He Got Game", "release_date": "1998-04-28"}),12 content_type="application/json",13 )14 data = json.loads(resp.data.decode())15 assert resp.status_code == 20116 assert True == data['success']17 assert "He Got Game was added!" == data["message"]18def test_add_movie_invalid_json(test_app, test_database, get_access_token):19 client = test_app.test_client()20 access_token = get_access_token['access_token']21 resp = client.post("/movies",22 headers={"Authorization": f"Bearer {access_token}"},23 data=json.dumps({}),24 content_type="application/json",)25 data = json.loads(resp.data.decode())26 assert resp.status_code == 42227 assert "unprocessable" == data["message"]28def test_get_single_movie(test_app, test_database, add_movie, get_access_token):29 movie = add_movie('Love and Basketball', date(1998, 4, 28))30 client = test_app.test_client()31 access_token = get_access_token['access_token']32 resp = client.get(f'/movies/{movie.id}',33 headers = {"Authorization": f"Bearer {access_token}"})34 data = json.loads(resp.data.decode())35 assert resp.status_code == 20036 assert len(data['movie']) == 337 assert 'Love and Basketball' == data['movie']['title']38 assert '1998-04-28' == data['movie']['release_date']39def test_get_all_movies(test_app, test_database, add_movie, get_access_token):40 test_database.session.query(Movie).delete()41 add_movie('He Got Game', date(1998, 4, 28))42 add_movie('He Got Game', date(1998, 4, 28))43 client = test_app.test_client()44 access_token = get_access_token['access_token']45 resp = client.get('/movies',46 headers={"Authorization": f"Bearer {access_token}"})47 data = json.loads(resp.data.decode())48 assert resp.status_code == 20049 assert len(data['movies']) == 250 assert 'He Got Game' == data['movies'][0]['title']51 assert "1998-04-28" == data['movies'][0]['release_date']52 assert 'He Got Game' == data['movies'][1]['title']53 assert "1998-04-28" == data['movies'][1]['release_date']54def test_remove_movie(test_app, test_database, add_movie, get_access_token):55 test_database.session.query(Movie).delete()56 movie = add_movie('He Got Game', date(1998, 4, 28))57 client = test_app.test_client()58 access_token = get_access_token['access_token']59 resp_one = client.get("/movies",60 headers={"Authorization": f"Bearer {access_token}"})61 data = json.loads(resp_one.data.decode())62 assert resp_one.status_code == 20063 assert len(data['movies']) == 164 resp_two = client.delete(f"/movies/{movie.id}",65 headers={"Authorization": f"Bearer {access_token}"})66 data = json.loads(resp_two.data.decode())67 assert resp_two.status_code == 20068 assert f'Movie id {movie.id}, {movie.title} was deleted!' in data["message"]69 resp_three = client.get("/movies",70 headers={"Authorization": f"Bearer {access_token}"})71 data = json.loads(resp_three.data.decode())72 assert resp_three.status_code == 20073 print(data)74 assert len(data['movies']) == 075def test_remove_actor_incorrect_id(test_app, test_database, get_access_token):76 client = test_app.test_client()77 access_token = get_access_token['access_token']78 resp = client.delete("/movies/999",79 headers={"Authorization": f"Bearer {access_token}"})80 data = json.loads(resp.data.decode())81 assert resp.status_code == 40482 assert "Movie 999 does not exist" in data["message"]83def test_update_movie(test_app, test_database, add_movie, get_access_token):84 movie = add_movie('He Got Game', date(1998, 4, 28))85 client = test_app.test_client()86 access_token = get_access_token['access_token']87 resp_one = client.patch(88 f"/movies/{movie.id}",89 headers={"Authorization": f"Bearer {access_token}"},90 data=json.dumps({"title": "jamaal"}),91 content_type="application/json",92 )93 data = json.loads(resp_one.data.decode())94 assert resp_one.status_code == 20095 assert f"{movie.id} was updated!" in data["message"]96 resp_two = client.get(f"/movies/{movie.id}",97 headers={"Authorization": f"Bearer {access_token}"})98 data = json.loads(resp_two.data.decode())99 assert resp_two.status_code == 200100 assert "jamaal" in data['movie']['title']101 assert "1998-04-28" == data['movie']['release_date']102def test_update_actor_incorrect_id(test_app, test_database, get_access_token):103 client = test_app.test_client()104 access_token = get_access_token['access_token']105 resp = client.patch("/movies/999",106 headers={"Authorization": f"Bearer {access_token}"})107 data = json.loads(resp.data.decode())108 assert resp.status_code == 404...

Full Screen

Full Screen

test_actors.py

Source:test_actors.py Github

copy

Full Screen

1import json2from src.castingagency.api.models.actor import Actor3def test_add_actor(test_app, test_database, get_access_token):4 client = test_app.test_client()5 access_token = get_access_token['access_token']6 resp = client.post(7 "/actors",8 headers={"Authorization": f"Bearer {access_token}"},9 data=json.dumps({"name": "jamaal", "age": 37, "gender": "M"}),10 content_type="application/json",11 )12 data = json.loads(resp.data.decode())13 assert resp.status_code == 20114 assert True == data['success']15 assert "jamaal was added!" == data["message"]16def test_add_user_invalid_json(test_app, test_database, get_access_token):17 client = test_app.test_client()18 access_token = get_access_token['access_token']19 resp = client.post("/actors",20 headers={"Authorization": f"Bearer {access_token}"},21 data=json.dumps({}),22 content_type="application/json",)23 data = json.loads(resp.data.decode())24 assert resp.status_code == 42225 assert "unprocessable" == data["message"]26def test_get_single_actors(test_app, test_database, add_actor, get_access_token):27 actor = add_actor('jaimen', 33, 'M')28 client = test_app.test_client()29 access_token = get_access_token['access_token']30 resp = client.get(f'/actors/{actor.id}',31 headers={"Authorization": f"Bearer {access_token}"})32 data = json.loads(resp.data.decode())33 assert resp.status_code == 20034 assert len(data['actor']) == 435 assert 'jaimen' == data['actor']['name']36 assert 33 == data['actor']['age']37 assert 'M' == data['actor']['gender']38def test_get_all_actors(test_app, test_database, add_actor, get_access_token):39 test_database.session.query(Actor).delete()40 add_actor('jamaal', 37, 'M')41 add_actor('heather', 37, 'F')42 client = test_app.test_client()43 access_token = get_access_token['access_token']44 resp = client.get('/actors',45 headers={"Authorization": f"Bearer {access_token}"})46 data = json.loads(resp.data.decode())47 assert resp.status_code == 20048 assert len(data['actors']) == 249 assert 'jamaal' == data['actors'][0]['name']50 assert 37 == data['actors'][0]['age']51 assert 'M' == data['actors'][0]['gender']52 assert 'heather' == data['actors'][1]['name']53 assert 37 == data['actors'][1]['age']54 assert 'F' == data['actors'][1]['gender']55def test_remove_actor(test_app, test_database, add_actor, get_access_token):56 test_database.session.query(Actor).delete()57 actor = add_actor("jaimen", 25, 'M')58 client = test_app.test_client()59 access_token = get_access_token['access_token']60 resp_one = client.get("/actors",61 headers={"Authorization": f"Bearer {access_token}"})62 data = json.loads(resp_one.data.decode())63 assert resp_one.status_code == 20064 assert len(data['actors']) == 165 resp_two = client.delete(f"/actors/{actor.id}",66 headers={"Authorization": f"Bearer {access_token}"})67 data = json.loads(resp_two.data.decode())68 assert resp_two.status_code == 20069 assert f'Actor id {actor.id}, {actor.name} was deleted!' in data["message"]70 resp_three = client.get("/actors",71 headers={"Authorization": f"Bearer {access_token}"})72 data = json.loads(resp_three.data.decode())73 assert resp_three.status_code == 20074 assert len(data['actors']) == 075def test_remove_actor_incorrect_id(test_app, test_database, get_access_token):76 client = test_app.test_client()77 access_token = get_access_token['access_token']78 resp = client.delete("/actors/999",79 headers={"Authorization": f"Bearer {access_token}"})80 data = json.loads(resp.data.decode())81 assert resp.status_code == 40482 assert "Actor 999 does not exist" in data["message"]83def test_update_actor(test_app, test_database, add_actor, get_access_token):84 actor = add_actor("jaimen", 25, 'M')85 access_token = get_access_token['access_token']86 client = test_app.test_client()87 print(actor.id)88 resp_one = client.patch(89 f"/actors/{actor.id}",90 headers={"Authorization": f"Bearer {access_token}"},91 data=json.dumps({"name": "jamaal"}),92 content_type="application/json",93 )94 data = json.loads(resp_one.data.decode())95 assert resp_one.status_code == 20096 assert f"{actor.id} was updated!" in data["message"]97 resp_two = client.get(f"/actors/{actor.id}",98 headers={"Authorization": f"Bearer {access_token}"})99 data = json.loads(resp_two.data.decode())100 assert resp_two.status_code == 200101 assert "jamaal" in data['actor']['name']102 assert "M" in data['actor']["gender"]103def test_update_actor_incorrect_id(test_app, test_database, get_access_token):104 client = test_app.test_client()105 access_token = get_access_token['access_token']106 resp = client.patch("/actors/999",107 headers={"Authorization": f"Bearer {access_token}"})108 data = json.loads(resp.data.decode())109 assert resp.status_code == 404...

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