def test_that_when_set_identity_pool_roles_with_only_unauth_role_specified_the_set_identity_pool_roles_method_only_set_the_unauth_role(
     self,
 ):
     """
     Tests that given a valid pool id, and only other given role is the UnauthenticatedRole, the unauth role for the
     pool is set and the auth role is cleared.
     """
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(
         boto_cognitoidentity.__salt__,
         {
             "boto_iam.describe_role": MagicMock(
                 return_value={"arn": "my_unauth_role_arn"}
             )
         },
     ):
         expected_roles = dict(unauthenticated="my_unauth_role_arn")
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id",
             UnauthenticatedRole="my_unauth_role",
             **conn_parameters
         )
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get("set"))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get("Roles"), expected_roles)
 def test_that_when_set_identity_pool_roles_with_both_roles_specified_the_set_identity_pool_role_method_set_both_roles(
     self,
 ):
     """
     Tests setting of both roles to valid given roles
     """
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(
         boto_cognitoidentity.__salt__,
         {
             "boto_iam.describe_role": MagicMock(
                 return_value={"arn": "my_unauth_role_arn"}
             )
         },
     ):
         expected_roles = dict(
             authenticated="arn:aws:iam:my_auth_role",
             unauthenticated="my_unauth_role_arn",
         )
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id",
             AuthenticatedRole="arn:aws:iam:my_auth_role",
             UnauthenticatedRole="my_unauth_role",
             **conn_parameters
         )
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get("set"))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get("Roles"), expected_roles)
def test_that_when_set_identity_pool_roles_given_invalid_auth_role_the_set_identity_pool_method_returns_set_false_and_error(boto_conn):
    '''
    Tests error handling for invalid auth role
    '''
    with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value=False)}):
        result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='no_such_auth_role', **pytest.conn_parameters)
        mock_calls = boto_conn.mock_calls
        assert result.get('set') is False
        assert 'no_such_auth_role' in result.get('error', '')
        assert len(mock_calls) == 0
def test_that_when_set_identity_pool_roles_with_no_roles_specified_the_set_identity_pool_roles_method_unset_the_roles(boto_conn):
    '''
    Tests that given a valid pool id, and no other roles given, the role for the pool is cleared.
    '''
    boto_conn.set_identity_pool_roles.return_value = None
    result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', **pytest.conn_parameters)
    mock_calls = boto_conn.mock_calls
    assert result.get('set') is True
    assert len(mock_calls) == 1
    assert mock_calls[0][2].get('Roles') == {}
def test_that_when_set_identity_pool_roles_with_invalid_pool_id_the_set_identity_pool_roles_method_returns_set_false_and_error(boto_conn):
    '''
    Tests that given an invalid pool id, we properly handle error generated from set_identity_pool_roles
    '''
    boto_conn.set_identity_pool_roles.side_effect = exceptions.ClientError(error_content, 'set_identity_pool_roles')
    result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='no_such_pool_id', **pytest.conn_parameters)
    mock_calls = boto_conn.mock_calls
    assert result.get('set') is False
    assert result.get('error', {}).get('message') == error_message.format('set_identity_pool_roles')
    assert len(mock_calls) == 1
 def test_that_when_set_identity_pool_roles_with_invalid_pool_id_the_set_identity_pool_roles_method_returns_set_false_and_error(self):
     '''
     Tests that given an invalid pool id, we properly handle error generated from set_identity_pool_roles
     '''
     self.conn.set_identity_pool_roles.side_effect = ClientError(error_content, 'set_identity_pool_roles')
     result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='no_such_pool_id', **conn_parameters)
     mock_calls = self.conn.mock_calls
     self.assertIs(result.get('set'), False)
     self.assertEqual(result.get('error', {}).get('message'), error_message.format('set_identity_pool_roles'))
     self.assertEqual(len(mock_calls), 1)
 def test_that_when_set_identity_pool_roles_with_no_roles_specified_the_set_identity_pool_roles_method_unset_the_roles(self):
     '''
     Tests that given a valid pool id, and no other roles given, the role for the pool is cleared.
     '''
     self.conn.set_identity_pool_roles.return_value = None
     result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', **conn_parameters)
     mock_calls = self.conn.mock_calls
     self.assertTrue(result.get('set'))
     self.assertEqual(len(mock_calls), 1)
     self.assertEqual(mock_calls[0][2].get('Roles'), {})
 def test_that_when_set_identity_pool_roles_given_invalid_unauth_role_the_set_identity_pool_method_returns_set_false_and_error(self):
     '''
     Tests error handling for invalid unauth role
     '''
     with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value=False)}):
         result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='arn:aws:iam:my_auth_role', UnauthenticatedRole='no_such_unauth_role', **conn_parameters)
         mock_calls = self.conn.mock_calls
         self.assertIs(result.get('set'), False)
         self.assertIn('no_such_unauth_role', result.get('error', ''))
         self.assertEqual(len(mock_calls), 0)
 def test_that_when_set_identity_pool_roles_with_invalid_pool_id_the_set_identity_pool_roles_method_returns_set_false_and_error(
     self
 ):
     """
     Tests that given an invalid pool id, we properly handle error generated from set_identity_pool_roles
     """
     self.conn.set_identity_pool_roles.side_effect = ClientError(error_content, "set_identity_pool_roles")
     result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId="no_such_pool_id", **conn_parameters)
     mock_calls = self.conn.mock_calls
     self.assertIs(result.get("set"), False)
     self.assertEqual(result.get("error", {}).get("message"), error_message.format("set_identity_pool_roles"))
     self.assertEqual(len(mock_calls), 1)
 def test_that_when_set_identity_pool_roles_with_no_roles_specified_the_set_identity_pool_roles_method_unset_the_roles(
     self
 ):
     """
     Tests that given a valid pool id, and no other roles given, the role for the pool is cleared.
     """
     self.conn.set_identity_pool_roles.return_value = None
     result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId="some_id", **conn_parameters)
     mock_calls = self.conn.mock_calls
     self.assertTrue(result.get("set"))
     self.assertEqual(len(mock_calls), 1)
     self.assertEqual(mock_calls[0][2].get("Roles"), {})
 def test_that_when_set_identity_pool_roles_with_no_roles_specified_the_set_identity_pool_roles_method_unset_the_roles(
     self, ):
     """
     Tests that given a valid pool id, and no other roles given, the role for the pool is cleared.
     """
     self.conn.set_identity_pool_roles.return_value = None
     result = boto_cognitoidentity.set_identity_pool_roles(
         IdentityPoolId="some_id", **conn_parameters)
     mock_calls = self.conn.mock_calls
     assert result.get("set")
     assert len(mock_calls) == 1
     assert mock_calls[0][2].get("Roles") == {}
 def test_that_when_set_identity_pool_roles_with_both_roles_specified_the_set_identity_pool_role_method_set_both_roles(self):
     '''
     Tests setting of both roles to valid given roles
     '''
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_unauth_role_arn'})}):
         expected_roles = dict(authenticated='arn:aws:iam:my_auth_role',
                               unauthenticated='my_unauth_role_arn')
         result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='arn:aws:iam:my_auth_role', UnauthenticatedRole='my_unauth_role', **conn_parameters)
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get('set'))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get('Roles'), expected_roles)
 def test_that_when_set_identity_pool_roles_with_only_unauth_role_specified_the_set_identity_pool_roles_method_only_set_the_unauth_role(self):
     '''
     Tests that given a valid pool id, and only other given role is the UnauthenticatedRole, the unauth role for the
     pool is set and the auth role is cleared.
     '''
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_unauth_role_arn'})}):
         expected_roles = dict(unauthenticated='my_unauth_role_arn')
         result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', UnauthenticatedRole='my_unauth_role', **conn_parameters)
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get('set'))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get('Roles'), expected_roles)
def test_that_when_set_identity_pool_roles_with_only_auth_role_specified_the_set_identity_pool_roles_method_only_set_the_auth_role(boto_conn):
    '''
    Tests that given a valid pool id, and only other given role is the AuthenticatedRole, the auth role for the
    pool is set and unauth role is cleared.
    '''
    boto_conn.set_identity_pool_roles.return_value = None
    with patch.dict(boto_cognitoidentity.__salt__, {'boto_iam.describe_role': MagicMock(return_value={'arn': 'my_auth_role_arn'})}):
        expected_roles = dict(authenticated='my_auth_role_arn')
        result = boto_cognitoidentity.set_identity_pool_roles(IdentityPoolId='some_id', AuthenticatedRole='my_auth_role', **pytest.conn_parameters)
        mock_calls = boto_conn.mock_calls
        assert result.get('set') is True
        assert len(mock_calls) == 1
        assert mock_calls[0][2].get('Roles') == expected_roles
 def test_that_when_set_identity_pool_roles_with_invalid_pool_id_the_set_identity_pool_roles_method_returns_set_false_and_error(
     self, ):
     """
     Tests that given an invalid pool id, we properly handle error generated from set_identity_pool_roles
     """
     self.conn.set_identity_pool_roles.side_effect = ClientError(
         error_content, "set_identity_pool_roles")
     result = boto_cognitoidentity.set_identity_pool_roles(
         IdentityPoolId="no_such_pool_id", **conn_parameters)
     mock_calls = self.conn.mock_calls
     assert result.get("set") is False
     assert result.get("error", {}).get("message") == error_message.format(
         "set_identity_pool_roles")
     assert len(mock_calls) == 1
 def test_that_when_set_identity_pool_roles_given_invalid_auth_role_the_set_identity_pool_method_returns_set_false_and_error(
     self
 ):
     """
     Tests error handling for invalid auth role
     """
     with patch.dict(boto_cognitoidentity.__salt__, {"boto_iam.describe_role": MagicMock(return_value=False)}):
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id", AuthenticatedRole="no_such_auth_role", **conn_parameters
         )
         mock_calls = self.conn.mock_calls
         self.assertIs(result.get("set"), False)
         self.assertIn("no_such_auth_role", result.get("error", ""))
         self.assertEqual(len(mock_calls), 0)
 def test_that_when_set_identity_pool_roles_given_invalid_auth_role_the_set_identity_pool_method_returns_set_false_and_error(
     self, ):
     """
     Tests error handling for invalid auth role
     """
     with patch.dict(
             boto_cognitoidentity.__salt__,
         {"boto_iam.describe_role": MagicMock(return_value=False)},
     ):
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id",
             AuthenticatedRole="no_such_auth_role",
             **conn_parameters)
         mock_calls = self.conn.mock_calls
         self.assertIs(result.get("set"), False)
         self.assertIn("no_such_auth_role", result.get("error", ""))
         self.assertEqual(len(mock_calls), 0)
 def test_that_when_set_identity_pool_roles_given_invalid_unauth_role_the_set_identity_pool_method_returns_set_false_and_error(
     self, ):
     """
     Tests error handling for invalid unauth role
     """
     with patch.dict(
             boto_cognitoidentity.__salt__,
         {"boto_iam.describe_role": MagicMock(return_value=False)},
     ):
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id",
             AuthenticatedRole="arn:aws:iam:my_auth_role",
             UnauthenticatedRole="no_such_unauth_role",
             **conn_parameters)
         mock_calls = self.conn.mock_calls
         assert result.get("set") is False
         assert "no_such_unauth_role" in result.get("error", "")
         assert len(mock_calls) == 0
 def test_that_when_set_identity_pool_roles_with_only_unauth_role_specified_the_set_identity_pool_roles_method_only_set_the_unauth_role(
     self
 ):
     """
     Tests that given a valid pool id, and only other given role is the UnauthenticatedRole, the unauth role for the
     pool is set and the auth role is cleared.
     """
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(
         boto_cognitoidentity.__salt__,
         {"boto_iam.describe_role": MagicMock(return_value={"arn": "my_unauth_role_arn"})},
     ):
         expected_roles = dict(unauthenticated="my_unauth_role_arn")
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id", UnauthenticatedRole="my_unauth_role", **conn_parameters
         )
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get("set"))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get("Roles"), expected_roles)
 def test_that_when_set_identity_pool_roles_with_both_roles_specified_the_set_identity_pool_role_method_set_both_roles(
     self
 ):
     """
     Tests setting of both roles to valid given roles
     """
     self.conn.set_identity_pool_roles.return_value = None
     with patch.dict(
         boto_cognitoidentity.__salt__,
         {"boto_iam.describe_role": MagicMock(return_value={"arn": "my_unauth_role_arn"})},
     ):
         expected_roles = dict(authenticated="arn:aws:iam:my_auth_role", unauthenticated="my_unauth_role_arn")
         result = boto_cognitoidentity.set_identity_pool_roles(
             IdentityPoolId="some_id",
             AuthenticatedRole="arn:aws:iam:my_auth_role",
             UnauthenticatedRole="my_unauth_role",
             **conn_parameters
         )
         mock_calls = self.conn.mock_calls
         self.assertTrue(result.get("set"))
         self.assertEqual(len(mock_calls), 1)
         self.assertEqual(mock_calls[0][2].get("Roles"), expected_roles)