
    ceZ0                     @   d dl Z d dlmZ d dlm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  G d	 d
ej                        Z G d dej                        Z G d dej                        Zd Z ed      dde	j&                  dfie	j&                  dfe	j(                  dfe	j*                  dfe	j,                  dfe	j.                  dfe	j0                  dfe	j2                  dfe	j4                  dfe	j6                  g dfd	dd ed      dd d!e	j&                  d!fiid ed"      d"d e	j&                  dfe	j&                  d#fd$id ed%      d%d e	j&                  dfe	j&                  dfe	j&                  d&fdidiZd' Z G d( d)ej                        Zy)*    N)base)	HTTPError)
_list_opts)cfg)fixture)sources)_uric                   6     e Zd Z fdZd Zd Zd Zd Z xZS )TestProcessingSourcesc                     t         t        |           t        j                         | _        | j                  t        j                  | j
                              | _	        y N)
superr   setUpr   
ConfigOptsconf
useFixturer   Configconf_fixtureself	__class__s    @/usr/lib/python3/dist-packages/oslo_config/tests/test_sources.pyr   zTestProcessingSources.setUp#   s=    #T02NN$	 OOGNN499,EF    c                     t         j                  j                  j                  | j                  d      5 }t        d      |_        | j	                  g        d d d        y # 1 sw Y   y xY w)N_open_source_from_opt_groupshould not be called)r   mockpatchobjectr   AssertionErrorside_effectr   open_sources     r   test_no_sources_defaultz-TestProcessingSources.test_no_sources_default(   sS    YY__##		-/ 	2=&45K&LK#IIbM		 	 	s   "A  A)c                    | j                   j                  g        t        j                  j                  j                  | j                  d      5 }t        d      |_        | j                  g        d d d        y # 1 sw Y   y xY w)Nconfig_sourcer   r   )	r   configr   r   r   r   r   r    r!   r"   s     r   test_no_sourcesz%TestProcessingSources.test_no_sources/   sq       	! 	
 YY__##		-/ 	2=&45K&LK#IIbM		 	 	s   "A<<Bc                    | j                   j                  dg       t        j                  j                  j                  | j                  d      5 }| j                  g        |j                  d       d d d        y # 1 sw Y   y xY w)Nmissing_sourcer&   r   )r   r(   r   r   r   r   r   assert_called_once_withr"   s     r   test_source_namedz'TestProcessingSources.test_source_named9   sy      +, 	! 	
 YY__##		-/ 	B2=IIbM//0@A		B 	B 	Bs   #A>>Bc                    | j                   j                  ddg       t        j                  j                  j                  | j                  d      5 }| j                  g        |j                  t        j                  j                  d      t        j                  j                  d      g       d d d        y # 1 sw Y   y xY w)Nsource1source2r&   r   )	r   r(   r   r   r   r   r   assert_has_callscallr"   s     r   test_multiple_sources_namedz1TestProcessingSources.test_multiple_sources_namedC   s      $i0 	! 	
 YY__##		-/ 	2=IIbM((		y)		y)* 		 	 	s   AB;;C)	__name__
__module____qualname__r   r$   r)   r-   r3   __classcell__r   s   @r   r   r      s    G
Br   r   c                   0     e Zd Z fdZd Zd Zd Z xZS )TestLoadingc                     t         t        |           t        j                         | _        | j                  t        j                  | j
                              | _	        y r   )
r   r:   r   r   r   r   r   r   r   r   r   s    r   r   zTestLoading.setUpW   s<    k4&(NN$	 OOGNN499,EFr   c                 \    | j                   j                  d      }| j                  |       y )Nr+   )r   r   assertIsNoner   sources     r   test_source_missingzTestLoading.test_source_missing\   s%    667GH&!r   c                     | j                   j                  dd       | j                  j                  d      }| j	                  |       y )Nmissing_driverfoo)group
not_driverr   load_raw_valuesr   r   r=   r>   s     r   test_driver_missingzTestLoading.test_driver_missinga   sH     	))" 	* 	
 667GH&!r   c                     | j                   j                  dd       | j                  j                  d      }| j	                  |       y )Nunknown_driver"very_unlikely_to_exist_driver_namerD   driverrF   r>   s     r   test_unknown_driverzTestLoading.test_unknown_driverk   sF    ))"7 	* 	
 667GH&!r   )r4   r5   r6   r   r@   rH   rN   r7   r8   s   @r   r:   r:   Q   s    G
"
""r   r:   c                   <     e Zd Z fdZd Zd Zd Zd Zd Z xZ	S )"TestEnvironmentConfigurationSourcec                    t         t        |           t        j                         | _        | j                  t        j                  | j
                              | _	        | j
                  j                  t        j                  d      d       | j
                  j                  t        j                  dd      d       d }| j                  |       y )NbarrC   bazz	^[a-z].*$)regexc                  Z    dD ]&  } | t         j                  v st         j                  | = ( y )N)OS_FOO__BAROS_FOO__BAZ)osenviron)envs    r   cleanupz9TestEnvironmentConfigurationSource.setUp.<locals>.cleanup~   s(    5 ("**$

3(r   )r   rP   r   r   r   r   r   r   r   r   register_optStrOpt
addCleanup)r   r[   r   s     r   r   z(TestEnvironmentConfigurationSource.setUpw   s    0$=?NN$	 OOGNN499,EF		szz%0%8		szz%{CUK	(
 	 r   c                     | j                  g        d}|t        j                  d<   | j                  || j                   d   d          y )NargsgoodbyerV   rC   rR   )r   rX   rY   assertEqualr   	env_values     r   test_simple_environment_getz>TestEnvironmentConfigurationSource.test_simple_environment_get   sA    		r		$-

=!DIIe$4U$;<r   c                 L   d}d}| j                  g        | j                  j                  d|       | j                  || j                   d   d          | j                   j	                          |t
        j                  d<   | j                  || j                   d   d          y )Nhellorb   r`   rC   rD   rR   rR   rV   )r   r   rG   rc   reload_config_filesrX   rY   r   
file_valuere   s      r   test_env_beats_filesz7TestEnvironmentConfigurationSource.test_env_beats_files   s    
			r	)) 	* 	

 	TYYu%5e%<=		%%'$-

=!DIIe$4U$;<r   c                     d}d}|t         j                  d<   | j                  j                  t	        j
                  d      d       | j                  d|z  g       | j                  || j                  d   d          y )Nrb   clirV   rR   rC   z--foo=%sr`   )rX   rY   r   register_cli_optr   r]   rc   )r   re   	cli_values      r   test_cli_beats_envz5TestEnvironmentConfigurationSource.test_cli_beats_env   sk    		$-

=!		""3::e#4e<		
Y./	0DIIe$4U$;<r   c                 t   d}d}|t         j                  d<   | j                  g d       | j                  j	                  d|       | j                  || j                  d   d          | j                  j                          | j                  g d	       | j                  || j                  d   d          y )
Nrh   rb   rV   F)ra   use_envrC   ri   rR   T)rX   rY   r   r   rG   rc   resetrk   s      r   test_use_env_false_allows_fileszBTestEnvironmentConfigurationSource.test_use_env_false_allows_files   s    
	$-

=!		r5	))) 	* 	

 	TYYu%5e%<=				r4	(DIIe$4U$;<r   c                     | j                  g        d}|t        j                  d<   t        j                  t
        j                        5  | j                   d   d    d d d        y # 1 sw Y   y xY w)Nr`   ABCrW   rC   rS   )r   rX   rY   	testtoolsExpectedExceptionr   ConfigSourceValueErrorrd   s     r   test_invalid_envz3TestEnvironmentConfigurationSource.test_invalid_env   s]    		r		$-

=!(()C)CD 	$IIeU#	$ 	$ 	$s   A''A0)
r4   r5   r6   r   rf   rm   rr   rv   r|   r7   r8   s   @r   rP   rP   u   s!    !====$r   rP   c                 $    dj                  |       S )Nzhttps://oslo.config/{}.conf)format)names    r   make_urir      s    (//55r   typesrC   rR   za nice stringT*   gQ	@z	127.0.0.1i  zwww.openstack.orgzhttps://www.openstack.org)abcdefghi)	opt_stropt_boolopt_int	opt_floatopt_ipopt_portopt_hostopt_uri	opt_multi)DEFAULTtest)r   dataini_1r   r   ini_2r   )r   r   ini_3r   c                 :   t         |    d   }d}|j                         D ]y  }|dj                  |      z  }||   j                         D ]M  \  }\  }}|t        j
                  k(  r|D ]  }	|dj                  ||	      z  } 9|dj                  ||      z  }O { |S )Nr    z[{}]
z{} = {}
)_extra_configskeysr~   itemsr   MultiStrOpt)
urira   kwargsoptsresultgotvis
             r   opts_to_inir      s    #v&DF YY[ 3(//!$$a 	3IAv1COO# 7Ak00A66F7 +,,Q22	33 Mr   c                        e Zd Z fdZd Zd Z ej                         d        Ze	j                  j                  de      d        Ze	j                  j                  de      d        Zd	 Z xZS )
URISourceTestCasec                     t         t        |           t        j                         | _        | j                  t        j                  | j
                              | _	        y r   )
r   r   r   r   r   r   r   r   r   r   r   s    r   r   zURISourceTestCase.setUp  s=    ,.NN$	 OOGNN499,EFr   c                     |j                         D ]I  }||   j                         D ]1  \  }\  }}| j                  j                   ||      |dk7  r|nd        3 K y )Nr   )r   r   r   r\   )r   r   r   r   r   _s         r   _register_optsz URISourceTestCase._register_opts	  s\     	LA!!W]]_ L	6Aq		&&qt!y.QdKL	Lr   c                     | j                   j                  dd       | j                  j                  d      }| j	                  |       y )Nincomplete_ini_driverremote_filerL   rF   r>   s     r   test_incomplete_driverz(URISourceTestCase.test_incomplete_driver  sH     	)))  	* 	
 667NO&!r   c           
      6   |j                  dd       | j                  t        t        j                  d       |j                  dd       t        j                  d      }| j                  d|j                  dd	t        j                  d	            d
          y )Nzhttps://bad.urii  )status_codezhttps://good.uriz[DEFAULT]
foo=bar
)textrR   r   rC   r   )getassertRaisesr   r	   URIConfigurationSourcerc   r   r]   )r   mr?   s      r   test_fetch_uriz URISourceTestCase.test_fetch_uri  s    	S1t224E	G 	
 '=>,,-?@6::i

50AB1E	Gr   z:oslo_config.sources._uri.URIConfigurationSource._fetch_uri)r!   c                    d}t        |      }| j                  j                  |d|       | j                  j                  |g       | j	                  | j
                  j                  g        | j
                  j                          | j                  | j
                  j                  d   t        j                         | j
                  j                  |      }| j                  t        |   d          | j                  t        j                   |j#                  ddt%        j&                  d            d          t        |   d   D ]  }t        |   d   |   j)                         D ]|  \  }\  }}| j	                  t+        |      t+        |j#                  || ||            d                | j	                  ||dk7  r| j
                  |   |   n| j
                  |          ~  y )	Nr   r   rD   rM   r   r&   r   r   r   rR   )r   r   rG   r(   rc   r   _sources_load_alternative_sourcesassertIsInstancer	   r   r   r   r   assertIsr   _NoValuer   r   r]   r   str)	r   mock_fetch_urirD   r   r?   r   r   r   r   s	            r   test_configuration_sourcez+URISourceTestCase.test_configuration_source&  s    uo))  	* 	

 	  w 7 	++R0		++-dii003"99	; 66u=N3/78 	g&&jjE3::e3DEaH	J  $V, 	/A+C08;AAC /	6Aq  QVZZ1ad-CA-F)GH  45N1a!%1//	/r   c                    g d}t        d      }|D ])  }| j                  j                  |dt        |             + | j                  j                  |       | j                  j                          | j                  t        |   d          t        |   d   d   D ]!  }| j                  || j                  |          # y )N)r   r   r   r   r   r   r&   r   r   )	r   r   rG   r(   r   r   r   r   rc   )r   r   groupsr   rD   options         r   #test_multiple_configuration_sourcesz5URISourceTestCase.test_multiple_configuration_sourcesJ  s     -w 	E--$UO . 	 	  v 6		++- 	N3/78
 %S)&1)< 	8FVTYYv%67	8r   c                    d }t        j                         D ]  }|d   	|d   j                  dk(  s|} n | j                  |       | j	                  t        j                         j                         |d   dd         y )Nr   sample_remote_file_source   )r   	list_optsr   assertIsNotNonerc   r	   URIConfigurationSourceDriverlist_options_for_discovery)r   discovered_grouprD   s      r   test_list_optsz URISourceTestCase.test_list_optsd  s    ))+ 	EQx#8==$??',$		 	-.--/JJLQ#	
r   )r4   r5   r6   r   r   r   requests_mockr   r   r   r   r   r   r   r   r7   r8   s   @r   r   r     s    G
L" ]
G 
G 
YY__D  !/!/B 
YY__D  !8!8.
r   r   )rX   oslotestr   requestsr   r   ry   oslo_configr   r   r   r   oslo_config.sourcesr	   BaseTestCaser   r:   rP   r   r]   BoolOptIntOptFloatOptIPOptPortOptHostnameOptURIOptr   r   r   r    r   r   <module>r      s   
     "    $3D-- 3l!"$## !"HC$):): C$L6
 W 

E*  JJ8 [[$/JJ+!llD199k2 [[#. __.ABJJ(CD!oo/DE
	
& W

E*
 W

E*

E*
 W

E*

E*

E*
	K/d"p
)) p
r   