Skip to content

Commit

Permalink
Comment out domain ID
Browse files Browse the repository at this point in the history
Domain ID has been commented out as not implemented yet, to be added
back in once project creation action has a domain id parameter
  • Loading branch information
meoflynn committed Feb 6, 2025
1 parent bdb019c commit 1be27f3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 57 deletions.
8 changes: 4 additions & 4 deletions lib/openstack_api/openstack_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def create_project(
email_regex = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
if not re.match(email_regex, project_details.email):
raise ValueError("The project contact email is invalid")
if not project_details.project_domain:
raise MissingMandatoryParamError("The domain for the project is missing")
# if not project_details.project_domain:
# raise MissingMandatoryParamError("The domain for the project is missing")

create_project_kwargs = {
"name": project_details.name,
Expand All @@ -36,9 +36,9 @@ def create_project(
}

# get domain id for the domain to use
domain_details = conn.identity.get_domain(project_details.project_domain)
# domain_details = conn.identity.get_domain(project_details.project_domain)

create_project_kwargs["domain_id"] = domain_details.id
# create_project_kwargs["domain_id"] = domain_details.id

if project_details.parent_id:
create_project_kwargs["parent_id"] = project_details.parent_id
Expand Down
2 changes: 1 addition & 1 deletion lib/structs/project_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ProjectDetails:
name: str
email: str
description: str = ""
project_domain: str = None
# project_domain: str = None
is_enabled: Optional[bool] = None
openstack_id: Optional[str] = None
immutable: Optional[bool] = None
Expand Down
5 changes: 1 addition & 4 deletions lib/workflows/create_jasmin_external_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def create_jasmin_external_project(
conn: Connection,
project_name: str,
project_email: str,
project_domain: str,
project_description: str,
network_name: str,
subnet_name: str,
Expand All @@ -54,7 +53,7 @@ def create_jasmin_external_project(
:param conn: Openstack connection object
:param project_name: A string for project name
:param project_email: A string for email associated with the project
:param project_domain: Domain to create project in
:param project_domain: Domain to create project in (to be added to project)
:param project_description: A string for project description
:param network_name: A string for external network name
:param subnet_name: A string for external subnet name
Expand All @@ -78,7 +77,6 @@ def create_jasmin_external_project(
ProjectDetails(
name=project_name,
email=project_email,
project_domain=project_domain,
description=project_description,
immutable=project_immutable,
parent_id=parent_id,
Expand Down Expand Up @@ -181,4 +179,3 @@ def create_jasmin_external_project(
role_identifier="user",
),
)

81 changes: 39 additions & 42 deletions tests/lib/openstack_api/test_openstack_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ def test_create_project_invalid_email_throws():
create_project(mock_conn, mock_project_details)


def test_create_project_domain_missing_throws():
"""
Tests calling the API wrapper without a project domain will throw
"""
mock_project_details = MagicMock()
mock_project_details.name = "foo"
mock_project_details.email = "[email protected]"
mock_project_details.project_domain = None
# def test_create_project_domain_missing_throws():
# """
# Tests calling the API wrapper without a project domain will throw
# """
# mock_project_details = MagicMock()
# mock_project_details.name = "foo"
# mock_project_details.email = "[email protected]"
# mock_project_details.project_domain = None

mock_conn = MagicMock()
with pytest.raises(ValueError):
create_project(mock_conn, mock_project_details)
# mock_conn = MagicMock()
# with pytest.raises(ValueError):
# create_project(mock_conn, mock_project_details)


def test_create_project_forwards_error():
Expand All @@ -74,34 +74,34 @@ def test_create_project_forwards_error():
create_project(mock_conn, mock_project_details)


def test_get_domain_called():
"""
Tests that get_domain is called when creating a project
"""
# def test_get_domain_called():
# """
# Tests that get_domain is called when creating a project
# """

mock_project_details = MagicMock()
mock_project_details.name = "foo"
mock_project_details.description = "bar"
mock_project_details.project_domain = "test-domain"
mock_project_details.is_enabled = True
mock_project_details.email = "[email protected]"
mock_project_details.parent_id = None
mock_project_details.immutable = False
# mock_project_details = MagicMock()
# mock_project_details.name = "foo"
# mock_project_details.description = "bar"
# mock_project_details.project_domain = "test-domain"
# mock_project_details.is_enabled = True
# mock_project_details.email = "[email protected]"
# mock_project_details.parent_id = None
# mock_project_details.immutable = False

mock_conn = MagicMock()
# mock_conn = MagicMock()

create_project(mock_conn, mock_project_details)
mock_conn.identity.get_domain.assert_called_once_with("test-domain")
# create_project(mock_conn, mock_project_details)
# mock_conn.identity.get_domain.assert_called_once_with("test-domain")


def test_create_project_successful():
"""
Tests that create project works without a domain id
Tests that create project works
"""
mock_project_details = MagicMock()
mock_project_details.name = "foo"
mock_project_details.description = "bar"
mock_project_details.project_domain = "test-domain"
# mock_project_details.project_domain = "test-domain"
mock_project_details.is_enabled = True
mock_project_details.email = "[email protected]"
mock_project_details.parent_id = None
Expand All @@ -111,16 +111,15 @@ def test_create_project_successful():

res = create_project(mock_conn, mock_project_details)

mock_conn.identity.get_domain.assert_called_once_with("test-domain")
# mock_conn.identity.get_domain.assert_called_once_with("test-domain")

domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
domain_id = domain_details.id
# domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
# domain_id = domain_details.id

mock_conn.identity.create_project.assert_called_once_with(
name="foo",
description="bar",
is_enabled=True,
domain_id=domain_id,
tags=["[email protected]"],
)
assert res == mock_conn.identity.create_project.return_value
Expand All @@ -133,7 +132,7 @@ def test_create_project_successful_no_parent_id_and_not_immutable():
mock_project_details = MagicMock()
mock_project_details.name = "foo"
mock_project_details.description = "bar"
mock_project_details.project_domain = "buzz"
# mock_project_details.project_domain = "buzz"
mock_project_details.is_enabled = True
mock_project_details.email = "[email protected]"
mock_project_details.parent_id = None
Expand All @@ -143,15 +142,14 @@ def test_create_project_successful_no_parent_id_and_not_immutable():

res = create_project(mock_conn, mock_project_details)

mock_conn.identity.get_domain.assert_called_once_with("buzz")
# mock_conn.identity.get_domain.assert_called_once_with("buzz")

domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
domain_id = domain_details.id
# domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
# domain_id = domain_details.id

mock_conn.identity.create_project.assert_called_once_with(
name="foo",
description="bar",
domain_id=domain_id,
is_enabled=True,
tags=["[email protected]"],
)
Expand All @@ -166,7 +164,7 @@ def test_create_project_successful_with_parent_id_and_immutable():
mock_project_details = MagicMock()
mock_project_details.name = "foo"
mock_project_details.description = "bar"
mock_project_details.project_domain = "buzz"
# mock_project_details.project_domain = "buzz"
mock_project_details.is_enabled = True
mock_project_details.email = "[email protected]"
mock_project_details.parent_id = "baz"
Expand All @@ -176,15 +174,14 @@ def test_create_project_successful_with_parent_id_and_immutable():

res = create_project(mock_conn, mock_project_details)

mock_conn.identity.get_domain.assert_called_once_with("buzz")
# mock_conn.identity.get_domain.assert_called_once_with("buzz")

domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
domain_id = domain_details.id
# domain_details = mock_conn.identity.get_domain(mock_project_details.project_domain)
# domain_id = domain_details.id

mock_conn.identity.create_project.assert_called_once_with(
name="foo",
description="bar",
domain_id=domain_id,
is_enabled=True,
parent_id="baz",
tags=["[email protected]", "immutable"],
Expand Down
7 changes: 1 addition & 6 deletions tests/lib/workflows/test_create_jasmin_external_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def test_create_jasmin_external_project(
mock_conn = MagicMock()
project_name = "Test Project"
project_email = "[email protected]"
project_domain = "test-domain"
project_description = "Test Description"
network_name = "External Network"
subnet_name = "External Subnet"
Expand All @@ -72,7 +71,6 @@ def test_create_jasmin_external_project(
mock_conn,
project_name,
project_email,
project_domain,
project_description,
network_name,
subnet_name,
Expand All @@ -91,7 +89,6 @@ def test_create_jasmin_external_project(
ProjectDetails(
name=project_name,
email=project_email,
project_domain=project_domain,
description=project_description,
immutable=project_immutable,
parent_id=parent_id,
Expand Down Expand Up @@ -256,7 +253,7 @@ def test_create_jasmin_external_project_no_users(
mock_conn = MagicMock()
project_name = "Test Project"
project_email = "[email protected]"
project_domain = "test-domain"
# project_domain = "test-domain"
project_description = "Test Description"
network_name = "External Network"
subnet_name = "External Subnet"
Expand All @@ -273,7 +270,6 @@ def test_create_jasmin_external_project_no_users(
mock_conn,
project_name,
project_email,
project_domain,
project_description,
network_name,
subnet_name,
Expand All @@ -292,7 +288,6 @@ def test_create_jasmin_external_project_no_users(
ProjectDetails(
name=project_name,
email=project_email,
project_domain=project_domain,
description=project_description,
immutable=project_immutable,
parent_id=parent_id,
Expand Down

0 comments on commit 1be27f3

Please sign in to comment.