diff --git a/nailgun/entities.py b/nailgun/entities.py index 72457f61..843610c6 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -274,6 +274,13 @@ def path(self, which=None): return f'{super().path(which="self")}/{which}' return super().path(which) + def update_payload(self, fields=None): + """Always include organization_id.""" + payload = super().update_payload(fields) + # organization is required for the AK update call + payload['organization_id'] = self.organization.id + return payload + def add_host_collection(self, synchronous=True, timeout=None, **kwargs): """Helper for associating host collection with activation key. diff --git a/tests/test_entities.py b/tests/test_entities.py index da537875..f4a6bab3 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -2685,6 +2685,26 @@ def test_remove(self): self.assertEqual(handlr.call_count, 1) +class ActivationKeyTestCase(TestCase): + """Tests for :class:`nailgun.entities.ActivationKey`.""" + + def test_creation_and_update(self): + """Check template combinations as json or entity is set on correct + attribute template_combinations_attributes ( check #333) + """ + cfg = config.ServerConfig(url='foo') + activation_key = entities.ActivationKey(cfg, name='test_ak', organization=42) + expected_dct = { + 'name': 'test_ak', + 'organization_id': 42, + } + self.assertEqual(expected_dct, activation_key.create_payload()) + # Testing update + activation_key.name = 'test_ak_new' + expected_dct['name'] = 'test_ak_new' + self.assertEqual(expected_dct, activation_key.update_payload()) + + class ReportTemplateTestCase(TestCase): """Tests for :class:`nailgun.entities.ReportTemplate`."""