@@ -184,6 +184,68 @@ def test_csv_process_pass_connectivity_test_flag(self, mock_sync_devices_command
184184 self .assertEqual (job .ip_address_inventory ["172.23.0.8" ]["platform" ], None )
185185 self .assertEqual (log_level , 10 )
186186
187+ def test_add_content_type_during_csv_sync (self ):
188+ """Test successful addition of content type to location type during CSV sync."""
189+ # Create a location type without Device content type
190+ location_type_without_device = self .testing_objects ["location_2" ].location_type
191+ location_type_without_device .content_types .clear ()
192+ location_type_without_device .validated_save ()
193+
194+ self .assertFalse (location_type_without_device .content_types .filter (app_label = "dcim" , model = "device" ).exists ())
195+
196+ # Run CSV processing which should add the content type
197+ onboarding_job = jobs .SSOTSyncDevices ()
198+ with open ("nautobot_device_onboarding/tests/fixtures/onboarding_csv_fixture.csv" , "rb" ) as csv_file :
199+ onboarding_job ._process_csv_data (csv_file = csv_file ) # pylint: disable=protected-access
200+
201+ # Verify content type was added
202+ location_type_without_device .refresh_from_db ()
203+ self .assertTrue (location_type_without_device .content_types .filter (app_label = "dcim" , model = "device" ).exists ())
204+
205+ @patch ("nautobot_device_onboarding.diffsync.adapters.sync_devices_adapters.sync_devices_command_getter" )
206+ def test_add_content_type_during_manual_sync (self , device_data ):
207+ """Test that content type is added when running manual sync with location."""
208+ device_data .return_value = sync_devices_fixture .sync_devices_mock_data_valid
209+
210+ # Create a location type without Device content type
211+ location_type_without_device = self .testing_objects ["location_2" ].location_type
212+ location_type_without_device .content_types .clear ()
213+ location_type_without_device .validated_save ()
214+
215+ self .assertFalse (location_type_without_device .content_types .filter (app_label = "dcim" , model = "device" ).exists ())
216+
217+ job_form_inputs = {
218+ "debug" : True ,
219+ "connectivity_test" : False ,
220+ "dryrun" : False ,
221+ "csv_file" : None ,
222+ "location" : self .testing_objects ["location_2" ].pk ,
223+ "namespace" : self .testing_objects ["namespace" ].pk ,
224+ "ip_addresses" : "10.1.1.10,10.1.1.11" ,
225+ "port" : 22 ,
226+ "timeout" : 30 ,
227+ "set_mgmt_only" : True ,
228+ "update_devices_without_primary_ip" : True ,
229+ "device_role" : self .testing_objects ["device_role" ].pk ,
230+ "device_status" : self .testing_objects ["status" ].pk ,
231+ "interface_status" : self .testing_objects ["status" ].pk ,
232+ "ip_address_status" : self .testing_objects ["status" ].pk ,
233+ "secrets_group" : self .testing_objects ["secrets_group" ].pk ,
234+ "platform" : None ,
235+ "memory_profiling" : False ,
236+ }
237+ job_result = create_job_result_and_run_job (
238+ module = "nautobot_device_onboarding.jobs" , name = "SSOTSyncDevices" , ** job_form_inputs
239+ )
240+ self .assertEqual (
241+ job_result .status ,
242+ JobResultStatusChoices .STATUS_SUCCESS ,
243+ (job_result .traceback , list (job_result .job_log_entries .values_list ("message" , flat = True ))),
244+ )
245+ # Verify content type was added
246+ location_type_without_device .refresh_from_db ()
247+ self .assertTrue (location_type_without_device .content_types .filter (app_label = "dcim" , model = "device" ).exists ())
248+
187249
188250class SSOTSyncNetworkDataTestCase (TransactionTestCase ):
189251 """Test SSOTSyncNetworkData class."""
0 commit comments