@@ -192,24 +192,73 @@ def test_delete_country_not_found(self):
192192
193193 def test_delete_country_with_dependent_states (self ):
194194 """Test that deleting a country with states raises ValueError."""
195- with patch ('data.countries.get_dependent_states_count ' , return_value = 5 ):
195+ with patch ('data.countries.can_delete_country ' , return_value = ( False , "Cannot delete: 5 state(s) depend on this country" ) ):
196196 with pytest .raises (ValueError , match = "Cannot delete: 5 state" ):
197197 countries .delete_country ('US' )
198198
199199 def test_can_delete_country_with_dependencies (self ):
200200 """Test can_delete_country returns False when states exist."""
201- with patch ('data.countries.get_dependent_states_count' , return_value = 3 ):
201+ with patch ('data.countries.get_country_delete_impact' , return_value = {
202+ countries .COUNTRY_CODE : 'US' ,
203+ 'exists' : True ,
204+ 'states' : 3 ,
205+ 'cities' : 8 ,
206+ 'direct_dependency_count' : 3 ,
207+ 'total_dependency_count' : 11 ,
208+ 'blocked' : True ,
209+ }):
202210 can_delete , reason = countries .can_delete_country ('US' )
203211 assert can_delete is False
204212 assert "3 state" in reason
205213
206214 def test_can_delete_country_no_dependencies (self ):
207215 """Test can_delete_country returns True when no states exist."""
208- with patch ('data.countries.get_dependent_states_count' , return_value = 0 ):
216+ with patch ('data.countries.get_dependent_states_count' , return_value = 0 ), \
217+ patch ('data.countries.get_dependent_cities_count' , return_value = 0 ), \
218+ patch ('data.countries.get_country_by_code' , return_value = countries .TEST_COUNTRY ):
209219 can_delete , reason = countries .can_delete_country ('XX' )
210220 assert can_delete is True
211221 assert reason == ""
212222
223+ def test_get_country_delete_impact_zero_dependencies (self ):
224+ """Delete impact reports zero totals when no dependent states or cities exist."""
225+ with patch ('data.countries.get_country_by_code' , return_value = countries .TEST_COUNTRY ), \
226+ patch ('data.countries.get_dependent_states_count' , return_value = 0 ), \
227+ patch ('data.countries.get_dependent_cities_count' , return_value = 0 ):
228+ impact = countries .get_country_delete_impact ('us' )
229+
230+ assert impact == {
231+ countries .COUNTRY_CODE : 'US' ,
232+ 'exists' : True ,
233+ 'states' : 0 ,
234+ 'cities' : 0 ,
235+ 'direct_dependency_count' : 0 ,
236+ 'total_dependency_count' : 0 ,
237+ 'blocked' : False ,
238+ }
239+
240+ def test_get_country_delete_impact_includes_total_cities (self ):
241+ """Delete impact total counts include both direct states and nested cities."""
242+ with patch ('data.countries.get_country_by_code' , return_value = countries .TEST_COUNTRY ), \
243+ patch ('data.countries.get_dependent_states_count' , return_value = 2 ), \
244+ patch ('data.countries.get_dependent_cities_count' , return_value = 7 ):
245+ impact = countries .get_country_delete_impact ('us' )
246+
247+ assert impact == {
248+ countries .COUNTRY_CODE : 'US' ,
249+ 'exists' : True ,
250+ 'states' : 2 ,
251+ 'cities' : 7 ,
252+ 'direct_dependency_count' : 2 ,
253+ 'total_dependency_count' : 9 ,
254+ 'blocked' : True ,
255+ }
256+
257+ def test_get_country_delete_impact_not_found (self ):
258+ """Delete impact returns None when the country does not exist."""
259+ with patch ('data.countries.get_country_by_code' , return_value = None ):
260+ assert countries .get_country_delete_impact ('xx' ) is None
261+
213262 def test_country_exists_true (self ):
214263 """Test checking if a country exists - returns True."""
215264 with patch ('data.countries.get_country_by_code' ) as mock_get :
0 commit comments