U -_~8 @sddlZddlZddlZddlmZmZmZddlZddddddd dd dd dd d dd dd dd dZGddde Z Gdddej Z dS)N)callpatchMockCreatez test-event-idzarn/test-stack-id/guidZTestResourceIdZ response_url) RequestType RequestIdStackIdLogicalResourceId ResponseURLUpdatez test-stack-idztest-pid)rrrr PhysicalResourceIdr Delete)rr r c@s eZdZdZdZeddZdS) MockContextz test-functioni(#cCstjSN)r ms_remainingrr>/tmp/pip-unpacked-wheel-7s1ms2ou/tests/test_resource_helper.pyget_remaining_time_in_millis'sz(MockContext.get_remaining_time_in_millisN)__name__ __module__ __qualname__Z function_namer staticmethodrrrrrr"src @sdeZdZddZddZedddeded d Zedddeded d Zedeed eddedeedeededeededdZ edeed eddedeedeedeedeedeedddddZ edeed eddedeedeedeedeededdddZ edeed eddedeedeedeedeededdZ edeed eddedeedeedeededdZ edeed eddedeedeededdZedeed eddedeeded d!Zedeed eddedeedddeded"d#Zedeed eddedeeded$d%Zedeed eddedeedeeded&d'Zedeed eddedeedeeded(d)Zedeed eddedeedeeded*d+Zedeed eddedeedeeded,d-ZdS).TestCfnResourcecCsdtjd<dS)Nz us-east-1 AWS_REGION)osenvironselfrrrsetUp-szTestCfnResource.setUpcCstjdddS)Nr)rrpoprrrrtearDown0szTestCfnResource.tearDownzcrhelper.log_helper.setupNZ return_valuez1crhelper.resource_helper.CfnResource._set_timeoutcCs<tj|jddddtjjdd|jdddddS)NDEBUGERROR) boto_levelZ formatter_clsTZ json_loggingZ ContainerInit)r$r)crhelperresource_helper CfnResourceassert_called_once_withassert_called_with)r mock_methodrrr test_init3s zTestCfnResource.test_initcCs(td|_tjjdd}||jdS)NtestTr%) Exception side_effectr&r'r( assertTrueZ _init_failed)rr+crrrtest_init_failure<s z!TestCfnResource.test_init_failurez2crhelper.resource_helper.CfnResource._poll_enabledFz2crhelper.resource_helper.CfnResource._polling_initz5crhelper.resource_helper.CfnResource._wait_for_cwlogsz*crhelper.resource_helper.CfnResource._sendz3crhelper.resource_helper.CfnResource._wrap_functioncCsFtj}|tdtd}||t|t ddg|j dS)NZ TestExceptionrFAILED) r&r'r(Z init_failurer. test_events__call__r assertEqualrcall_args_list)rZ mock_sendr1eventrrrtest_init_failure_callCs   z&TestCfnResource.test_init_failure_callz2crhelper.resource_helper.CfnResource._cfn_responsecCs tj}td}||t||j||d|_ t dd|_ t |_ ||t|j |dt|jd|_ d|_||t|j |dt|jtd}t |_t dd|_ ||t|jt |_td|_||t|jdddS) NrTr!Fr r-r3)r&r'r(r4r5rr0Z_send_responser)Z _sam_localrZ _poll_enabled _polling_initassert_not_calledr6lenr7 assert_called_wait_for_cwlogs_sendr.r/r*)rZcfn_response_mockr1r8rrr test_callSs2              zTestCfnResource.test_callcCsHtj}t|_t}|j|d|dt_|j|d| dS)N)sleepi") r&r'r(r_contextrr?r<rassert_called_oncerr1srrrtest_wait_for_cwlogszs   z$TestCfnResource.test_wait_for_cwlogscCstj}td}t|_t|_|||j|j | |j dd|_ |j|jtj}td}t|_t|_d|d<d|_ |||j |j d|_ |||j|j d|_ d|_ |j |j dS)Nrr3z Some stuff CrHelperPollzsome-id)r&r'r(r4r_setup_polling_remove_pollingr;rDr<r6r Statusr>)rr1r8rrrtest_polling_inits8              z!TestCfnResource.test_polling_initcCstj}td}t|_|j}||d|||j t d|jg|d|j dt|_d|_|||j |d|jt|_d|_|||j |d|j dt|_d|_d|d<|||j |d|jdS) NrrIz RID: [%s]Tztest-stack-id_TestResourceId_testpidzpid-from-eventr ) r&r'r(r4rr@r r6Z _cfn_responserDprint startswith)rr1r8Zorig_pidrrrtest_cfn_responses2          z!TestCfnResource.test_cfn_responsecCsjtj}dd}|||d|j|d|jdd}|||d|j|d|jdS)NcSsdS)NrNrer1rrrfuncsz0TestCfnResource.test_wrap_function..funcrNr3cSs tddS)Ntest exception)r.rRrrrrTsrU) r&r'r(Z_wrap_functionr6r ZassertNotEqualrLZReason)rr1rTrrrtest_wrap_functions   z"TestCfnResource.test_wrap_functioncCs(tj}t}|j|d|dS)N)Z send_response)r&r'r(rr@rDrErrr test_sends  zTestCfnResource.test_sendcCs"tj}||dddS)Nr3zExecution timed out)r&r'r(_timeoutr*)rrFr1rrr test_timeouts zTestCfnResource.test_timeoutcCsZtj}t|_dd}|td|}|t |t |j | |j dS)NcSsdSrrrrrrrT sz.TestCfnResource.test_set_timeout..funci) r&r'r(rrCZ _set_timeout threadingTimerr6typeZ_timercancel)rr1rTtrrrtest_set_timeouts  z TestCfnResource.test_set_timeoutcCs2tj}dddd|_||i|jdS)Nr:)rHCrHelperPermission CrHelperRule)r&r'r(DataZ_cleanup_responser6rr1rrrtest_cleanup_responses z%TestCfnResource.test_cleanup_responsec Cstj}t|_t|j_t|j_t|j _ | t }| |dt|W5QRX|jj|jj|j j d|jd<d|jd<| |jj|jj|j j dS)Nz*failed to cleanup CloudWatch event pollingz1/2rcrb)r&r'r(rrCr_events_clientZremove_targetsZ delete_rule_lambda_clientZremove_permission assertRaisesr.rKr6strr<_eventr>)rr1rSrrrtest_remove_pollings"            z#TestCfnResource.test_remove_pollingcCsrtj}t|_td|_t|j_ tddid|j _ t|j _ | |j j |j j |jj dS)Nr ZRuleArnz+arn:aws:lambda:blah:blah:function:blah/blahr!)r&r'r(rrCr4rkrrhZadd_permissionrgZput_ruleZ put_targetsrJr>rerrrtest_setup_polling;s      z"TestCfnResource.test_setup_pollingcCsZtj}dd}dD]>}|dt|d|t|||||t|d|qdS)NcSsdSrrrrrrrTTsz+TestCfnResource.test_wrappers..func)createupdatedeleteZ poll_createZ poll_updateZ poll_deletez_%s_func)r&r'r(r6getattr)rr1rTfrrr test_wrappersLs  zTestCfnResource.test_wrappers)rrrrr rrr,r2r9rArGrMrQrVrWrYr_rfrlrmrsrrrrr,s                             "                                   r) rr&ZunittestZ unittest.mockrrrrZr4objectrZTestCaserrrrrs6