Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.14.z] AK update must contain org id, it is a required field #993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading