B _^~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(#cCstjS)N)r ms_remainingrrr/private/var/folders/6d/485zl0ms10b8gn_c1vw1k_780000gn/T/pip-unpacked-wheel-ytewl15c/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)osenviron)selfrrrsetUp-szTestCfnResource.setUpcCstjdddS)Nr)rrpop)rrrrtearDown0szTestCfnResource.tearDownzcrhelper.log_helper.setupN) return_valuez1crhelper.resource_helper.CfnResource._set_timeoutcCs<tj|jddddtjjdd|jdddddS)NDEBUGERROR) boto_levelZ formatter_clsT) json_loggingZ ContainerInit)r"r)crhelperresource_helper CfnResourceassert_called_once_withassert_called_with)r mock_methodrrr test_init3s zTestCfnResource.test_initcCs(td|_tjjdd}||jdS)NtestT)r#) 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_sendr/eventrrrtest_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) NrT)rFr r+r1)r$r%r&r2r3rr.Z_send_responser'Z _sam_localrZ _poll_enabled _polling_initassert_not_calledr4lenr5 assert_called_wait_for_cwlogs_sendr,r-r()rZcfn_response_mockr/r6rrr test_callSs2              zTestCfnResource.test_callcCsHtj}t|_t}|j|d|dt_|j|d| dS)N)sleepi") r$r%r&r_contextrr=r:rassert_called_once)rr/srrrtest_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)Nrr1z Some stuff CrHelperPollzsome-id)r$r%r&r2r_setup_polling_remove_pollingr9rBr:r4r Statusr<)rr/r6rrrtest_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) NrrFz RID: [%s]Tztest-stack-id_TestResourceId_testpidzpid-from-eventr ) r$r%r&r2rr>r r4Z _cfn_responserBprint startswith)rr/r6Zorig_pidrrrtest_cfn_responses2          z!TestCfnResource.test_cfn_responsecCsjtj}dd}|||d|j|d|jdd}|||d|j|d|jdS)NcSsdS)NrKr)er/rrrfuncsz0TestCfnResource.test_wrap_function..funcrKr1cSs tddS)Nztest exception)r,)rOr/rrrrPsztest exception) r$r%r&Z_wrap_functionr4r ZassertNotEqualrIZReason)rr/rPrrrtest_wrap_functions   z"TestCfnResource.test_wrap_functioncCs(tj}t}|j|d|dS)N)Z send_response)r$r%r&rr>rB)rr/rCrrr test_sends  zTestCfnResource.test_sendcCs"tj}||dddS)Nr1zExecution timed out)r$r%r&_timeoutr()rrCr/rrr test_timeouts zTestCfnResource.test_timeoutcCsZtj}t|_dd}|td|}|t |t |j | |j dS)NcSsdS)NrrrrrrP sz.TestCfnResource.test_set_timeout..funci) r$r%r&rrAZ _set_timeout threadingTimerr4typeZ_timercancel)rr/rPtrrrtest_set_timeouts  z TestCfnResource.test_set_timeoutcCs2tj}dddd|_||i|jdS)Nr8)rECrHelperPermission CrHelperRule)r$r%r&DataZ_cleanup_responser4)rr/rrrtest_cleanup_responses z%TestCfnResource.test_cleanup_responsec Cstj}t|_t|j_t|j_t|j _ | t }| |dt|WdQRX|jj|jj|j j d|jd<d|jd<| |jj|jj|j j dS)Nz*failed to cleanup CloudWatch event pollingz1/2r^r])r$r%r&rrAr_events_clientZremove_targetsZ delete_rule_lambda_clientZremove_permission assertRaisesr,rHr4strr:_eventr<)rr/rOrrrtest_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/blah)r)r$r%r&rrAr2rerrbZadd_permissionraZput_ruleZ put_targetsrGr<)rr/rrrtest_setup_polling;s      z"TestCfnResource.test_setup_pollingcCs^tj}dd}xFdD]>}|dt|d|t|||||t|d|qWdS)NcSsdS)NrrrrrrPTsz+TestCfnResource.test_wrappers..func)createupdatedeleteZ poll_createZ poll_updateZ poll_deletez_%s_func)r$r%r&r4getattr)rr/rPfrrr test_wrappersLs   zTestCfnResource.test_wrappers)rrrrrrrr*r0r7r?rDrJrNrQrRrTrZr`rfrgrmrrrrr,s            "     $      #                          r) rr$ZunittestZ unittest.mockrrrrUr2objectrZTestCaserrrrrs.