Skip to content

Commit 4ce7dd5

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Refactor unit tests for project and domain with fake classes in identityv3"
2 parents 72a82b2 + 441e4e9 commit 4ce7dd5

3 files changed

Lines changed: 343 additions & 298 deletions

File tree

openstackclient/tests/identity/v3/fakes.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import copy
1717
import mock
18+
import uuid
1819

1920
from keystoneauth1 import access
2021
from keystoneauth1 import fixture
@@ -575,3 +576,66 @@ def setUp(self):
575576
endpoint=fakes.AUTH_URL,
576577
token=fakes.AUTH_TOKEN
577578
)
579+
580+
581+
class FakeProject(object):
582+
"""Fake one or more project."""
583+
584+
@staticmethod
585+
def create_one_project(attrs=None):
586+
"""Create a fake project.
587+
588+
:param Dictionary attrs:
589+
A dictionary with all attributes
590+
:return:
591+
A FakeResource object, with id, name, and so on
592+
"""
593+
594+
attrs = attrs or {}
595+
596+
# set default attributes.
597+
project_info = {
598+
'id': 'project-id-' + uuid.uuid4().hex,
599+
'name': 'project-name-' + uuid.uuid4().hex,
600+
'description': 'project-description-' + uuid.uuid4().hex,
601+
'enabled': True,
602+
'is_domain': False,
603+
'domain_id': 'domain-id-' + uuid.uuid4().hex,
604+
'parent_id': 'parent-id-' + uuid.uuid4().hex,
605+
'links': 'links-' + uuid.uuid4().hex,
606+
}
607+
project_info.update(attrs)
608+
609+
project = fakes.FakeResource(info=copy.deepcopy(project_info),
610+
loaded=True)
611+
return project
612+
613+
614+
class FakeDomain(object):
615+
"""Fake one or more domain."""
616+
617+
@staticmethod
618+
def create_one_domain(attrs=None):
619+
"""Create a fake domain.
620+
621+
:param Dictionary attrs:
622+
A dictionary with all attributes
623+
:return:
624+
A FakeResource object, with id, name, and so on
625+
"""
626+
627+
attrs = attrs or {}
628+
629+
# set default attributes.
630+
domain_info = {
631+
'id': 'domain-id-' + uuid.uuid4().hex,
632+
'name': 'domain-name-' + uuid.uuid4().hex,
633+
'description': 'domain-description-' + uuid.uuid4().hex,
634+
'enabled': True,
635+
'links': 'links-' + uuid.uuid4().hex,
636+
}
637+
domain_info.update(attrs)
638+
639+
domain = fakes.FakeResource(info=copy.deepcopy(domain_info),
640+
loaded=True)
641+
return domain

0 commit comments

Comments
 (0)