@@ -189,6 +189,42 @@ def test_list_roots():
189189 validate_roots (org , response )
190190
191191
192+ @mock_aws
193+ def test_list_roots_for_new_account_in_organization ():
194+ if not settings .TEST_DECORATOR_MODE :
195+ raise SkipTest ("Involves changing account using env variable" )
196+ client = boto3 .client ("organizations" , region_name = "us-east-1" )
197+ org = client .create_organization ()["Organization" ]
198+ org_roots = client .list_roots ()
199+ new_account_id = client .create_account (
200+ AccountName = "test_account" ,
201+ 202+ RoleName = "CustomOrganizationRole" ,
203+ )["CreateAccountStatus" ]["AccountId" ]
204+
205+ with mock .patch .dict (os .environ , {"MOTO_ACCOUNT_ID" : new_account_id }):
206+ client_for_new_account = boto3 .client ("organizations" , "us-east-1" )
207+ new_account_roots = client_for_new_account .list_roots ()
208+ validate_roots (org , new_account_roots )
209+ assert len (new_account_roots ["Roots" ]) == 1
210+ assert len (org_roots ["Roots" ]) == len (new_account_roots ["Roots" ])
211+ assert org_roots ["Roots" ][0 ] == new_account_roots ["Roots" ][0 ]
212+
213+
214+ @mock_aws
215+ def test_list_roots_for_account_without_organization_exception ():
216+ client = boto3 .client ("organizations" , region_name = "us-east-1" )
217+ with pytest .raises (ClientError ) as e :
218+ client .list_roots ()
219+ ex = e .value
220+ assert ex .operation_name == "ListRoots"
221+ assert ex .response ["ResponseMetadata" ]["HTTPStatusCode" ] == 400
222+ assert "AWSOrganizationsNotInUseException" in ex .response ["Error" ]["Code" ]
223+ assert ex .response ["Error" ]["Message" ] == (
224+ "Your account is not a member of an organization."
225+ )
226+
227+
192228@mock_aws
193229def test_create_organizational_unit ():
194230 client = boto3 .client ("organizations" , region_name = "us-east-1" )
0 commit comments