
    wBf                    \   d Z ddlmZ ddl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 ddlmZ dd	lmZ dd
lmZ ddlmZ erddlmZ ddlmZ ddlmZ dZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZddZ G d d      Z	 	 d 	 	 	 	 	 d!dZ  G d d      Z!d"dZ"y)#z;Collection of helper functions used in conda.notices tests.    )annotationsN)chain)Path)TYPE_CHECKING   )get_channel_objs)get_notices_cache_file)get_channel_name_and_urls)ChannelNoticeResponse)Sequence)mock)Contextz:Here is an example message that will be displayed to usersc           
     Z   |xs7 t         j                   j                  t         j                  j                        }|xs |t        j                  d      z   }d| D cg c]A  }t        t        j                               |||j                         |j                         dC c}iS c c}w )N   )daysnotices)idmessagelevel
created_at
expired_at)	datetimenowtimezoneutc	timedeltastruuiduuid4	isoformat)messagesr   r   r   r   s        =lib/python3.12/site-packages/conda/testing/notices/helpers.pyget_test_noticesr#      s     Kx0044X5F5F5J5JKJFzH,>,>A,FFJ 	 $	
  $**,'"(224(224	
 	
s   AB(c                    d }fd}t         |        |             t        fdt        d      D               |        j                  _        y)zCAdds any number of MockResponse to MagicMock object as side_effectsc               3  *   K   	 t        di        w)Ni  MockResponse     r"   forever_404z%add_resp_to_mock.<locals>.forever_404<   s     sB'' s   c               3  .   K   t                y w)N)	raise_excr&   )messages_jsonr,   status_codes   r"   one_200z!add_resp_to_mock.<locals>.one_200@   s     ;KKs   c              3  4   K   | ]  }t                y wN)next).0_chns     r"   	<genexpr>z#add_resp_to_mock.<locals>.<genexpr>D   s     *I49*Is   d   N)r   tuplerangegetside_effect)mock_sessionr.   r-   r,   r*   r/   r5   s    ```  @r"   add_resp_to_mockr=   4   s?    (L 	;=
)C%**IeCj*I%ILN"r)   c                    t        ||      D ]D  \  }}| j                  |      j                  d      5 }t        j                  ||       ddd       F y# 1 sw Y   QxY w)z,Creates the cache files that we use in testswN)zipjoinpathopenjsondump)	cache_dircache_filesmessages_json_seqmessage_jsonfilefps         r"   create_notice_cache_filesrK   G   sc     ""3[A (d%**3/ 	(2IIlB'	( 	((	( 	(s   AA	c                    t               }t        j                  ||j                         j                  |j                         j
                  | z
  f       y)z
    Allows for offsetting the mtime of the notices cache file. This is often
    used to mock an older creation time the cache file.
    )timesN)r	   osutimestatst_atimest_mtime)mtime_offset
cache_files     r"   offset_cache_file_mtimerU   R   sB    
 ()JHH )):??+<+E+E+TUr)   c                      e Zd ZdZd Zy)	DummyArgsz7Dummy object that sets all kwargs as object properties.c                \    d| _         |j                         D ]  \  }}t        | ||        y )NT)no_ansi_colorsitemssetattr)selfkwargskeyvals       r"   __init__zDummyArgs.__init__a   s/    " 	$HCD#s#	$r)   N)__name__
__module____qualname____doc__r`   r(   r)   r"   rW   rW   ^   s
    A$r)   rW   c                    | j                   dk(  sJ || j                  v sJ |D ]%  }|r|| j                  vrJ || j                  v r%J  y)zc
    Tests a run of notices decorator where we expect to see the messages
    print to stdout.
     N)errout)capturedr!   
dummy_mesgnot_inmesgs        r"   *notices_decorator_assert_message_in_stdoutrm   h   s^     <<2%%% (x||+++8<<'''	(r)   c                      e Zd ZddZd Zy)r'   c                .    || _         || _        || _        y r1   )r.   	json_datar,   )r\   r.   rp   r,   s       r"   r`   zMockResponse.__init__}   s    &""r)   c                H    | j                   rt        d      | j                  S )NError)r,   
ValueErrorrp   )r\   s    r"   rC   zMockResponse.json   s    >>W%%~~r)   NF)ra   rb   rc   r`   rC   r(   r)   r"   r'   r'   |   s    #
r)   r'   c                N    t        t        |             }t        d |D              S )zBReturns the filenames of the cache files that will be searched forc              3  t   K   | ]0  \  }}t        j                  |t        d             j                   2 yw)rf   N)r   get_cache_keyr   name)r3   urlrx   s      r"   r6   z-get_notice_cache_filenames.<locals>.<genexpr>   s3      C 	++Cb:??s   68)r
   r   r8   )ctxchannel_urls_and_namess     r"   get_notice_cache_filenamesr|      s-    67G7LM /  r)   )infoNN)
r!   Sequence[str]r   
str | Noner   datetime.datetime | Noner   r   returndictrt   )
r<   zmock.MagicMockr.   intr-   r   r,   boolr   None)rE   r   rF   r~   rG   zSequence[dict]r   r   )r   r   )NF)r!   r~   rj   r   rk   r   )rz   r   r   z
tuple[str])#rd   
__future__r   r   rC   rN   r   	itertoolsr   pathlibr   typingr   models.channelr   notices.cacher	   notices.corer
   notices.typesr   r   unittestr   base.contextr   DEFAULT_NOTICE_MESGr#   r=   rK   rU   rW   rm   r'   r|   r(   r)   r"   <module>r      s-   B "   	      . 3 5 2'R 
 +/+/	 ) )	
 
6 	J JJ J 	J
 
J&((( &( 
	(	$ $ "	(( ( 	((	 	r)   