a EgH@sddlZddlmmZddlZddlmZddlm Z ddl Z ddl Z ddl Z ddl mZejddZddZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Z d'd(Z!d)d*Z"d+d,Z#dS)-N)app)Config) HTTPBasicAuthcCsdtjd<tS)NTZTESTING)rconfigZ test_clientrr9/home/cmiss/Jenkins/workspace/SPARC-API/tests/test_api.pyclient s rc Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz0217/files/derivative/brainstem_pig_metadata.json /s3-resource/'?s3BucketName=prd-sparc-discover50-use1==z3%(py2)s {%(py2)s = %(py0)s.status_code } == %(py5)srpy0py2py5assert %(py7)spy7smedullainz,%(py1)s in %(py5)s {%(py5)s = %(py3)s.data }py1py3r get status_code @pytest_ar_call_reprcompare @py_builtinslocals_should_repr_global_name _safereprAssertionError_format_explanationdata rZ small_s3_filer @py_assert1 @py_assert4 @py_assert3 @py_format6 @py_format8 @py_assert0 @py_assert2rrr#test_direct_download_url_small_filesr0c Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz3307%2Ffiles%2Fderivative%2Fhuman_body_metadata.jsonr r r r rrrrrscolonrrrr) rZ new_s3_filerr)r*r+r,r-r.r/rrr(test_direct_download_url_new_bucket_filesr1c Cs0d}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}d }|j }||v} | s td | fd ||ft|dtvst|rt|ndt|d}d d |i}tt |d}} }dS)Nz795/files/derivative%2FcolonHuman_Layout1_thumbnail.jpegr r r r rrrrrsrrrrr(rrr"test_direct_download_url_thumbnail!sr2cCsd}|d|d}|j}d}||k}|std|fd||fdtvsVt|r`t|ndt|t|d}d d |i}tt |d}}}dS) Nz95/files/?encodeBase64=truer r r )!=)z3%(py2)s {%(py2)s = %(py0)s.status_code } != %(py5)srrrr rrrr r!r"r#r$r%r&)rZincorrect_pathrr)r*r+r,r-rrr#test_direct_download_incorrect_path(sr5cCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nr r rrrrrr4rrr)r*r+r,r-rrrtest_direct_download_empty_path.s r8c Csfd}|d|}|j}d}||k}|std|fd||fdtvsTt|r^t|ndt|t|d}dd |i}tt |d}}}d }|j }|} | j } | } || v} | sJtd | fd || ft|dtvst|rt|ndt|t| t| t| d } dd| i}tt |d}} }} } } dS)NzW61%2Ffiles%2Fprimary%2Fsub-44%2Fsam-1%2Fmicroscopy%2Fsub-44sam-1C44-1Slide2p2MT_10x.nd2r ir rrrrrzFile too big to downloadr)z|%(py1)s in %(py11)s {%(py11)s = %(py9)s {%(py9)s = %(py7)s {%(py7)s = %(py5)s {%(py5)s = %(py3)s.get_data }() }.decode }() })rrrrpy9Zpy11zassert %(py13)sZpy13) rrrr r!r"r#r$r%r&get_datadecode)rZ large_s3_filerr)r*r+r,r-r. @py_assert6Z @py_assert8Z @py_assert10r/Z @py_format12Z @py_format14rrr#test_direct_download_url_large_file4sr=c Csd}d}|d|}|j}d}||k}|std|fd||fdtvsXt|rbt|ndt|t|d}d d |i}tt |d}}}| d } | |k} | std| fd | |ft| d tvst|rt|nd d} dd| i}tt |d} } |dd}|j}d}||k}|std|fd||fdtvszt|rt|ndt|t|d}d d |i}tt |d}}}dS)Niznih-data-portal@blackfynn.comz/get_owner_email/r r rrrrremail)z%(py1)s == %(py3)sportal_user_emailrrassert %(py5)sr?Br6 rrrr r!r"r#r$r%r&get_json) rZportal_user_idr?rr)r*r+r,r-r.r/ @py_format4rrrtest_get_owner_email<srFcCs>d}|dd}|j}d}||k}|std|fd||fdtvsTt|r^t|ndt|t|d}d d |i}tt |d}}}|d|}|j}d }||k}|s.td|fd||fdtvst|rt|ndt|t|d}d d |i}tt |d}}}dS) NZ OT2OD025340z /project/rBr6r rrrrrr r4)rZportal_project_idrr)r*r+r,r-rrrtest_get_datasets_by_projectIs rGcCs0ddddi}|jdid}|j}d}||k}|std|fd ||fd tvs\t|rft|nd t|t|d }d d |i}tt |d}}}|jd|d}|j}d}||k}|s6td|fd ||fd tvst|rt|nd t|t|d }d d |i}tt |d}}}d}|j }|} || v} | std| fd|| ft|d tvst|rt|nd t|t| d}dd|i} tt | d}} }} |jd| d}|j}d}||k}|sztd|fd ||fd tvsHere is a small text but not lorem ipsumr2)rcrdr r3task_idz%https://www.wrike.com/api/v4/tasks/{}Z AuthorizationzBearer )urlheadersresp)r[rrr r!r"r#r$r%r&rDformatrZ WRIKE_TOKENrequestsdelete)rrr)r*r+r,r-rerfrSrgrhZhedrjrrrtest_create_wrike_tasks rncsP|jdid}|j}d}||k}|std|fd||fdtvsNt|rXt|ndt|t|d}dd |i}tt |d}}}t j d fd d t d D}d fdd t dD}d||} |jd| dddd} | j}d}||k}|s|td|fd||fdtvs>t| rHt| ndt|t|d}dd |i}tt |d}}}| } | d} d| } tdtj}tj| |d}|j}d}||k}|s@td|fd||fdtvst|r t|ndt|t|d}dd |i}tt |d}}}dS)Nz/mailchimp_subscriberKrMr rrrrrc3s|]}tVqdSNrandomchoice.0ilettersrr z.test_subscribe_to_mailchimp..c3s|]}tVqdSrprqrtrwrrryrzz {}@{}.comTestZUser) email_addressZ first_name last_namer reidzVhttps://us2.api.mailchimp.com/3.0/lists/c81a347bd8/members/{}/actions/delete-permanentZAnyUser)rhauthrj)r[rrr r!r"r#r$r%r&stringascii_lowercasejoinrangerkrDrrZMAILCHIMP_API_KEYrl)rrr)r*r+r,r-r>domainr~rerSZ member_hashrhrrjrrwrtest_subscribe_to_mailchimps"   rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| }d }||v} | std | fd ||ft|d tvst|rt|nd d } dd| i}tt |d}} dS)Nz/get_osparc_datar r rrrrrZ file_viewersrrR osparc_datar@rArrC) rrr)r*r+r,r-rr.r/rErrrtest_osparc_viewerss rcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nz/sim/dataset/0r6r rrrrrr4r7rrrtest_sim_datasets rc Cs|jdddid}|j}d}||k}|std|fd||fdtvsRt|r\t|ndt|t|d }d d |i}tt |d}}}| }|d }d }||k} | std| fd||ft|t|d} dd| i} tt | d}} }dS)Nz/onto_term_lookuptermz-http://purl.obolibrary.org/obo/NCBITaxon_9606)Z query_stringr r rrrrrlabelZHumanrTrUrWrXrC) rrr)r*r+r,r-Z json_datar.r/r]r^rrrtest_onto_term_lookupsrcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}dS) Nz/simulation_ui_file/137r6r rrrrrr4r7rrr$test_non_existing_simulation_ui_files rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| d d d d }d }||k}|std|fd||ft|t|d} dd| i} tt | d}}}dS)Nz/simulation_ui_file/135r r rrrrr simulationsolversrnamezsimcore/services/comp/opencorrTrUrWrXrC rrr)r*r+r,r-r.r/r]r^rrr%test_simulation_ui_file_old_s3_buckets rc Cs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| d d d d }d }||k}|std|fd||ft|t|d} dd| i} tt | d}}}dS)Nz/simulation_ui_file/308r r rrrrrrrrrz*simcore/services/comp/kember-cardiac-modelrTrUrWrXrCrrrr%test_simulation_ui_file_new_s3_buckets rcCs|d}|j}d}||k}|std|fd||fdtvsJt|rTt|ndt|t|d}dd|i}tt |d}}}| }d }||v} | std | fd ||ft|d tvst|rt|nd d } dd| i}tt |d}} |d }t |}|t k} | std| fd|t fdtvsbtt rltt ndt|t|dtvstt rtt ndd} dd| i} tt | d}}} dS)Nz"/get_featured_datasets_identifiersr r rrrrrZ identifiersrrRrLr@rAr)z0%(py4)s {%(py4)s = %(py0)s(%(py2)s) } == %(py6)srIlist)rrrVrXzassert %(py8)sZpy8) rrrr r!r"r#r$r%r&rDrIr)rrr)r*r+r,r-rLr.r/rEZ @py_assert5r^Z @py_format9rrrtest_get_featured_datasetss  zr)$builtinsr!_pytest.assertion.rewrite assertionrewriterpytestrZ app.configrrlrrrZ requests.authrfixturerr0r1r2r5r8r=rFrGr_rbrnrrrrrrrrrrrrs6"