
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJ	r	  SSK
Jr  SS	KJr  SSKJs  Jr  SS
KJr  SSKJr  \" S5       " S S\R,                  5      5       rg)z+Integration tests for notification command.    )absolute_import)print_function)division)unicode_literalsN)ApiSelector)PopulateProjectId)	PubsubApi)	SkipForS3)ObjectToURIz'gsutil doesn't support S3 notificationsc                   \   ^  \ rS rSrSrU 4S jrU 4S jrS rS rS r	S r
S	 rS
 rSrU =r$ )TestNotificationPubSub!   zEIntegration tests for notification command (the Cloud Pub/Sub parts).c                 z   > [         [        U ]  5         [        [        R
                  " 5       S9U l        S U l        g )N)logger)superr   setUpr	   logging	getLogger
pubsub_apicreated_topicself	__class__s    7platform/gsutil/gslib/tests/test_notification_pubsub.pyr   TestNotificationPubSub.setUp%   s.    	
 $-/w'8'8':;DOD    c                    > [         [        U ]  5         U R                  (       a-  U R                  R                  U R                  5        S U l        g g )N)r   r   tearDownr   r   DeleteTopicr   s    r   r   TestNotificationPubSub.tearDown*   s?    	
 $02
oo!!$"4"45d r   c                     U R                   [        R                  :X  a  [        R                  " S5      $ S[        S5      < SU< 3nX l        U$ )z=Records the name of a topic we expect to create, for cleanup.*Notifications only work with the JSON API.z	projects/Nz/topics/)test_apir   XMLunittestskipr   r   )r   bucket_nameexpected_topic_names      r   _RegisterDefaultTopicCreation4TestNotificationPubSub._RegisterDefaultTopicCreation1   sJ    }}']]GHH ( 6Gt5L5@B,r   c                     U R                   [        R                  :X  a  [        R                  " S5      $ U R                  5       nU R                  SS[        U5      /SS9nU R                  U5        g)z3Tests listing notification configs on a new bucket.r"   notificationlistTreturn_stdoutN	r#   r   r$   r%   r&   CreateBucket	RunGsUtilsuriassertFalser   
bucket_uristdouts      r   test_list_new_bucket+TestNotificationPubSub.test_list_new_bucket;   sc    }}']]GHH""$J^^	j!12$  HFVr   c                     U R                   [        R                  :X  a  [        R                  " S5      $ U R                  5       nU R                  SS[        U5      /SS9nU R                  U5        g)z<Tests deleting all notification configs when there are none.r"   r,   deleteTr.   Nr0   r5   s      r   !test_delete_with_no_notifications8TestNotificationPubSub.test_delete_with_no_notificationsE   sc    }}']]GHH""$J^^	4
#34D  JFVr   c           	         U R                   [        R                  :X  a  [        R                  " S5      $ U R                  5       nU R                  UR                  5      nU R                  SSSS[        U5      /SSS9u  p4U R                  (       a$  U R                  SU5        U R                  X#5        g
U R                  S	U5        U R                  X$5        g
):Tests the create command succeeds in normal circumstances.r"   r,   create-fjsonT)r/   return_stderrzkind: storage#notificationzCreated notificationN)r#   r   r$   r%   r&   r1   r)   r'   r2   r3   _use_gcloud_storageassertIn)r   r6   
topic_namer7   stderrs        r   test_create_basic(TestNotificationPubSub.test_create_basicO   s    }}']]GHH""$J33J4J4JKJ^^	4	j			 $ NF 
mm0&9
mmJ'
mm*F3
mmJ'r   c                    U R                   [        R                  :X  a  [        R                  " S5      $ U R                  5       nUR                  nU R                  UR                  5      nU R                  SSSSSSSSS	S
SS[        U5      /SS9  U R                  SS[        U5      /SS9nU R                  (       a  SnOSnU R                  USR                  UUUS95        g)z1Tests notification config listing with one entry.r"   r,   r@   rA   rB   z-eOBJECT_FINALIZEOBJECT_DELETEz-mzsomeKey:someValuez-p
somePrefixT)rC   r-   r.   
 zprojects/_/buckets/{bucket_name}/notificationConfigs/1
	Cloud Pub/Sub topic: {topic_name}
	Custom attributes:
		someKey: someValue
	Filters:
		Event Types: OBJECT_FINALIZE, OBJECT_DELETE
		Object name prefix: 'somePrefix'
{trailing_space})r'   rF   trailing_spaceN)r#   r   r$   r%   r&   r1   r'   r)   r2   r3   rD   assertEqualformat)r   r6   r'   rF   r7   rP   s         r   test_list_one_entry*TestNotificationPubSub.test_list_one_entryd   s   }}']]GHH""$J((K33J4J4JKJNN$6G2D,Z
 "&  ' ^^	j!12$  HF  nn
D EKF$"* EK E,.r   c           	      :   U R                   [        R                  :X  a  [        R                  " S5      $ U R                  5       nU R                  UR                  5        U R                  SSSS[        U5      /5        U R                  SS[        U5      /5        g)r?   r"   r,   r@   rA   rB   r;   N)
r#   r   r$   r%   r&   r1   r)   r'   r2   r3   )r   r6   s     r   test_delete"TestNotificationPubSub.test_delete   sx    }}']]GHH""$J&&z'='=>NNNHdFD<LMNNNNHd:.>?@r   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r)   r8   r<   rH   rS   rV   __static_attributes____classcell__)r   s   @r   r   r   !   s6    M
 (*#.JA Ar   r   )r\   
__future__r   r   r   r   r   r%   gslib.cs_api_mapr   gslib.project_idr   gslib.pubsub_apir	   gslib.tests.testcaseteststestcase)gslib.tests.testcase.integration_testcaser
   gslib.tests.utilr   r3   GsUtilIntegrationTestCaser    r   r   <module>rj      s^    2 & %  '   ( . & ' ' ? 0 56oAX?? oA 7oAr   