
                         >   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	Z	ddl
mZ ddlmc mZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ  e eddd             ddlmZ d Z e       Z G d dej8                        Z G d dej<                        Zy)+Integration tests for notification command.    )absolute_import)print_function)division)unicode_literalsN)CloudApiDelegator)ObjectToURI)unittest)Retry)add_moveMovedModulemockzunittest.mock)r   c                  B    t         j                  j                  dd      S )NGSUtiltest_notification_url)botoconfig	get_value     0platform/gsutil/gslib/tests/test_notification.py_LoadNotificationUrlr   (   s    			x)@	AAr   c                   T    e Zd Zej                  j                  edd      d        Zy)TestNotificationUnitCreateNotificationConfigT)autospecc                 2   | j                  d      }| j                  ddddddd	t        |      gd
      }|j                  t        j
                  dt        j
                  t        j
                  ddid t        j
                  t        j
                         y )Nfoo_notification)bucket_namenotificationcreatez-fnonez-sz-mzfoo:bar:bazT)return_stdoutfoozbar:baz)pubsub_topicpayload_formatcustom_attributesevent_typesobject_name_prefixprovider)CreateBucket
RunCommandsuriassert_called_once_withr   ANY)selfmock_create_notification
bucket_uristdouts       r   /test_notification_splits_dash_m_value_correctlyzDTestNotificationUnit.test_notification_splits_dash_m_value_correctly1   s    
 ""/A"BJ__	4t]	j			  F
 44XXxx ),88 5 r   N)__name__
__module____qualname__r   patchobjectr   r4   r   r   r   r   r   /   s1    ::&/"  $$r   r   c                       e Zd ZdZ ej
                  ed      d        Z ej
                  ed      d        Z ej
                  ed      d        Z	d Z
y)TestNotificationr   z-Test requires notification URL configuration.c                    | j                         }| j                  ddt        t        |      g       t	        t        j                               }t	        t        j                               }| j                  ddd|d|t        t        |      gd      }| j                  d|z  |       | j                  d|z  |       y	)
z2Tests creating a notification channel on a bucket.r    watchbucketz-iz-tTreturn_stderrz	token: %szidentifier: %sN)r+   	RunGsUtilNOTIFICATION_URLr-   struuiduuid4assertIn)r0   r2   
identifiertokenstderrs        r   test_watch_bucketz"TestNotification.test_watch_bucketJ   s     ""$JNN	(8	j		 TZZ\"J

E^^tZuZ
 +/  0F 	MM+%v.MM"Z/8r   c                 n   | j                         }| j                  ddt        t        |      gd      }t	        j
                  d|      }| j                  t        |      d       t	        j
                  d|      }| j                  t        |      d       |d   }|d   }| j                  dd	||g       y
)z2Tests stopping a notification channel on a bucket.r    r=   Tr>   zchannel identifier: (?P<id>.*)   zresource identifier: (?P<id>.*)r   stopchannelN)r+   r@   rA   r-   refindallassertEquallen)r0   r2   rH   
channel_idresource_ids        r   test_stop_channelz"TestNotification.test_stop_channel^   s     ""$J^^	(8	j		  F
 =vFJS_a(**?HKS%q)AJa.KNNNM:{KLr   c                 0     t        j                  d      S )z/Tests listing notification channel on a bucket.z2Functionality has been disabled due to b/132277269)r
   skipr+   r@   rA   r-   r   AssertionErrortimesleeprM   rN   rO   rP   )	r0   _ListObjectChangeNotificationsrH   rQ   rR   push_urlsubscriber_emailcreation_timer2   s	   `       @r   test_list_one_channelz&TestNotification.test_list_one_channelr   s    
 ==MNNr   c                 T    | j                  g ddd      }| j                  d|       y )N)r    r$   barbazTrK   )r?   expected_statuszInvalid subcommand)r@   rE   )r0   rH   s     r   test_invalid_subcommandz(TestNotification.test_invalid_subcommand   s/    ^^A*.,-  /F 	MM&/r   N)r5   r6   r7   __doc__r
   
skipUnlessrA   rI   rS   r]   rb   r   r   r   r;   r;   G   s    38'FH9H9$ 8'FHMHM$ 8'FH%,H%,N0r   r;   ) rc   
__future__r   r   r   r   rM   rW   rC   r   gslib.cloud_api_delegatorr   gslib.tests.testcaseteststestcasegslib.tests.utilr	   r-   r
   gslib.utils.retry_utilr   sixr   r   	six.movesr   r   rA   GsUtilUnitTestCaser   GsUtilIntegrationTestCaser;   r   r   r   <module>rp      s    2 & %  ' 	    7 ' ' 0 % ( % VV_	5 6 B () 866 0X0x99 X0r   