a }|g5@sdZddlZddlZddlmZddlZddlmZddlmZ ddl m Z ddgZ gd ZGd d d ejZGd d d ejZedkreeejddegdS)z*Test :mod:`certbot._internal.display.obj`.N)mock)errors)obj)util)ZFirstZ Description1)ZSecondZ Description2)tag1tag2tag3csFeZdZdZfddZedddZddZd d Z d d Z d dZ edddZ ddZ ddZddZddZddZddZddZd d!Zed"d#d$Zed"d%d&Zed"d'd(Zed"d)d*Zd+d,Zd-d.Zd/d0Zed"d1d2Zd3d4Zd5d6Zd7d8Zd9d:Z d;d<Z!d=d>Z"Z#S)?FileOutputDisplayTestzTest stdout display. Most of this class has to deal with visual output. In order to test how the functions look to a user, uncomment the test_visual function. cs(tt|_t|jd|_dS)NF)supersetUpr MagicMock mock_stdout display_objZ FileDisplay displayerself __class__L/usr/lib/python3.9/site-packages/certbot/_internal/tests/display/obj_test.pyr s  zFileOutputDisplayTest.setUp$certbot._internal.display.obj.loggercCs2|jdd|jjjdd}|jdddS)NmessageFrNotifying user: %sr notificationr write call_argsdebugZassert_called_withr mock_loggerstringrrrtest_notification_no_pausesz0FileOutputDisplayTest.test_notification_no_pausecCsFd}tj|dd |jjdddWdn1s80YdS)N1certbot._internal.display.util.input_with_timeoutZenter return_valuerTZforce_interactive)rpatchrrrinput_with_timeoutrrrtest_notification_pause$s.z-FileOutputDisplayTest.test_notification_pausecCs&||jjd|jjjdd}dS)Nrr_force_noninteractiverrr rrrr rrr test_notification_noninteractive+sz6FileOutputDisplayTest.test_notification_noninteractivecCsH||jjd|jjjdd}||jjd|jjjdd}dS)Nrrmessage2r*r,rrr!test_notification_noninteractive20s z7FileOutputDisplayTest.test_notification_noninteractive2cCsVddlm}|jjdddd|jjjdd}|jjddd|jjjdd}dSNr)osrF)pauseZdecorater.)r2Zcertbot.compatr1rrr rrrr1r rrrtest_notification_decoration=s  z2FileOutputDisplayTest.test_notification_decorationz)r+rrDrr?rErHrrrtest_input_noninteractiveds  z/FileOutputDisplayTest.test_input_noninteractivecCsBtt$|j|jjdddWdn1s40YdS)Nr--flagZcli_flag)pytestraises Exceptionr+rrDrrrrtest_input_assertion_faills z/FileOutputDisplayTest.test_input_assertion_failc CsntdPttj$|j|jjdddWdn1sB0YWdn1s`0YdS)Nz&certbot.display.util.assert_valid_callr=rLrM) rr&rNrOrErrorr+rrDrrrrtest_input_assertion_fail2rs z0FileOutputDisplayTest.test_input_assertion_fail2cCs&d}tj|ddWdn1s(0Ytj|ddWdn1sV0Ytj|ddgdWdn1s0Ytj|ddWdn1s0Ytj|dd gdWdn1s0Ytj|d dWdn1s0YdS) Nr"ZYesr#ymaybe side_effectZNocancelnarr&r'rrr test_yesnowsz FileOutputDisplayTest.test_yesnocCsdSNrrrrrtest_yesno_noninteractivesz/FileOutputDisplayTest.test_yesno_noninteractiver"cCs d|_|jjdtdd\}}dS)Nz2 1r=Tr%r$r checklistTAGSr mock_inputrEZtag_listrrrtest_checklist_valids  z*FileOutputDisplayTest.test_checklist_validcCs d|_|jjdtdd\}}dS)Nr=Tr%r_rbrrrtest_checklist_emptysz*FileOutputDisplayTest.test_checklist_emptycCs gd|_|jjdtdd}dS)N)10z tag1 please1r=Tr%rWrr`rarrcr;rrrtest_checklist_miss_valids z/FileOutputDisplayTest.test_checklist_miss_validcCs ddg|_|jjdtdd}dS)NrgrBr=Tr%rirjrrrtest_checklist_miss_quits z.FileOutputDisplayTest.test_checklist_miss_quitcCs"t}|j|jjdt|d\}}dS)Nr=r>)rar+rr`rJrrrtest_checklist_noninteractives  z3FileOutputDisplayTest.test_checklist_noninteractivecCsPdggdddgg}dhddhddhg}t|D]\}}t|j|t}q0dS)Nrh)rh2rhrn3rrr) enumeratesetr_scrub_checklist_inputra)rindicesexpilist_Zset_tagsrrr test_scrub_checklist_input_valids z6FileOutputDisplayTest.test_scrub_checklist_input_validcCsdgd}ddgddggdgdg}ddgddgddgddgg}t|D]\}}|j||}qHdS)N) ZT1ZT2ZT3T4ZT5ZT6ZT7ZT8T949)rzr{rz)r{rzr{rxry)rprrr)rZ source_tagsrsrtrurvtagsrrr+test_scrub_checklist_maintain_indices_orderszAFileOutputDisplayTest.test_scrub_checklist_maintain_indices_ordercCs"gd}d}||_|jj|}dS)N)r= /var/www/htmlrLTr~)r$rdirectory_select)rrcargsZ user_inputZreturnedrrrtest_directory_selects  z+FileOutputDisplayTest.test_directory_selectcCs d}|j|jjd|d\}}dS)Nr~r=r>)r+rrrJrrr$test_directory_select_noninteractives  z:FileOutputDisplayTest.test_directory_select_noninteractivec Os||jj}tdP}d|j_td}||i|}Wdn1sJ0YWdn1sh0Y|rxn|S)Nz'certbot._internal.display.obj.sys.stdinFr)rskipped_interactionrr&isattyr$)rfuncrkwargsrZ mock_stdinrr@rrrr+s  Jz+FileOutputDisplayTest._force_noninteractivecCs*dgdgdgddgddgg}|D]}q dS)N0rzrrhrnor)rrsrvrrr"test_scrub_checklist_input_invalidsz8FileOutputDisplayTest.test_scrub_checklist_input_invalidcCs |jdt|jdtdS)Nr=)rZ _print_menur:rarrrrtest_print_menusz%FileOutputDisplayTest.test_print_menucCshd}tj|ddWdn1s(0Yd}tj||dWdn1sZ0YdS)Nr"rhr#rnr[)rr(ansrrrtest_get_valid_int_ans_valid s z2FileOutputDisplayTest.test_get_valid_int_ans_validc CsTddggddgg}d}|D]2}tj||dWdq1sD0YqdS)NrrB)rzZoneCr"rVr[)rZanswersr(rrrrtest_get_valid_int_ans_invalidsz4FileOutputDisplayTest.test_get_valid_int_ans_invalid)$__name__ __module__ __qualname____doc__r rr&r!r)r-r/r5r<rArGrIrKrQrSr\r^rdrfrkrlrmrwr}rrr+rrrr __classcell__rrrrr sJ            r c@sZeZdZdZddZedddZddZd d Z d d Z d dZ ddZ ddZ dS)NoninteractiveDisplayTestz:Test non-interactive display. These tests are pretty easy!cCst|_t|j|_dSr])rr r rZNoninteractiveDisplayrrrrrr $s zNoninteractiveDisplayTest.setUprcCs2|jdd|jjjdd}|jdddS)Nr rrrrrrrr!(sz4NoninteractiveDisplayTest.test_notification_no_pausecCsVddlm}|jjdddd|jjjdd}|jjddd|jjjdd}dSr0r3r4rrrr50s  z6NoninteractiveDisplayTest.test_notification_decorationcCsPd}|jjd|d}ttj|jdWdn1sB0YdS)Nzan incomputable valuerr>)rrDrNrOrMissingCommandlineFlagrdr;rrr test_input;sz$NoninteractiveDisplayTest.test_inputcCsP|jjdtdd}ttj|jdtWdn1sB0YdS)Nrr6r>)rr9r:rNrOrr)rr;rrrr<Bsz#NoninteractiveDisplayTest.test_menucCsPd}|jjd|d}ttj|jdWdn1sB0YdS)NFrr>)rZyesnorNrOrrrrrrr\Hsz$NoninteractiveDisplayTest.test_yesnocCsXddg}|jjdt|d}ttj|jdtWdn1sJ0YdS)Nr6rr>)rr`rarNrOrrrrrrtest_checklistOsz(NoninteractiveDisplayTest.test_checklistcCsXd}tj|f}|jd|}ttj|jdWdn1sJ0YdS)Nr~r=)r7r8rrrNrOrr)rr?ZexpectedactualrrrrVs  z/NoninteractiveDisplayTest.test_directory_selectN)rrrrr rr&r!r5rr<r\rrrrrrr"s  r__main__r6)rsysZunittestrrNZcertbotrZcertbot._internal.displayrrZcertbot.displayrr7r:raZTestCaser rrexitmainargv__file__rrrrs    >