U
    b                     @  s  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dZd-ddddddddZd.ddddddddZddddddd ZG d!d" d"Zd/dddd#d$d%ZG d&d' d'Zd(d)d*d+d,ZdS )0    )annotationsN)chain)Path)OptionalSequence)mock)Context)get_channel_name_and_urls)ChannelNoticeResponse)get_channel_objsz:Here is an example message that will be displayed to usersinfozSequence[str]zOptional[str]zOptional[datetime.datetime]dict)messageslevel
created_at
expired_atreturnc                   sF    pt j t jj p& t jdd dt fdd| D iS )N   )ZdaysZnoticesc                 3  s.   | ]&}t t |   d V  qdS ))idmessager   r   r   N)struuidZuuid4Z	isoformat).0r   r   r   r    <lib/python3.8/site-packages/conda/testing/notices/helpers.py	<genexpr>    s   
z#get_test_notices.<locals>.<genexpr>)datetimeZnowtimezoneZutcZ	timedeltalist)r   r   r   r   r   r   r   get_test_notices   s     r    Fzmock.MagicMockintboolNone)mock_sessionstatus_codemessages_json	raise_excr   c                   sF   dd }fdd}t | |  t fddtdD | _dS )	zCAdds any number of MockResponse to MagicMock object as side_effectsc                   s  s   t di V  q d S )Ni  MockResponser   r   r   r   forever_4045   s    z%add_resp_to_mock.<locals>.forever_404c                   3  s   t  dV  d S )N)r'   r(   r   )r&   r'   r%   r   r   one_2009   s    z!add_resp_to_mock.<locals>.one_200c                 3  s   | ]}t  V  qd S N)next)r   _)chnr   r   r   =   s     z#add_resp_to_mock.<locals>.<genexpr>d   N)r   tuplerangeZside_effect)r$   r%   r&   r'   r*   r+   r   )r/   r&   r'   r%   r   add_resp_to_mock-   s    r3   r   zSequence[dict])	cache_dircache_filesmessages_json_seqr   c              
   C  sD   t ||D ]4\}}| |}t|d}t|| W 5 Q R X q
dS )z,Creates the cache files that we use in testswN)zipZjoinpathopenjsondump)r4   r5   r6   Zmessage_jsonfileZ	cache_keyfpr   r   r   create_notice_cache_files@   s    
r>   c                   @  s   e Zd ZdZdd ZdS )	DummyArgsz@
    Dummy object that sets all kwargs as object properties
    c                 K  s(   d| _ | D ]\}}t| || qd S )NT)Zno_ansi_colorsitemssetattr)selfkwargskeyvalr   r   r   __init__Q   s    zDummyArgs.__init__N)__name__
__module____qualname____doc__rF   r   r   r   r   r?   L   s   r?   )r   
dummy_mesgnot_inc                 C  sL   | j dkst|| jkst|D ]&}|r8|| jksFtq || jks tq dS )zc
    Tests a run of notices decorator where we expect to see the messages
    print to stdout.
     N)errAssertionErrorout)Zcapturedr   rK   rL   Zmesgr   r   r   *notices_decorator_assert_message_in_stdoutX   s    rQ   c                   @  s   e Zd ZdddZdd ZdS )r)   Fc                 C  s   || _ || _|| _d S r,   )r%   	json_datar'   )rB   r%   rR   r'   r   r   r   rF   j   s    zMockResponse.__init__c                 C  s   | j rtd| jS )NError)r'   
ValueErrorrR   )rB   r   r   r   r:   o   s    zMockResponse.jsonN)F)rG   rH   rI   rF   r:   r   r   r   r   r)   i   s   
r)   r   z
tuple[str])ctxr   c                 C  s   t t| }tdd |D S )zBReturns the filenames of the cache files that will be searched forc                 s  s$   | ]\}}t |td jV  qdS )rM   N)r
   Zget_cache_keyr   name)r   ZurlrV   r   r   r   r   y   s   z-get_notice_cache_filenames.<locals>.<genexpr>)r	   r   r1   )rU   Zchannel_urls_and_namesr   r   r   get_notice_cache_filenamesu   s    rW   )r   NN)F)NF)Z
__future__r   r   r   r:   	itertoolsr   pathlibr   typingr   r   Zunittestr   Zconda.base.contextr   Zconda.notices.corer	   Zconda.notices.typesr
   Zconda.models.channelr   ZDEFAULT_NOTICE_MESGr    r3   r>   r?   rQ   r)   rW   r   r   r   r   <module>   s2          