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.loggercCs>|jdd|jjjdd}d|vs,J|jdddS)NmessageFrNotifying user: %sr notificationr write call_argsdebugZassert_called_withr mock_loggerstringrrrtest_notification_no_pauses z0FileOutputDisplayTest.test_notification_no_pausecCs`d}tj|dd |jjdddWdn1s80Yd|jjjddvs\JdS)N1certbot._internal.display.util.input_with_timeoutZenter return_valuerTforce_interactiver)rpatchrrr rrrinput_with_timeoutrrrtest_notification_pause$s.z-FileOutputDisplayTest.test_notification_pausecCs2||jjd|jjjdd}d|vs.JdS)Nrr)_force_noninteractiverrr rrrr rrr test_notification_noninteractive+sz6FileOutputDisplayTest.test_notification_noninteractivecCsl||jjd|jjjdd}d|vs.J|jjs:J||jjd|jjjdd}d|vshJdS)Nrrmessage2)r+rrr rrskipped_interactionr,rrr!test_notification_noninteractive20s  z7FileOutputDisplayTest.test_notification_noninteractive2cCsddlm}|jjdddd|jjjdd}|d|jksBJ|jjddd|jjjdd}d|vspJd|j|vsJdS Nr)osrF)pauseZdecorater.)r3z- - - Zcertbot.compatr2rrr rrlineseprr2r rrrtest_notification_decoration=s  z2FileOutputDisplayTest.test_notification_decorationzd|_|jjdtdd\}}|t|ftjddhfks:JdS)Nz2 1r?Tr%rrr$r checklistTAGSsetr9r:r mock_inputrGZtag_listrrrtest_checklist_valids  z*FileOutputDisplayTest.test_checklist_validcCs>d|_|jjdtdd\}}|t|ftjhdfks:JdS)Nr?Tr%>rrrr`rdrrrtest_checklist_emptysz*FileOutputDisplayTest.test_checklist_emptycCs4gd|_|jjdtdd}|tjdgfks0JdS)N)10z tag1 please1r?Tr%r)rYrrarbr9r:rrer=rrrtest_checklist_miss_valids z/FileOutputDisplayTest.test_checklist_miss_validcCs2ddg|_|jjdtdd}|tjgfks.JdS)NrirDr?Tr%)rYrrarbr9rFrkrrrtest_checklist_miss_quits z.FileOutputDisplayTest.test_checklist_miss_quitcCs<t}|j|jjdt|d\}}|tjks,J||ks8JdS)Nr?r@)rbr+rrar9r:rLrrrtest_checklist_noninteractives  z3FileOutputDisplayTest.test_checklist_noninteractivecCs`dggdddgg}dhddhddhg}t|D]*\}}t|j|t}|||ks0Jq0dS)Nrj)rj2rjro3rrr) enumeratercr_scrub_checklist_inputrb)rindicesexpilist_Zset_tagsrrr test_scrub_checklist_input_valids z6FileOutputDisplayTest.test_scrub_checklist_input_validcCstgd}ddgddggdgdg}ddgddgddgddgg}t|D]&\}}|j||}|||ksHJqHdS)N) ZT1ZT2ZT3T4ZT5ZT6ZT7ZT8T949)rzr{rz)r{rzr{rxry)rqrrr)rZ source_tagsrsrtrurvtagsrrr+test_scrub_checklist_maintain_indices_orderszAFileOutputDisplayTest.test_scrub_checklist_maintain_indices_ordercCs4gd}d}||_|jj|}|tj|fks0JdS)N)r? /var/www/htmlrNTr~)r$rdirectory_selectr9r:)rreargsZ user_inputZreturnedrrrtest_directory_selects  z+FileOutputDisplayTest.test_directory_selectcCs:d}|j|jjd|d\}}|tjks*J||ks6JdS)Nr~r?r@)r+rrr9r:rLrrr$test_directory_select_noninteractives  z:FileOutputDisplayTest.test_directory_select_noninteractivec Os|jj}tdP}d|j_td}||i|}Wdn1sJ0YWdn1sh0Y|r|jjdusJn|jjdksJ|S)Nz'certbot._internal.display.obj.sys.stdinFrr8) rr/rr'isattyr$ZwarningZcalledZ call_count)rfuncrkwargsr/Z mock_stdinrrBrrrr+s  Jz+FileOutputDisplayTest._force_noninteractivecCs@dgdgdgddgddgg}|D]}|j|tgks Jq dS)N0rzrrjroo)rrrrb)rrsrvrrr"test_scrub_checklist_input_invalidsz8FileOutputDisplayTest.test_scrub_checklist_input_invalidcCs |jdt|jdtdS)Nr?)rZ _print_menur<rbrrrrtest_print_menusz%FileOutputDisplayTest.test_print_menucCsd}tj|dd*|jdtjdfks.JWdn1sB0Yd}tj||d.|jdtjt|fks~JWdn1s0YdS)Nr"rjr#r8ro)rr'r_get_valid_int_ansr9r:int)rr)ansrrrtest_get_valid_int_ans_valid s8  z2FileOutputDisplayTest.test_get_valid_int_ans_validc Csnddggddgg}d}|D]L}tj||d*|jdtjdfksJJWdq1s^0YqdS)NrrD)rzZoneCr"rXr)rr'rrr9rF)rZanswersr)rrrrtest_get_valid_int_ans_invalids z4FileOutputDisplayTest.test_get_valid_int_ans_invalid)$__name__ __module__ __qualname____doc__r rr'r!r*r-r0r7r>rCrIrKrMrSrUr^r_rfrhrlrmrnrwr}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|_dS)N)rr r rZNoninteractiveDisplayrrrrrr $s zNoninteractiveDisplayTest.setUprcCs>|jdd|jjjdd}d|vs,J|jdddS)Nr rrrrrrrr!(s z4NoninteractiveDisplayTest.test_notification_no_pausecCsddlm}|jjdddd|jjjdd}|d|jksBJ|jjddd|jjjdd}d|vspJd|j|vsJdSr1r4r6rrrr70s  z6NoninteractiveDisplayTest.test_notification_decorationcCsbd}|jjd|d}|tj|fks&Jttj|jdWdn1sT0YdS)Nzan incomputable valuerr@)rrEr9r:rPrQrMissingCommandlineFlagrdr=rrr test_input;s z$NoninteractiveDisplayTest.test_inputcCsb|jjdtdd}|tjdfks$Jttj|jdtWdn1sT0YdS)Nrr8r@) rr;r<r9r:rPrQrr)rr=rrrr>Bsz#NoninteractiveDisplayTest.test_menucCs\d}|jjd|d}||ks Jttj|jdWdn1sN0YdS)NFrr@)rr]rPrQrrrrrrr^Hs  z$NoninteractiveDisplayTest.test_yesnocCsjddg}|jjdt|d}|tj|fks,Jttj|jdtWdn1s\0YdS)Nr8rrr@) rrarbr9r:rPrQrrrrrrtest_checklistOs z(NoninteractiveDisplayTest.test_checklistcCsdd}tj|f}|jd|}||ks(Jttj|jdWdn1sV0YdS)Nr~r?)r9r:rrrPrQrr)rrAZexpectedactualrrrrVs   z/NoninteractiveDisplayTest.test_directory_selectN)rrrrr rr'r!r7rr>r^rrrrrrr"s  r__main__r8)rsysZunittestrrPZcertbotrZcertbot._internal.displayrrZcertbot.displayrr9r<rbZTestCaser rrexitmainargv__file__rrrrs    >