a }|g@sdZddlZddlZddlZddlmZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddlmmZejedZGdd d ejZGd d d eZGd d d eZGdddejZedkreeejdde gdS)z Tests for certbot._internal.eff.N)mock)messages)account) constantszrsa512_key.pemcs eZdZdZfddZZS)SubscriptionTestz&Abstract class for subscription tests.csbttjtjdtddttjjdt j ddddddt j d d d |_d |j _ d|j _dS) Nhi)ZuribodyZnew_authzr_uriztest.certbot.orgi )Ztzinfo)Z creation_hostZ creation_dt)Zregrkeymetacertbot@example.org)supersetUprZAccountrZRegistrationResourceZ Registration_KEYZMetadatetimepytzZUTCconfigemail eff_emailself __class__D/usr/lib/python3.9/site-packages/certbot/_internal/tests/eff_test.pyrs   zSubscriptionTest.setUp)__name__ __module__ __qualname____doc__r __classcell__rrrrrsrc@seZdZdZddZeedddZ eddZ ed d Z ed d Z ed dZ ddZddZdS)PrepareSubscriptionTestz5Tests for certbot._internal.eff.prepare_subscription.cCsddlm}||j|jdS)Nr)prepare_subscription)certbot._internal.effr$rr)rr$rrr_call's zPrepareSubscriptionTest._call)certbot._internal.eff.display_util.notifycCs.d|j_d|j_||jdd}d}dS)NTrz,because you didn't provide an e-mail address)rrrr& call_args)r mock_notifymock_get_utilityactual expected_partrrr test_failure+s z$PrepareSubscriptionTest.test_failurecCsd|j_|||dSNFrrr&_assert_no_get_utility_callsrr*rrr&test_will_not_subscribe_with_no_prompt6s z>PrepareSubscriptionTest.test_will_not_subscribe_with_no_promptcCsd|j_|||dSNTr/r1rrr"test_will_subscribe_with_no_prompt=s z:PrepareSubscriptionTest.test_will_subscribe_with_no_promptcCs d|j_|||dSr.yesno return_valuer&_assert_correct_yesno_callr1rrr#test_will_not_subscribe_with_promptDs  z;PrepareSubscriptionTest.test_will_not_subscribe_with_promptcCs d|j_|||dSr3r5r1rrrtest_will_subscribe_with_promptLs  z7PrepareSubscriptionTest.test_will_subscribe_with_promptcCsdSNrr1rrrr0Tsz4PrepareSubscriptionTest._assert_no_get_utility_callscCs|jj\}}|d}d}dS)NrzElectronic Frontier Foundation)r6r()rr*r( call_kwargsr+r,rrrr8Xsz2PrepareSubscriptionTest._assert_correct_yesno_callN)rrr r!r& test_utilpatch_display_utilrpatchr-r2r4r9r:r0r8rrrrr#%s     r#c@s<eZdZdZddZedddZedddZd S) HandleSubscriptionTestz4Tests for certbot._internal.eff.handle_subscription.cCsddlm}||j|jdS)Nr)handle_subscription)r%rArr)rrArrrr&cs zHandleSubscriptionTest._callzcertbot._internal.eff.subscribecCs |dSr;r&rZmock_subscriberrrtest_no_subscribegsz(HandleSubscriptionTest.test_no_subscribecCs$|jjj|jjd|j_|dS)N)Zregister_to_eff)rrupdaterrr&rCrrrtest_subscribelsz%HandleSubscriptionTest.test_subscribeN) rrr r!r&rr?rDrFrrrrr@as  r@c@sjeZdZdZddZedddZddZd d Z d d Z d dZ ddZ ddZ eddZdS) SubscribeTestz*Tests for certbot._internal.eff.subscribe.cCsNd|_ddi|_tjdd|_|j|jj_td}||_| |j dS)NrstatusT)okr') rjsonrZMockresponser7r?startr)Z addCleanupstop)rZpatcherrrrrvs    zSubscribeTest.setUpz#certbot._internal.eff.requests.postcCs,|j|_ddlm}||j||dS)Nr) subscribe)rKr7r%rNr_check_post_call)r mock_postrNrrrr&s  zSubscribeTest._callcCs|j\}}|d}dS)Ndata)r(get)rrPr(r<rQrrrrOs  zSubscribeTest._check_post_callcCs"d|jd<||}d}dS)NFrHz2because your e-mail address appears to be invalid.)rJr&_get_reported_messagerr+r,rrrtest_bad_statuss  zSubscribeTest.test_bad_statuscCs.d|j_tjj|jj_||}d}dS)NFZbecause) rKrIrequests exceptionsZ HTTPErrorZraise_for_status side_effectr&rS)rr+Zunexpected_partrrr test_not_oks zSubscribeTest.test_not_okcCs$t|jj_||}d}dSNZproblem) ValueErrorrKrJrXr&rSrTrrrtest_response_not_jsons  z$SubscribeTest.test_response_not_jsoncCs"|j||}d}dSrZ)rJclearr&rSrTrrr)test_response_json_missing_status_elements  z7SubscribeTest.test_response_json_missing_status_elementcCs|jjddS)Nr)r)r(rrrrrSsz#SubscribeTest._get_reported_messagecCs |dSr;rBr1rrrrFszSubscribeTest.test_subscribeN)rrr r!rrr?r&rOrUrYr\r^rSr=r>rFrrrrrGts   rG__main__)!r!rsysZunittestrZjosepyZpytestrrVZacmerZcertbot._internalrrZcertbot.tests.utilZtestsutilr=ZJWKRSAloadZ load_vectorrZConfigTestCaserr#r@ZTestCaserGrexitmainargv__file__rrrrs&    <C