Skip to content

Commit dd22844

Browse files
jeremylenzclaude
andcommitted
Rename cves to cvenvs and add unit tests for AK properties
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c6660b1 commit dd22844

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

nailgun/entities.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,21 @@ def read(self, entity=None, attrs=None, ignore=None, params=None):
275275
@property
276276
def content_view(self):
277277
"""Backward-compat: extract the first content view from content_view_environments."""
278-
cves = getattr(self, 'content_view_environments', None)
279-
if not cves:
278+
cvenvs = getattr(self, 'content_view_environments', None)
279+
if not cvenvs:
280280
return None
281-
cv_data = cves[0].get('content_view')
281+
cv_data = cvenvs[0].get('content_view')
282282
if not cv_data:
283283
return None
284284
return ContentView(server_config=self._server_config, id=cv_data['id'])
285285

286286
@property
287287
def environment(self):
288288
"""Backward-compat: extract the first lifecycle environment from content_view_environments."""
289-
cves = getattr(self, 'content_view_environments', None)
290-
if not cves:
289+
cvenvs = getattr(self, 'content_view_environments', None)
290+
if not cvenvs:
291291
return None
292-
lce_data = cves[0].get('lifecycle_environment')
292+
lce_data = cvenvs[0].get('lifecycle_environment')
293293
if not lce_data:
294294
return None
295295
return LifecycleEnvironment(server_config=self._server_config, id=lce_data['id'])

tests/test_entities.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

26962732
class ReportTemplateTestCase(TestCase):
26972733
"""Tests for :class:`nailgun.entities.ReportTemplate`."""

0 commit comments

Comments
 (0)