def test_apply_access_limited(self): """Test handling of limited resource access data for apply access method.""" processed_acls = { "provider": [{ "operation": "write", "resources": ["1", "3"] }, { "operation": "read", "resources": ["2"] }] } res_access = _apply_access(processed_acls) # pylint: disable=protected-access op_access = {"write": ["1", "3"], "read": ["1", "3", "2"]} no_rw_access = {"write": [], "read": []} no_access = {"read": []} expected = { "provider": op_access, "rate": no_rw_access, "aws.account": no_access, "azure.subscription_guid": no_access, "openshift.cluster": no_access, "openshift.node": no_access, "openshift.project": no_access, } self.assertEqual(res_access, expected)
def test_apply_case(self): """Test apply with mixed condition.""" processed_acls = { 'provider': [{ 'operation': '*', 'resources': ['*'] }], 'rate': [{ 'operation': '*', 'resources': ['*'] }], 'aws.account': [{ 'operation': 'read', 'resources': ['myaccount'] }] } res_access = _apply_access(processed_acls) # pylint: disable=protected-access op_access = {'read': ['myaccount']} rw_access = {'write': ['*'], 'read': ['*']} no_access = {'read': []} expected = { 'provider': rw_access, 'rate': rw_access, 'aws.account': op_access, 'openshift.cluster': no_access, 'openshift.node': no_access, 'openshift.project': no_access } self.assertEqual(res_access, expected)
def test_apply_case(self): """Test apply with mixed condition.""" processed_acls = { "provider": [{ "operation": "*", "resources": ["*"] }], "rate": [{ "operation": "*", "resources": ["*"] }], "aws.account": [{ "operation": "read", "resources": ["myaccount"] }], } res_access = _apply_access(processed_acls) # pylint: disable=protected-access op_access = {"read": ["myaccount"]} rw_access = {"write": ["*"], "read": ["*"]} no_access = {"read": []} expected = { "provider": rw_access, "rate": rw_access, "aws.account": op_access, "azure.subscription_guid": no_access, "openshift.cluster": no_access, "openshift.node": no_access, "openshift.project": no_access, } self.assertEqual(res_access, expected)
def test_apply_access_limited(self): """Test handling of limited resource access data for apply access method.""" processed_acls = { "cost_model": [{ "operation": "write", "resources": ["1", "3"] }, { "operation": "read", "resources": ["2"] }] } res_access = _apply_access(processed_acls) op_access = {"write": ["1", "3"], "read": ["1", "3", "2"]} no_access = {"read": []} expected = { "cost_model": op_access, "aws.account": no_access, "aws.organizational_unit": no_access, "gcp.account": no_access, "gcp.project": no_access, "azure.subscription_guid": no_access, "openshift.cluster": no_access, "openshift.node": no_access, "openshift.project": no_access, "ibm.account": no_access, } self.assertEqual(res_access, expected)
def test_apply_case(self): """Test apply with mixed condition.""" processed_acls = { "cost_model": [{ "operation": "*", "resources": ["*"] }], "aws.account": [{ "operation": "read", "resources": ["myaccount"] }], } res_access = _apply_access(processed_acls) op_access = {"read": ["myaccount"]} rw_access = {"write": ["*"], "read": ["*"]} no_access = {"read": []} expected = { "cost_model": rw_access, "aws.account": op_access, "aws.organizational_unit": no_access, "azure.subscription_guid": no_access, "gcp.account": no_access, "gcp.project": no_access, "openshift.cluster": no_access, "openshift.node": no_access, "openshift.project": no_access, "ibm.account": no_access, } self.assertEqual(res_access, expected)
def test_apply_access_limited(self): """Test handling of limited resource access data for apply access method.""" processed_acls = {'provider': [ { 'operation': 'write', 'resources': ['1', '3'] }, { 'operation': 'read', 'resources': ['2'] } ]} res_access = _apply_access(processed_acls) # pylint: disable=protected-access op_access = {'write': ['1', '3'], 'read': ['1', '3', '2']} no_rw_access = {'write': [], 'read': []} no_access = {'read': []} expected = { 'provider': op_access, 'rate': no_rw_access, 'aws.account': no_access, 'openshift.cluster': no_access, 'openshift.node': no_access, 'openshift.project': no_access } self.assertEqual(res_access, expected)
def test_apply_access_wildcard(self): """Test handling of wildcard data for apply access method.""" processed_acls = { "*": [{ "operation": "write", "resources": ["1", "3"] }, { "operation": "read", "resources": ["2"] }] } res_access = _apply_access(processed_acls) rw_access = {"write": ["1", "3"], "read": ["1", "3", "2"]} read_access = {"read": ["2"]} expected = { "provider": rw_access, "rate": rw_access, "aws.account": read_access, "aws.organizational_unit": read_access, "azure.subscription_guid": read_access, "openshift.cluster": read_access, "openshift.node": read_access, "openshift.project": read_access, } self.assertEqual(res_access, expected)
def test_apply_access_none(self): """Test handling none input for apply access method.""" res_access = _apply_access(None) # pylint: disable=protected-access rw_access = {'write': [], 'read': []} read_access = {'read': []} expected = { 'provider': rw_access, 'rate': rw_access, 'aws.account': read_access, 'openshift.cluster': read_access, 'openshift.node': read_access, 'openshift.project': read_access } self.assertEqual(res_access, expected)
def test_apply_access_all_wildcard(self): """Test handling of wildcard data for apply access method.""" processed_acls = {'*': [{'operation': '*', 'resources': ['1', '3']}]} res_access = _apply_access(processed_acls) # pylint: disable=protected-access rw_access = {'write': ['1', '3'], 'read': ['1', '3']} read_access = {'read': ['1', '3']} expected = { 'provider': rw_access, 'rate': rw_access, 'aws.account': read_access, 'openshift.cluster': read_access, 'openshift.node': read_access, 'openshift.project': read_access } self.assertEqual(res_access, expected)
def test_apply_access_none(self): """Test handling none input for apply access method.""" res_access = _apply_access(None) # pylint: disable=protected-access rw_access = {"write": [], "read": []} read_access = {"read": []} expected = { "provider": rw_access, "rate": rw_access, "aws.account": read_access, "azure.subscription_guid": read_access, "openshift.cluster": read_access, "openshift.node": read_access, "openshift.project": read_access, } self.assertEqual(res_access, expected)
def test_apply_access_none(self): """Test handling none input for apply access method.""" res_access = _apply_access(None) rw_access = {"write": [], "read": []} read_access = {"read": []} expected = { "cost_model": rw_access, "aws.account": read_access, "aws.organizational_unit": read_access, "azure.subscription_guid": read_access, "openshift.cluster": read_access, "openshift.node": read_access, "openshift.project": read_access, } self.assertEqual(res_access, expected)
def test_apply_access_except(self, mock_get_operation): """Test handling exception _get_operation used in apply access method.""" processed_acls = {'*': [{'operation': '*', 'resources': ['1', '3']}]} res_access = _apply_access(processed_acls) # pylint: disable=protected-access rw_access = {'write': [], 'read': []} read_access = {'read': []} expected = { 'provider': rw_access, 'rate': rw_access, 'aws.account': read_access, 'openshift.cluster': read_access, 'openshift.node': read_access, 'openshift.project': read_access } self.assertEqual(res_access, expected) mock_get_operation.assert_called()
def test_apply_access_limited_no_read_write(self): """Test handling of limited resource access data for apply access method.""" processed_acls = {} res_access = _apply_access(processed_acls) no_rw_access = {"write": [], "read": []} no_access = {"read": []} expected = { "cost_model": no_rw_access, "aws.account": no_access, "aws.organizational_unit": no_access, "azure.subscription_guid": no_access, "openshift.cluster": no_access, "openshift.node": no_access, "openshift.project": no_access, } self.assertEqual(res_access, expected)
def test_apply_access_except(self, mock_get_operation): """Test handling exception _get_operation used in apply access method.""" processed_acls = {"*": [{"operation": "*", "resources": ["1", "3"]}]} res_access = _apply_access(processed_acls) # pylint: disable=protected-access rw_access = {"write": [], "read": []} read_access = {"read": []} expected = { "provider": rw_access, "rate": rw_access, "aws.account": read_access, "azure.subscription_guid": read_access, "openshift.cluster": read_access, "openshift.node": read_access, "openshift.project": read_access, } self.assertEqual(res_access, expected) mock_get_operation.assert_called()
def test_apply_access_except(self, mock_get_operation): """Test handling exception _get_operation used in apply access method.""" processed_acls = {"*": [{"operation": "*", "resources": ["1", "3"]}]} res_access = _apply_access(processed_acls) rw_access = {"write": [], "read": []} read_access = {"read": []} expected = { "cost_model": rw_access, "aws.account": read_access, "aws.organizational_unit": read_access, "gcp.account": read_access, "gcp.project": read_access, "azure.subscription_guid": read_access, "openshift.cluster": read_access, "openshift.node": read_access, "openshift.project": read_access, "ibm.account": read_access, } self.assertEqual(res_access, expected) mock_get_operation.assert_called()