Skip to content

Commit

Permalink
AK update must contain org id, it is a required field (#992)
Browse files Browse the repository at this point in the history
* AK update must contain org id, it is a required field

* Test for AK update

(cherry picked from commit 7bc1a11)
  • Loading branch information
lhellebr authored and ogajduse committed Sep 12, 2023
1 parent d708488 commit bc3770c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""

Expand Down

0 comments on commit bc3770c

Please sign in to comment.