Skip to content

Commit e7ffa24

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 5e22c83 commit e7ffa24

2 files changed

Lines changed: 43 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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,6 +2693,43 @@ def test_creation_and_update(self):
26932693
self.assertEqual(expected_dct, activation_key.update_payload())
26942694

26952695

2696+
def test_content_view_property(self):
2697+
"""content_view property extracts CV from content_view_environments."""
2698+
cfg = config.ServerConfig(url='foo')
2699+
ak = entities.ActivationKey(cfg, name='test_ak', organization=42)
2700+
ak.content_view_environments = [
2701+
{
2702+
'content_view': {'id': 10, 'name': 'Default'},
2703+
'lifecycle_environment': {'id': 20, 'name': 'Library'},
2704+
}
2705+
]
2706+
cv = ak.content_view
2707+
self.assertIsInstance(cv, entities.ContentView)
2708+
self.assertEqual(cv.id, 10)
2709+
2710+
def test_environment_property(self):
2711+
"""environment property extracts LCE from content_view_environments."""
2712+
cfg = config.ServerConfig(url='foo')
2713+
ak = entities.ActivationKey(cfg, name='test_ak', organization=42)
2714+
ak.content_view_environments = [
2715+
{
2716+
'content_view': {'id': 10, 'name': 'Default'},
2717+
'lifecycle_environment': {'id': 20, 'name': 'Library'},
2718+
}
2719+
]
2720+
lce = ak.environment
2721+
self.assertIsInstance(lce, entities.LifecycleEnvironment)
2722+
self.assertEqual(lce.id, 20)
2723+
2724+
def test_content_view_property_empty(self):
2725+
"""content_view returns None when content_view_environments is empty."""
2726+
cfg = config.ServerConfig(url='foo')
2727+
ak = entities.ActivationKey(cfg, name='test_ak', organization=42)
2728+
ak.content_view_environments = []
2729+
self.assertIsNone(ak.content_view)
2730+
self.assertIsNone(ak.environment)
2731+
2732+
26962733
class ReportTemplateTestCase(TestCase):
26972734
"""Tests for :class:`nailgun.entities.ReportTemplate`."""
26982735

0 commit comments

Comments
 (0)