@@ -485,3 +485,76 @@ def setUpTestData(cls):
485485 'end_of_support' : '2050-01-01' ,
486486 },
487487 ]
488+
489+ # Additional device types for null date tests
490+ cls .device_type_for_null_test = DeviceType .objects .create (
491+ model = 'Device Type Null Test' ,
492+ manufacturer = manufacturer ,
493+ slug = 'device-type-null' ,
494+ )
495+ cls .device_type_for_explicit_null = DeviceType .objects .create (
496+ model = 'Device Type Explicit Null' ,
497+ manufacturer = manufacturer ,
498+ slug = 'device-type-explicit-null' ,
499+ )
500+ cls .device_type_for_update_null = DeviceType .objects .create (
501+ model = 'Device Type Update Null' ,
502+ manufacturer = manufacturer ,
503+ slug = 'device-type-update-null' ,
504+ )
505+
506+ def test_create_lifecycle_with_omitted_dates (self ):
507+ """Test creating a hardware lifecycle with omitted date fields."""
508+ self .add_permissions ('netbox_lifecycle.add_hardwarelifecycle' )
509+ url = reverse ('plugins-api:netbox_lifecycle-api:hardwarelifecycle-list' )
510+ data = {
511+ 'assigned_object_id' : self .device_type_for_null_test .pk ,
512+ 'assigned_object_type' : 'dcim.devicetype' ,
513+ }
514+ response = self .client .post (url , data , format = 'json' , ** self .header )
515+ self .assertHttpStatus (response , status .HTTP_201_CREATED )
516+ self .assertIsNone (response .data ['end_of_sale' ])
517+ self .assertIsNone (response .data ['end_of_support' ])
518+ self .assertIsNone (response .data ['end_of_maintenance' ])
519+ self .assertIsNone (response .data ['end_of_security' ])
520+
521+ def test_create_lifecycle_with_explicit_null_dates (self ):
522+ """Test creating a hardware lifecycle with explicit null values for dates."""
523+ self .add_permissions ('netbox_lifecycle.add_hardwarelifecycle' )
524+ url = reverse ('plugins-api:netbox_lifecycle-api:hardwarelifecycle-list' )
525+ data = {
526+ 'assigned_object_id' : self .device_type_for_explicit_null .pk ,
527+ 'assigned_object_type' : 'dcim.devicetype' ,
528+ 'end_of_sale' : None ,
529+ 'end_of_support' : None ,
530+ 'end_of_maintenance' : None ,
531+ 'end_of_security' : None ,
532+ }
533+ response = self .client .post (url , data , format = 'json' , ** self .header )
534+ self .assertHttpStatus (response , status .HTTP_201_CREATED )
535+ self .assertIsNone (response .data ['end_of_sale' ])
536+ self .assertIsNone (response .data ['end_of_support' ])
537+ self .assertIsNone (response .data ['end_of_maintenance' ])
538+ self .assertIsNone (response .data ['end_of_security' ])
539+
540+ def test_update_lifecycle_dates_to_null (self ):
541+ """Test updating a hardware lifecycle to set dates to null."""
542+ self .add_permissions ('netbox_lifecycle.change_hardwarelifecycle' )
543+ # Create lifecycle with dates
544+ lifecycle = HardwareLifecycle .objects .create (
545+ assigned_object = self .device_type_for_update_null ,
546+ end_of_sale = '2030-01-01' ,
547+ end_of_support = '2035-01-01' ,
548+ )
549+ url = reverse (
550+ 'plugins-api:netbox_lifecycle-api:hardwarelifecycle-detail' ,
551+ kwargs = {'pk' : lifecycle .pk },
552+ )
553+ data = {
554+ 'end_of_sale' : None ,
555+ 'end_of_support' : None ,
556+ }
557+ response = self .client .patch (url , data , format = 'json' , ** self .header )
558+ self .assertHttpStatus (response , status .HTTP_200_OK )
559+ self .assertIsNone (response .data ['end_of_sale' ])
560+ self .assertIsNone (response .data ['end_of_support' ])
0 commit comments