a
    !fU                     @   s   d dl Z G dd de jZdS )    Nc                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestMessagec                 C   s   ddl m} |S )Nr   )Message)Zgcloud.pubsub.messager   )selfr    r   [/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/pubsub/test_message.py_getTargetClass   s    zTestMessage._getTargetClassc                 O   s   |   |i |S N)r   )r   argskwr   r   r   _makeOne   s    zTestMessage._makeOnec                 C   sR   d}d}| j ||d}| |j| | |j| | |ji  | |jd  d S )N   DEADBEEF   12345data
message_idr   assertEqualr   r   
attributesservice_timestamp)r   DATA
MESSAGE_IDmessager   r   r   test_ctor_no_attributes   s    z#TestMessage.test_ctor_no_attributesc                 C   s\   d}d}ddi}| j |||d}| |j| | |j| | |j| | |jd  d S )Nr   r   abr   r   r   r   )r   r   r   ATTRSr   r   r   r   test_ctor_w_attributes$   s    z"TestMessage.test_ctor_w_attributesc                    s2   d}d}| j ||d  fdd}| t| d S )Nr   r   r   c                      s    j S r   	timestampr   r   r   r   _to_fail4   s    z:TestMessage.test_timestamp_no_attributes.<locals>._to_failr   assertRaises
ValueError)r   r   r   r!   r   r    r   test_timestamp_no_attributes/   s
    z(TestMessage.test_timestamp_no_attributesc                    s<   d}d}ddi}| j |||d  fdd}| t| d S )Nr   r   r   r   r   c                      s    j S r   r   r   r    r   r   r!   @   s    zGTestMessage.test_timestamp_wo_timestamp_in_attributes.<locals>._to_failr"   )r   r   r   r   r!   r   r    r   )test_timestamp_wo_timestamp_in_attributes9   s    z5TestMessage.test_timestamp_wo_timestamp_in_attributesc                 C   sr   ddl m } ddlm} ddlm} d}d}d}|||}|j|d}d	|i}	| j|||	d
}
| |
j| d S )Nr   )datetime)_RFC3339_MICROS)UTCr   r   z2015-04-10T18:42:27.131956Z)tzinfor   r   )	r'   Zgcloud._helpersr(   r)   strptimereplacer   r   r   )r   r'   r(   r)   r   r   	TIMESTAMPZnaiver   r   r   r   r   r   (test_timestamp_w_timestamp_in_attributesE   s    z4TestMessage.test_timestamp_w_timestamp_in_attributesc                 C   sV   d}d|i}|   |}| |jd | |j| | |ji  | |jd  d S )N12345	messageId    )r   from_api_reprr   r   r   r   r   )r   r   api_reprr   r   r   r   test_from_api_repr_missing_dataS   s    z+TestMessage.test_from_api_repr_missing_datac                 C   sv   ddl m} d}||}d}d}|||d}|  |}| |j| | |j| | |ji  | |j| d S )Nr   	b64encoder   r/   2016-03-18-19:38:22.001393427Z)r   r0   publishTimestamp)	base64r6   r   r2   r   r   r   r   r   )r   b64r   B64_DATAr   r-   r3   r   r   r   r    test_from_api_repr_no_attributes\   s    z,TestMessage.test_from_api_repr_no_attributesc           	      C   s   ddl m} d}||}d}ddi}d}||||d}|  |}| |j| | |j| | |j| | |j| d S )	Nr   r5   r   r/   r   r   r7   )r   r0   r8   r   )	r9   r6   r   r2   r   r   r   r   r   )	r   r:   r   r;   r   r   r-   r3   r   r   r   r   test_from_api_repr_w_attributesm   s     z+TestMessage.test_from_api_repr_w_attributesN)__name__
__module____qualname__r   r   r   r   r%   r&   r.   r4   r<   r=   r   r   r   r   r      s   	
	r   )Z	unittest2ZTestCaser   r   r   r   r   <module>   s   