data_transfer: export new role attributes (#71844)
This commit is contained in:
parent
0ad917ac04
commit
a8f3390de8
|
@ -654,21 +654,21 @@ class Role(AbstractBase):
|
|||
'ou__slug': self.ou.slug if self.ou else None,
|
||||
}
|
||||
|
||||
def export_json(self, attributes=False, parents=False, permissions=False):
|
||||
def export_json(self, parents=False, permissions=False):
|
||||
d = {
|
||||
'uuid': self.uuid,
|
||||
'slug': self.slug,
|
||||
'name': self.name,
|
||||
'description': self.description,
|
||||
'details': self.details,
|
||||
'emails': self.emails,
|
||||
'emails_to_members': self.emails_to_members,
|
||||
'is_superuser': self.is_superuser,
|
||||
'external_id': self.external_id,
|
||||
'ou': self.ou and self.ou.natural_key_json(),
|
||||
'service': self.service and self.service.natural_key_json(),
|
||||
}
|
||||
|
||||
if attributes:
|
||||
for attribute in self.attributes.all():
|
||||
d.setdefault('attributes', []).append(attribute.to_json())
|
||||
|
||||
if parents:
|
||||
for parenting in RoleParenting.objects.filter(
|
||||
child_id=self.id, direct=True, deleted__isnull=True
|
||||
|
|
|
@ -145,12 +145,21 @@ def test_role_natural_key(db):
|
|||
|
||||
|
||||
def test_basic_role_export_json(db):
|
||||
role = Role.objects.create(name='basic role', slug='basic-role', description='basic role description')
|
||||
role = Role.objects.create(
|
||||
name='basic role',
|
||||
slug='basic-role',
|
||||
description='basic role description',
|
||||
emails=['test@example.org'],
|
||||
)
|
||||
role_dict = role.export_json()
|
||||
assert role_dict['name'] == role.name
|
||||
assert role_dict['slug'] == role.slug
|
||||
assert role_dict['uuid'] == role.uuid
|
||||
assert role_dict['description'] == role.description
|
||||
assert role_dict['details'] == role.details
|
||||
assert role_dict['emails'] == role.emails
|
||||
assert role_dict['emails_to_members'] == role.emails_to_members
|
||||
assert role_dict['is_superuser'] == role.is_superuser
|
||||
assert role_dict['external_id'] == role.external_id
|
||||
assert role_dict['ou'] is None
|
||||
assert role_dict['service'] is None
|
||||
|
|
|
@ -327,6 +327,23 @@ def test_role_deserializer_parenting_non_existing_parent(db):
|
|||
assert "Could not find parent role" in str(excinfo.value)
|
||||
|
||||
|
||||
def test_role_deserializer_emails(db):
|
||||
role_dict = {
|
||||
'name': 'test role',
|
||||
'slug': 'test-role-slug',
|
||||
'uuid': get_hex_uuid(),
|
||||
'ou': None,
|
||||
'emails': ['a@example.com'],
|
||||
}
|
||||
|
||||
import_context = ImportContext()
|
||||
rd = RoleDeserializer(role_dict, import_context)
|
||||
rd.deserialize()
|
||||
|
||||
role = Role.objects.get(slug='test-role-slug')
|
||||
assert role.emails == ['a@example.com']
|
||||
|
||||
|
||||
def test_role_deserializer_permissions(db):
|
||||
ou = OU.objects.create(slug='some-ou')
|
||||
other_role_dict = {'name': 'other role', 'slug': 'other-role-slug', 'uuid': get_hex_uuid(), 'ou': ou}
|
||||
|
|
Loading…
Reference in New Issue