Raise DuplicateOrganizationalUnitException
Calling UpdateOrganizationalUnit with name that already exists should raise proper error.
This commit is contained in:
parent
14ebf29a61
commit
fc9eab2591
3 changed files with 38 additions and 1 deletions
|
|
@ -10,3 +10,13 @@ class InvalidInputException(JsonRESTError):
|
|||
"InvalidInputException",
|
||||
"You provided a value that does not match the required pattern.",
|
||||
)
|
||||
|
||||
|
||||
class DuplicateOrganizationalUnitException(JsonRESTError):
|
||||
code = 400
|
||||
|
||||
def __init__(self):
|
||||
super(DuplicateOrganizationalUnitException, self).__init__(
|
||||
"DuplicateOrganizationalUnitException",
|
||||
"An OU with the same name already exists.",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@ from moto.core import BaseBackend, BaseModel
|
|||
from moto.core.exceptions import RESTError
|
||||
from moto.core.utils import unix_time
|
||||
from moto.organizations import utils
|
||||
from moto.organizations.exceptions import InvalidInputException
|
||||
from moto.organizations.exceptions import (
|
||||
InvalidInputException,
|
||||
DuplicateOrganizationalUnitException,
|
||||
)
|
||||
|
||||
|
||||
class FakeOrganization(BaseModel):
|
||||
|
|
@ -223,6 +226,9 @@ class OrganizationsBackend(BaseBackend):
|
|||
return new_ou.describe()
|
||||
|
||||
def update_organizational_unit(self, **kwargs):
|
||||
for ou in self.ou:
|
||||
if ou.name == kwargs["Name"]:
|
||||
raise DuplicateOrganizationalUnitException
|
||||
ou = self.get_organizational_unit_by_id(kwargs["OrganizationalUnitId"])
|
||||
ou.name = kwargs["Name"]
|
||||
return ou.describe()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue