
                             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m	Z	 ddl
mZ dd	lmZ ddlmc mZ dd
lmZ ddlmZ  ed       G d dej,                               Zy)z+Integration tests for notification command.    )absolute_import)print_function)division)unicode_literalsN)ApiSelector)PopulateProjectId)	PubsubApi)	SkipForS3)ObjectToURIz'gsutil doesn't support S3 notificationsc                   P     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
TestNotificationPubSubzEIntegration tests for notification command (the Cloud Pub/Sub parts).c                 ~    t         t        |           t        t	        j
                               | _        d | _        y )N)logger)superr   setUpr	   logging	getLogger
pubsub_apicreated_topicself	__class__s    7platform/gsutil/gslib/tests/test_notification_pubsub.pyr   zTestNotificationPubSub.setUp%   s.    	
 $-/w'8'8':;DOD    c                     t         t        |           | j                  r-| j                  j                  | j                         d | _        y y )N)r   r   tearDownr   r   DeleteTopicr   s    r   r   zTestNotificationPubSub.tearDown*   s?    	
 $02
oo!!$"4"45d r   c                     | j                   t        j                  k(  rt        j                  d      S dt        d      d|}|| _        |S )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   _RegisterDefaultTopicCreationz4TestNotificationPubSub._RegisterDefaultTopicCreation1   sL    }}']]GHH ( 6Gt5L5@B,Dr   c                     | j                   t        j                  k(  rt        j                  d      S | j                         }| j                  ddt        |      gd      }| j                  |       y)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_bucketz+TestNotificationPubSub.test_list_new_bucket;   sc    }}']]GHH""$J^^	j!12$  HFVr   c                     | j                   t        j                  k(  rt        j                  d      S | j                         }| j                  ddt        |      gd      }| j                  |       y)z<Tests deleting all notification configs when there are none.r   r(   deleteTr*   Nr,   r1   s      r   !test_delete_with_no_notificationsz8TestNotificationPubSub.test_delete_with_no_notificationsE   sc    }}']]GHH""$J^^	4
#34D  JFVr   c           	         | j                   t        j                  k(  rt        j                  d      S | j                         }| j                  |j                        }| j                  ddddt        |      gdd      \  }}| j                  r%| j                  d|       | j                  ||       y
| j                  d	|       | j                  ||       y
):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#   r-   r&   r$   r.   r/   _use_gcloud_storageassertIn)r   r2   
topic_namer3   stderrs        r   test_create_basicz(TestNotificationPubSub.test_create_basicO   s    }}']]GHH""$J33J4J4JKJ^^	4	j			 $ NFF 
mm0&9
mmJ'
mm*F3
mmJ'r   c                    | j                   t        j                  k(  rt        j                  d      S | j                         }|j                  }| j                  |j                        }| j                  ddddddddd	d
ddt        |      gd       | j                  ddt        |      gd      }| j                  rd}nd}| j                  |dj                  |||             y)z1Tests notification config listing with one entry.r   r(   r:   r;   r<   z-eOBJECT_FINALIZEOBJECT_DELETEz-mzsomeKey:someValuez-p
somePrefixT)r=   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$   r@   trailing_spaceN)r    r   r!   r"   r#   r-   r$   r&   r.   r/   r>   assertEqualformat)r   r2   r$   r@   r3   rI   s         r   test_list_one_entryz*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           	      6   | j                   t        j                  k(  rt        j                  d      S | j                         }| j                  |j                         | j                  ddddt        |      g       | j                  ddt        |      g       y)r9   r   r(   r:   r;   r<   r6   N)
r    r   r!   r"   r#   r-   r&   r$   r.   r/   )r   r2   s     r   test_deletez"TestNotificationPubSub.test_delete   sx    }}']]GHH""$J&&z'='=>NNNHdFD<LMNNNNHd:.>?@r   )__name__
__module____qualname____doc__r   r   r&   r4   r7   rB   rL   rN   __classcell__)r   s   @r   r   r   !   s0    M
 (*#.JAr   r   )rR   
__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   r/   GsUtilIntegrationTestCaser    r   r   <module>r_      s^    2 & %  '   ( . & ' ' ? 0 56oAX?? oA 7oAr   