@@ -2692,6 +2692,42 @@ def test_creation_and_update(self):
26922692 expected_dct ['name' ] = 'test_ak_new'
26932693 self .assertEqual (expected_dct , activation_key .update_payload ())
26942694
2695+ def test_content_view_property (self ):
2696+ """content_view property extracts CV from content_view_environments."""
2697+ cfg = config .ServerConfig (url = 'foo' )
2698+ ak = entities .ActivationKey (cfg , name = 'test_ak' , organization = 42 )
2699+ ak .content_view_environments = [
2700+ {
2701+ 'content_view' : {'id' : 10 , 'name' : 'Default' },
2702+ 'lifecycle_environment' : {'id' : 20 , 'name' : 'Library' },
2703+ }
2704+ ]
2705+ cv = ak .content_view
2706+ self .assertIsInstance (cv , entities .ContentView )
2707+ self .assertEqual (cv .id , 10 )
2708+
2709+ def test_environment_property (self ):
2710+ """Environment property extracts LCE from content_view_environments."""
2711+ cfg = config .ServerConfig (url = 'foo' )
2712+ ak = entities .ActivationKey (cfg , name = 'test_ak' , organization = 42 )
2713+ ak .content_view_environments = [
2714+ {
2715+ 'content_view' : {'id' : 10 , 'name' : 'Default' },
2716+ 'lifecycle_environment' : {'id' : 20 , 'name' : 'Library' },
2717+ }
2718+ ]
2719+ lce = ak .environment
2720+ self .assertIsInstance (lce , entities .LifecycleEnvironment )
2721+ self .assertEqual (lce .id , 20 )
2722+
2723+ def test_content_view_property_empty (self ):
2724+ """content_view returns None when content_view_environments is empty."""
2725+ cfg = config .ServerConfig (url = 'foo' )
2726+ ak = entities .ActivationKey (cfg , name = 'test_ak' , organization = 42 )
2727+ ak .content_view_environments = []
2728+ self .assertIsNone (ak .content_view )
2729+ self .assertIsNone (ak .environment )
2730+
26952731
26962732class ReportTemplateTestCase (TestCase ):
26972733 """Tests for :class:`nailgun.entities.ReportTemplate`."""
0 commit comments