From b03e20c7e5ca6a75ebb65fc4aca2eb528196028e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hellebrandt?= Date: Tue, 12 Sep 2023 11:15:03 +0200 Subject: [PATCH] AK update must contain org id, it is a required field (#992) * AK update must contain org id, it is a required field * Test for AK update (cherry picked from commit 7bc1a11d0778e61bdcdab63852256cd2c26963e7) --- nailgun/entities.py | 7 +++++++ tests/test_entities.py | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) 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`."""