55
66import os
77import unittest
8- from unittest .mock import patch
98
109from microsoft_agents_a365 .runtime .environment_utils import (
1110 DEVELOPMENT_ENVIRONMENT_NAME ,
1817
1918
2019class TestEnvironmentUtils (unittest .TestCase ):
21- """Test cases for environment utility functions."""
20+ """Test cases for environment utility functions.
21+
22+ Tests: Constants validation, observability scope retrieval, and environment detection logic.
23+ """
2224
2325 def tearDown (self ):
2426 """Clean up environment variables after each test."""
25- env_vars = ["PYTHON_ENVIRONMENT" ]
26- for var in env_vars :
27- if var in os .environ :
28- del os .environ [var ]
27+ if "PYTHON_ENVIRONMENT" in os .environ :
28+ del os .environ ["PYTHON_ENVIRONMENT" ]
2929
3030 def test_constants (self ):
3131 """Test that environment constants have expected values."""
@@ -44,7 +44,6 @@ def test_get_observability_authentication_scope_returns_prod_scope(self):
4444
4545 def test_is_development_environment_with_no_env_var (self ):
4646 """Test is_development_environment returns False when no environment variable is set."""
47- # Ensure environment variables are not set
4847 if "PYTHON_ENVIRONMENT" in os .environ :
4948 del os .environ ["PYTHON_ENVIRONMENT" ]
5049
@@ -60,16 +59,6 @@ def test_is_development_environment_with_development_env_var(self):
6059
6160 self .assertTrue (result )
6261
63- def test_is_development_environment_case_insensitive (self ):
64- """Test is_development_environment is case-insensitive."""
65- test_cases = ["development" , "DEVELOPMENT" , "DeveLoPMenT" , "Development" ]
66-
67- for env_value in test_cases :
68- with self .subTest (env_value = env_value ):
69- os .environ ["PYTHON_ENVIRONMENT" ] = env_value
70- result = is_development_environment ()
71- self .assertTrue (result )
72-
7362 def test_is_development_environment_with_production_env_var (self ):
7463 """Test is_development_environment returns False when PYTHON_ENVIRONMENT is 'production'."""
7564 os .environ ["PYTHON_ENVIRONMENT" ] = "production"
@@ -78,86 +67,6 @@ def test_is_development_environment_with_production_env_var(self):
7867
7968 self .assertFalse (result )
8069
81- def test_is_development_environment_with_other_env_var (self ):
82- """Test is_development_environment returns False for other environment values."""
83- test_cases = ["staging" , "test" , "preprod" , "custom" ]
84-
85- for env_value in test_cases :
86- with self .subTest (env_value = env_value ):
87- os .environ ["PYTHON_ENVIRONMENT" ] = env_value
88- result = is_development_environment ()
89- self .assertFalse (result )
90-
91- def test_is_development_environment_with_empty_env_var (self ):
92- """Test is_development_environment returns False when PYTHON_ENVIRONMENT is empty."""
93- os .environ ["PYTHON_ENVIRONMENT" ] = ""
94-
95- result = is_development_environment ()
96-
97- self .assertFalse (result )
98-
99- def test_is_development_environment_with_whitespace_env_var (self ):
100- """Test is_development_environment returns False when PYTHON_ENVIRONMENT is whitespace."""
101- os .environ ["PYTHON_ENVIRONMENT" ] = " "
102-
103- result = is_development_environment ()
104-
105- self .assertFalse (result )
106-
107- @patch .dict (os .environ , {"PYTHON_ENVIRONMENT" : "Development" }, clear = False )
108- def test_python_environment_precedence (self ):
109- """Test that PYTHON_ENVIRONMENT takes precedence."""
110- result = is_development_environment ()
111-
112- self .assertTrue (result )
113-
114- def test_default_environment_is_production (self ):
115- """Test that the default environment is production when no env vars are set."""
116- # Ensure no environment variables are set
117- if "PYTHON_ENVIRONMENT" in os .environ :
118- del os .environ ["PYTHON_ENVIRONMENT" ]
119-
120- # The _get_current_environment function should default to PRODUCTION_ENVIRONMENT_NAME
121- result = is_development_environment ()
122-
123- self .assertFalse (result )
124-
125-
126- class TestObservabilityAuthenticationScope (unittest .TestCase ):
127- """Test cases for observability authentication scope."""
128-
129- def test_scope_is_list (self ):
130- """Test that the scope is returned as a list."""
131- result = get_observability_authentication_scope ()
132-
133- self .assertIsInstance (result , list )
134-
135- def test_scope_contains_single_value (self ):
136- """Test that the scope list contains exactly one value."""
137- result = get_observability_authentication_scope ()
138-
139- self .assertEqual (len (result ), 1 )
140-
141- def test_scope_value_is_string (self ):
142- """Test that the scope value is a string."""
143- result = get_observability_authentication_scope ()
144-
145- self .assertIsInstance (result [0 ], str )
146-
147- def test_scope_value_format (self ):
148- """Test that the scope value has the correct format."""
149- result = get_observability_authentication_scope ()
150-
151- self .assertTrue (result [0 ].startswith ("https://" ))
152- self .assertTrue (result [0 ].endswith (".default" ))
153-
154- def test_scope_consistency (self ):
155- """Test that multiple calls return the same scope."""
156- result1 = get_observability_authentication_scope ()
157- result2 = get_observability_authentication_scope ()
158-
159- self .assertEqual (result1 , result2 )
160-
16170
16271if __name__ == "__main__" :
16372 unittest .main ()
0 commit comments