
    gA                         d dl Z d dlmZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZ d	Zd
Z G d de j*                        Z G d de j*                        Zy)    N)datedatetime	timedelta)Decimal)Optional)UUID)tzutc)	BaseModel)utils+kOOlRy2QlMY9jHZQv0bKz0FZyazBUoY8Arj0lFVNjs4
random_keyc                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)		TestUtilsc                    t        j                         }t        j                  t                     }| j                  t	        j
                  |             | j                  t	        j
                  |             t	        j                  |      }| j                  t	        j
                  |             t	        j                  |      }| j                  ||       y )N)tz)	r   nowr	   
assertTruer   is_naiveassertFalseguess_timezoneassertEqual)selfr   utcnowfixedshouldnt_be_editeds        L/var/www/openai/venv/lib/python3.12/site-packages/posthog/test/test_utils.pytest_timezone_utilszTestUtils.test_timezone_utils   s    lln)s+,/0$$S)./"11&9!34    c           
         t        d      t        j                  d      t        j                         dddddd d	}t        d      t        d	
      g dd}t        |j                               }|j                  |j                                |j                         }t        j                  |       | j                  |j                         |       | j                  t        j                  t        d            d       y )Nz0.142857wooi    g       @T)	decimalunicoder   longintegerfloatboolstrnonezThis should show up   )microseconds)r!         )	exceptionr   list 12345678123456781234567812345678z$12345678-1234-5678-1234-567812345678)r   sixur   r   	Exceptionr   dictitemsupdatekeysr   cleanr   r   )r   simplecomplicatedcombinedpre_clean_keyss        r   
test_cleanzTestUtils.test_clean   s    z*uuU|LLN

 ##89"3
 '))+,!H.9 	T*L%MNPvwr   c                     t        ddd      t        j                         d}| j                  |t	        j
                  |             y )Ni  r!   )	birthdateregistration)r   r   r   r   r   r8   )r   dict_with_datess     r   test_clean_with_dateszTestUtils.test_clean_with_dates=   s:    dAq)$OO-
 	%++o*FGr   c                 |    t         j                  rt        d      }nt        d      }t	        j
                  |       y )N
   )r1   PY3bytes	bytearrayr   r8   )r   items     r   
test_byteszTestUtils.test_bytesD   s'    779DR=DDr   c                     t        j                  d dd      }| j                  |d   d       d|v r| j                  |d   d        y y )Nc                     | S N )xs    r   <lambda>z)TestUtils.test_clean_fn.<locals>.<lambda>M   s    qr      )fnnumberrR   rQ   )r   r8   r   )r   cleaneds     r   test_clean_fnzTestUtils.test_clean_fnL   sJ    ++[A>?*A.7?WT]D1 r   c                     | j                  dt        j                  d             | j                  dt        j                  d             y )Nzhttp://posthog.iozhttp://posthog.io/)r   r   remove_trailing_slash)r   s    r   test_remove_slashzTestUtils.test_remove_slashS   s<    ,e.I.IJ^._`,e.I.IJ].^_r   c                     G d dt                G d dt              } G fddt               }| j                  t        j                   dd	            ddd d
       | j                  t        j                   |dd	            ddd	       | j                  t        j                   | ddd
                  ddddd
i        G d d      }| j                  t        j                  d |       i      i        y )Nc                   6    e Zd ZU eed<   eed<   dZee   ed<   y).TestUtils.test_clean_pydantic.<locals>.ModelV2foobarNbaz)__name__
__module____qualname__r(   __annotations__intr]   r   rM   r   r   ModelV2rZ   X   s    HH!%C#%r   rc   c                   "    e Zd ZU eed<   eed<   y).TestUtils.test_clean_pydantic.<locals>.ModelV1r[   r\   N)r^   r_   r`   rb   ra   r(   rM   r   r   ModelV1re   ]   s    HHr   rf   c                       e Zd ZU W  ed<   y)2TestUtils.test_clean_pydantic.<locals>.NestedModelr[   N)r^   r_   r`   ra   )rc   s   r   NestedModelrh   a   s    Lr   ri   1r,   )r[   r\   )r[   r\   r]   r!   23)r[   r[   c                       e Zd Zd Zy),TestUtils.test_clean_pydantic.<locals>.Dummyc                      y rL   rM   )r   required_params     r   
model_dumpz7TestUtils.test_clean_pydantic.<locals>.Dummy.model_dumpk   s    r   N)r^   r_   r`   rq   rM   r   r   Dummyrn   j   s    r   rr   test)r
   BaseModelV1r   r   r8   )r   rf   ri   rr   rc   s       @r   test_clean_pydanticzTestUtils.test_clean_pydanticW   s    	&i 	&
	k 		) 	 	W!%<=sST]a?bcW%<=qQT?UVKKCQC(HIJU\_hiruTvLw	
	 	
 	feg%67<r   N)
r^   r_   r`   r   r=   rB   rI   rT   rW   ru   rM   r   r   r   r      s(    
5x<H2`=r   r   c                       e Zd Zd Zy)TestSizeLimitedDictc                    d}t        j                  |d       }t        d      D ]  }|||<   | j                  ||   |       | j                  t	        |      ||z  dz          ||z  dk(  sG| j                  |j                  |dz
               | j                  |j                  |dz
               | j                  |j                  |dz
               | j                  |j                  |dz
                y )	NrD   c                      y)NrM   )_s    r   rO   z<TestSizeLimitedDict.test_size_limited_dict.<locals>.<lambda>u   s    rr   d   r!   r   r-      	   )r   SizeLimitedDictranger   lenassertIsNoneget)r   sizevaluesis       r   test_size_limited_dictz*TestSizeLimitedDict.test_size_limited_dicts   s    &&t\:sAF1IVAY*S[!d(Q,74x1}!!&**QU"34!!&**QU"34!!&**QU"34!!&**QU"34 r   N)r^   r_   r`   r   rM   r   r   rw   rw   r   s    5r   rw   )unittestr   r   r   r"   r   typingr   uuidr   r1   dateutil.tzr	   pydanticr
   pydantic.v1rt   posthogr   TEST_API_KEYFAKE_TEST_API_KEYTestCaser   rw   rM   r   r   <module>r      sX     . .    
   0 <  ]=!! ]=@5(++ 5r   