o
    \ha                     @   s   d dl Z d dlZd dlmZmZ d dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZ d dlmZ G dd dejZejdg dd	d
 ZdS )    N)datedatetime)DatetimeSerializerQuotaLimitError
batch_postdecidedetermine_server_host)TEST_API_KEYc                   @   sT   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S )TestRequestsc                 C   s(   t tddddgd}| |jd d S )Ndistinct_idpython eventtrackr   eventtypebatch   r   r	   assertEqualstatus_codeselfres r   \/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/posthog/test/test_request.pytest_valid_request   s   
zTestRequests.test_valid_requestc                 C   s   |  ttdddd d S )N
testsecrethttps://t.posthog.comFz[{]assertRaises	Exceptionr   r   r   r   r   test_invalid_request_error   s   z'TestRequests.test_invalid_request_errorc                 C   s   | j ttddg d d S )Nr   t.posthog.com/r   r   r"   r   r   r   test_invalid_host"   s   

zTestRequests.test_invalid_hostc              	   C   s6   dt dddddddi}tj|td	}| |d
 d S )Ncreatedi                 i clsz){"created": "2012-03-04T05:06:07.891011"})r   jsondumpsr   r   )r   dataresultr   r   r   test_datetime_serialization'   s   z(TestRequests.test_datetime_serializationc                 C   s:   t  }d|i}tj|td}d|  }| || d S )Nr&   r,   z{"created": "%s"})r   todayr.   r/   r   	isoformatr   )r   r3   r0   r1   expectedr   r   r   test_date_serialization,   s
   z$TestRequests.test_date_serializationc                 C   s*   t tddddgdd}| |jd d S )Nr   r   r   r      r   timeoutr   r   r   r   r   r   test_should_not_timeout3   s   
z$TestRequests.test_should_not_timeoutc                 C   sJ   |  tj tdddddgdd W d    d S 1 sw   Y  d S )Nkeyr   r   r   r   g-C6?r8   )r    requestsReadTimeoutr   r"   r   r   r   test_should_timeout=   s   "z TestRequests.test_should_timeoutc              	   C   s   t  }d|_tdgi i ddd|_tjd|d3 | 	t
}tdd	 W d    n1 s3w   Y  | |jjd | |jjd
 W d    d S 1 sSw   Y  d S )Nr   feature_flagsF)quotaLimitedfeatureFlagsfeatureFlagPayloadserrorsWhileComputingFlagsutf-8posthog.request._session.postreturn_valuefake_key	fake_hostzFeature flags quota limited)r<   Responser   r.   r/   encode_contentmockpatchr    r   r   r   	exceptionstatusmessage)r   mock_responsecmr   r   r   test_quota_limited_responseK   s$   	"z(TestRequests.test_quota_limited_responsec                 C   s~   t  }d|_tddii ddd|_tjd|d t	d	d
}| 
|d ddi W d    d S 1 s8w   Y  d S )Nr   flag1TF)rA   rB   rC   rD   rE   rF   rH   rI   rA   )r<   rJ   r   r.   r/   rK   rL   rM   rN   r   r   )r   rR   responser   r   r   test_normal_decide_response^   s   
"z(TestRequests.test_normal_decide_responseN)__name__
__module____qualname__r   r#   r%   r2   r6   r:   r>   rT   rW   r   r   r   r   r
      s    	
r
   zhost, expected))r   r   )https://t.posthog.com/r[   )t.posthog.comr\   )r$   r$   )#https://us.posthog.com.rg.proxy.comr]   )app.posthog.comr^   )eu.posthog.comr_   )zhttps://app.posthog.comhttps://us.i.posthog.com)zhttps://eu.posthog.comhttps://eu.i.posthog.com)zhttps://us.posthog.comr`   )zhttps://app.posthog.com/r`   )zhttps://eu.posthog.com/ra   )zhttps://us.posthog.com/r`   )Nr`   c                 C   s   t | |ksJ d S )N)r   )hostr5   r   r   r   test_routing_to_custom_hostn   s   rc   )r.   unittestr   r   rM   pytestr<   posthog.requestr   r   r   r   r   posthog.test.test_utilsr	   TestCaser
   markparametrizerc   r   r   r   r   <module>   s    [