def test_get_grantees(self): """Test grantees extractor from target config""" # No default_target_schema_select_permissions and schema_mapping should return empty list target_config_with_empty_grantees = {} assert utils.get_grantees(target_config_with_empty_grantees, 'foo.foo') == [] # Empty default_target_schema_select_permissions should return empty list target_config_with_default_empty = { 'default_target_schema_select_permissions': '' } assert utils.get_grantees(target_config_with_default_empty, 'foo.foo') == [] # default_target_schema_select_permissions as string should return list target_config_with_default_as_string = { 'default_target_schema_select_permissions': 'grantee' } assert utils.get_grantees(target_config_with_default_as_string, 'foo.foo') == ['grantee'] # default_target_schema_select_permissions as list should return list target_config_with_default_as_list = { 'default_target_schema_select_permissions': ['grantee1'] } assert utils.get_grantees(target_config_with_default_as_list, 'foo.foo') == ['grantee1'] # default_target_schema_select_permissions as list should return list target_config_with_default_as_list = { 'default_target_schema_select_permissions': ['grantee1', 'grantee2'] } assert utils.get_grantees(target_config_with_default_as_list, 'foo.foo') == ['grantee1', 'grantee2'] # Empty schema_mapping should return empty list target_config_with_empty_schema_mapping = {'schema_mapping': {}} assert utils.get_grantees(target_config_with_empty_schema_mapping, 'foo.foo') == [] # Missing schema in schema_mapping should return empty list target_config_with_missing_schema_mapping = { 'schema_mapping': { 'foo2': { 'target_schema_select_permissions': 'grantee' } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, 'foo.foo') == [] # Grantees as string should be extracted from schema_mapping target_config_with_missing_schema_mapping = { 'schema_mapping': { 'foo': { 'target_schema_select_permissions': 'grantee' } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, 'foo.foo') == ['grantee'] # Grantees as list should be extracted from schema_mapping target_config_with_missing_schema_mapping = { 'schema_mapping': { 'foo': { 'target_schema_select_permissions': ['grantee1', 'grantee2'] } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, 'foo.foo') == ['grantee1', 'grantee2'] # If grantees exist in schema_mapping then should not use the default_target_schema_select_permissions target_config = { 'default_target_schema_select_permissions': ['grantee1', 'grantee2'], 'schema_mapping': { 'foo': { 'target_schema_select_permissions': ['grantee3', 'grantee4'] } } } assert utils.get_grantees(target_config, 'foo.foo') == ['grantee3', 'grantee4'] # If target schema not exist in schema_mapping then should return the default_target_schema_select_permissions target_config = { 'default_target_schema_select_permissions': ['grantee1', 'grantee2'], 'schema_mapping': { 'foo2': { 'target_schema_select_permissions': ['grantee3', 'grantee4'] } } } assert utils.get_grantees(target_config, 'foo.foo') == ['grantee1', 'grantee2'] # default_target_schema_select_permissions as dict with string should return dict target_config_with_default_as_dict = { 'default_target_schema_select_permissions': { 'users': 'grantee_user1', 'groups': 'grantee_group1' } } assert utils.get_grantees(target_config_with_default_as_dict, 'foo.foo') == { 'users': ['grantee_user1'], 'groups': ['grantee_group1'] } # default_target_schema_select_permissions as dict with list should return dict target_config_with_default_as_dict = { 'default_target_schema_select_permissions': { 'users': ['grantee_user1', 'grantee_user2'], 'groups': ['grantee_group1', 'grantee_group2'] } } assert utils.get_grantees(target_config_with_default_as_dict, 'foo.foo') == { 'users': ['grantee_user1', 'grantee_user2'], 'groups': ['grantee_group1', 'grantee_group2'] }
def test_get_grantees(self): """Test grantees extractor from target config""" # No default_target_schema_select_permissions and schema_mapping should return empty list target_config_with_empty_grantees = {} assert utils.get_grantees(target_config_with_empty_grantees, "foo.foo") == [] # Empty default_target_schema_select_permissions should return empty list target_config_with_default_empty = { "default_target_schema_select_permissions": "" } assert utils.get_grantees(target_config_with_default_empty, "foo.foo") == [] # default_target_schema_select_permissions as string should return list target_config_with_default_as_string = { "default_target_schema_select_permissions": "grantee" } assert utils.get_grantees(target_config_with_default_as_string, "foo.foo") == ["grantee"] # default_target_schema_select_permissions as list should return list target_config_with_default_as_list = { "default_target_schema_select_permissions": ["grantee1"] } assert utils.get_grantees(target_config_with_default_as_list, "foo.foo") == ["grantee1"] # default_target_schema_select_permissions as list should return list target_config_with_default_as_list = { "default_target_schema_select_permissions": ["grantee1", "grantee2"] } assert utils.get_grantees(target_config_with_default_as_list, "foo.foo") == ["grantee1", "grantee2"] # Empty schema_mapping should return empty list target_config_with_empty_schema_mapping = {"schema_mapping": {}} assert utils.get_grantees(target_config_with_empty_schema_mapping, "foo.foo") == [] # Missing schema in schema_mapping should return empty list target_config_with_missing_schema_mapping = { "schema_mapping": { "foo2": { "target_schema_select_permissions": "grantee" } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, "foo.foo") == [] # Grantees as string should be extracted from schema_mapping target_config_with_missing_schema_mapping = { "schema_mapping": { "foo": { "target_schema_select_permissions": "grantee" } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, "foo.foo") == ["grantee"] # Grantees as list should be extracted from schema_mapping target_config_with_missing_schema_mapping = { "schema_mapping": { "foo": { "target_schema_select_permissions": ["grantee1", "grantee2"] } } } assert utils.get_grantees(target_config_with_missing_schema_mapping, "foo.foo") == ["grantee1", "grantee2"] # If grantees exist in schema_mapping then should not use the default_target_schema_select_permissions target_config = { "default_target_schema_select_permissions": ["grantee1", "grantee2"], "schema_mapping": { "foo": { "target_schema_select_permissions": ["grantee3", "grantee4"] } } } assert utils.get_grantees(target_config, "foo.foo") == ["grantee3", "grantee4"] # If target schema not exist in schema_mapping then should return the default_target_schema_select_permissions target_config = { "default_target_schema_select_permissions": ["grantee1", "grantee2"], "schema_mapping": { "foo2": { "target_schema_select_permissions": ["grantee3", "grantee4"] } } } assert utils.get_grantees(target_config, "foo.foo") == ["grantee1", "grantee2"] # default_target_schema_select_permissions as dict with string should return dict target_config_with_default_as_dict = { "default_target_schema_select_permissions": { "users": "grantee_user1", "groups": "grantee_group1" } } assert utils.get_grantees(target_config_with_default_as_dict, "foo.foo") == { "users": ["grantee_user1"], "groups": ["grantee_group1"] } # default_target_schema_select_permissions as dict with list should return dict target_config_with_default_as_dict = { "default_target_schema_select_permissions": { "users": ["grantee_user1", "grantee_user2"], "groups": ["grantee_group1", "grantee_group2"] } } assert utils.get_grantees(target_config_with_default_as_dict, "foo.foo") == { "users": ["grantee_user1", "grantee_user2"], "groups": ["grantee_group1", "grantee_group2"] }