B r/]6 @sddlZddlmZddlZddlmZmZddlZdddddd d dd dd dd ddd dd dd dZGddde Z Gdddej Z dS)N)support)patchMockCreatez 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_remainingrr`C:\Users\Lcollins\AppData\Local\Temp\pip-install-xe9bn6ac\crhelper\tests\test_resource_helper.pyget_remaining_time_in_millis'sz(MockContext.get_remaining_time_in_millisN)__name__ __module__ __qualname__Z function_namer staticmethodrrrrrr"src @seZdZedddededdZedddededdZedeed ed ded eed eed eedeedeedddddZedeed ed ded eed eedeedeededdddZedeed ed ded eed eedeedeededdZ edeed ed ded eed eedeededdZ edeed ed ded eed eededdZ edeed ed ded eededdZ edeed ed ded eed ddededdZ edeed ed ded eed eddZedeed ed ded eed eeded d!Zedeed ed ded eed eeded"d#Zedeed ed ded eed eeded$d%Zedeed ed ded eed eeded&d'ZdS)(TestCfnResourcezcrhelper.log_helper.setupN) return_valuez1crhelper.resource_helper.CfnResource._set_timeoutc Cs|t}|ddtjWdQRX|jddddt }|ddtjjddWdQRX|jdddd dS) N AWS_REGIONz us-east-1DEBUGERROR) boto_levelZ formatter_clsT) json_loggingZ ContainerInit)rr)rEnvironmentVarGuardsetcrhelperresource_helper CfnResourceassert_called_once_withassert_called_with)self mock_methodenvironrrr test_init.s    zTestCfnResource.test_initcCs(td|_tjjdd}||jdS)NtestT)r) Exception side_effectr r!r" assertTrueZ _init_failed)r%r&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_functionz2crhelper.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)FAILED)r r!r" test_events__call__rr,Z_send_responser#Z _sam_localrZ _poll_enabled _polling_initassert_not_called assertEquallenZcall_args_list assert_called_wait_for_cwlogs_sendr*r+r$)r%Zcfn_response_mockr-eventrrr test_callBs2              zTestCfnResource.test_callcCsHtj}t|_t}|j|d|dt_|j|d| dS)N)sleepi") r r!r"r_contextrr8r4rassert_called_once)r%r-srrrtest_wait_for_cwlogsis   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)Nrr0z Some stuff CrHelperPollzsome-id)r r!r"r1r_setup_polling_remove_pollingr3r>r4r5r Statusr7)r%r-r:rrrtest_polling_init{s8              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) NrrBz RID: [%s]Tztest-stack-id_TestResourceId_testpidzpid-from-eventr ) r r!r"r1rr9r r5Z _cfn_responser>print startswith)r%r-r:Zorig_pidrrrtest_cfn_responses2          z!TestCfnResource.test_cfn_responsecCsjtj}dd}|||d|j|d|jdd}|||d|j|d|jdS)NcSsdS)NrGr)er-rrrfuncsz0TestCfnResource.test_wrap_function..funcrGr0cSs tddS)Nztest exception)r*)rKr-rrrrLsztest exception) r r!r"Z_wrap_functionr5r ZassertNotEqualrEZReason)r%r-rLrrrtest_wrap_functions   z"TestCfnResource.test_wrap_functioncCs(tj}t}|j|d|dS)N)Z send_response)r r!r"rr9r>)r%r-r?rrr test_sends  zTestCfnResource.test_sendcCs"tj}||dddS)Nr0zExecution timed out)r r!r"_timeoutr$)r%r?r-rrr test_timeouts zTestCfnResource.test_timeoutcCsZtj}t|_dd}|td|}|t |t |j | |j dS)NcSsdS)NrrrrrrLsz.TestCfnResource.test_set_timeout..funci) r r!r"rr=Z _set_timeout threadingTimerr5typeZ_timercancel)r%r-rLtrrrtest_set_timeouts  z TestCfnResource.test_set_timeoutcCs2tj}dddd|_||i|jdS)Nr/)rACrHelperPermission CrHelperRule)r r!r"DataZ_cleanup_responser5)r%r-rrrtest_cleanup_responses z%TestCfnResource.test_cleanup_responsec Cst}|ddtj}WdQRXt|_t|j _ t|j _ t|j _ |t}||dt|WdQRX|j j |j j |j j d|jd<d|jd<||j j |j j |j j dS)Nrz us-east-1z*failed to cleanup CloudWatch event pollingz1/2rZrY)rrrr r!r"rr=r_events_clientZremove_targetsZ delete_rule_lambda_clientZremove_permissionZ assertRaisesr*rDr5strr4_eventr7)r%r'r-rKrrrtest_remove_pollings&             z#TestCfnResource.test_remove_pollingc Cst}|ddtj}WdQRXt|_td|_ t |j _ t ddid|j _t |j _||j j|j j|j j dS)Nrz us-east-1r ZRuleArnz+arn:aws:lambda:blah:blah:function:blah/blah)r)rrrr r!r"rr=r1r`rr^Zadd_permissionr]Zput_ruleZ put_targetsrCr7)r%r'r-rrrtest_setup_polling,s       z"TestCfnResource.test_setup_pollingcCs^tj}dd}xFdD]>}|dt|d|t|||||t|d|qWdS)NcSsdS)NrrrrrrLGsz+TestCfnResource.test_wrappers..func)createupdatedeleteZ poll_createZ poll_updateZ poll_deletez_%s_func)r r!r"r5getattr)r%r-rLfrrr test_wrappers?s   zTestCfnResource.test_wrappers)rrrrrr(r.r;r@rFrJrMrNrPrVr\rarbrhrrrrr,s        "     $      #                          r) r r)rZunittestZ unittest.mockrrrQr1objectrZTestCaserrrrrs.