Skip to content

Commit

Permalink
Clean Custom Field Functions
Browse files Browse the repository at this point in the history
-Chance instances of add_field_data to update_existing_segment_traits
-Change instances of overwrite_field_data to overwrite_segment_traits
-Change __add_field_data to __add_additional_valid_segment_traits
-Change __overwrite_field_data to __overwrite_valid_segment_traits

Signed-off-by: Elijah Swift <elijah.swift@ibm.com>
  • Loading branch information
ElijahSwiftIBM committed Aug 30, 2023
1 parent 31b6f65 commit 0564b2b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 45 deletions.
8 changes: 4 additions & 4 deletions pyracf/access/access_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"permission",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
30 changes: 18 additions & 12 deletions pyracf/common/security_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __init__(
profile_type: str,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
self.__irrsmo00 = IRRSMO00()
self.__profile_type = profile_type
Expand All @@ -64,25 +64,31 @@ def __init__(
self._trait_map = {}
self.__debug = debug
self.__generate_requests_only = generate_requests_only
if add_field_data is not None:
self.__add_field_data(add_field_data)
if overwrite_field_data is not None:
self.__overwrite_field_data(overwrite_field_data)
if update_existing_segment_traits is not None:
self.__add_additional_valid_segment_traits(update_existing_segment_traits)
if overwrite_segment_traits is not None:
self.__overwrite_valid_segment_traits(overwrite_segment_traits)

# ============================================================================
# Custom Fields
# ============================================================================
def __add_field_data(self, field_data: dict):
def __add_additional_valid_segment_traits(
self, additional_valid_segment_traits: dict
):
"""Add additional fields to valid segment traits dictionary."""
for segment in field_data:
for segment in additional_valid_segment_traits:
if segment in self._valid_segment_traits:
self._valid_segment_traits[segment].update(field_data[segment])
self._valid_segment_traits[segment].update(
additional_valid_segment_traits[segment]
)
else:
self._valid_segment_traits[segment] = field_data[segment]
self._valid_segment_traits[segment] = additional_valid_segment_traits[
segment
]

def __overwrite_field_data(self, field_data: dict):
def __overwrite_valid_segment_traits(self, new_valid_segment_traits: dict):
"""Overwrite field data in valid segment traits dictionary"""
self._valid_segment_traits = field_data
self._valid_segment_traits = new_valid_segment_traits

# ============================================================================
# Request Execution
Expand Down
8 changes: 4 additions & 4 deletions pyracf/connection/connection_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"groupConnection",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
8 changes: 4 additions & 4 deletions pyracf/data_set/data_set_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"dataSet",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)
self._valid_segment_traits["base"].update(
self._common_base_traits_data_set_generic
Expand Down
8 changes: 4 additions & 4 deletions pyracf/group/group_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"group",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
8 changes: 4 additions & 4 deletions pyracf/resource/resource_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"resource",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
8 changes: 4 additions & 4 deletions pyracf/setropts/setropts_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"systemSettings",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
8 changes: 4 additions & 4 deletions pyracf/user/user_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ def __init__(
self,
debug: bool = False,
generate_requests_only: bool = False,
add_field_data: Union[dict, None] = None,
overwrite_field_data: Union[dict, None] = None,
update_existing_segment_traits: Union[dict, None] = None,
overwrite_segment_traits: Union[dict, None] = None,
) -> None:
super().__init__(
"user",
debug=debug,
generate_requests_only=generate_requests_only,
add_field_data=add_field_data,
overwrite_field_data=overwrite_field_data,
update_existing_segment_traits=update_existing_segment_traits,
overwrite_segment_traits=overwrite_segment_traits,
)

# ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
"-D_XOPEN_SOURCE_EXTENDED",
"-Wc,lp64,langlvl(EXTC99),STACKPROTECT(ALL),",
"-qcpluscmt",
]
],
)
]
}
Expand Down
6 changes: 3 additions & 3 deletions tests/user/test_user_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_user_admin_build_add_user_request_passphrase_and_password_redacted(
def test_user_admin_build_alter_request_alternate_segments(self):
user_admin = UserAdmin(
generate_requests_only=True,
overwrite_field_data=TestUserConstants.TEST_USER_ALTERNATE_SEGMENTS,
overwrite_segment_traits=TestUserConstants.TEST_USER_ALTERNATE_SEGMENTS,
)
result = user_admin.alter(
"squidwrd", traits=TestUserConstants.TEST_ALTER_USER_CSDATA_REQUEST_TRAITS
Expand All @@ -101,7 +101,7 @@ def test_user_admin_build_alter_request_alternate_segments(self):
def test_user_admin_build_alter_request_overwrite_segments(self):
user_admin = UserAdmin(
generate_requests_only=True,
overwrite_field_data=TestUserConstants.TEST_USER_OVERWRITE_SEGMENTS,
overwrite_segment_traits=TestUserConstants.TEST_USER_OVERWRITE_SEGMENTS,
)
result = user_admin.alter(
"squidwrd", traits=TestUserConstants.TEST_ALTER_USER_CSDATA_REQUEST_TRAITS
Expand All @@ -113,7 +113,7 @@ def test_user_admin_build_alter_request_overwrite_segments(self):
def test_user_admin_build_alter_request_update_segments(self):
user_admin = UserAdmin(
generate_requests_only=True,
add_field_data=TestUserConstants.TEST_USER_UPDATE_SEGMENTS,
update_existing_segment_traits=TestUserConstants.TEST_USER_UPDATE_SEGMENTS,
)
result = user_admin.alter(
"squidwrd", traits=TestUserConstants.TEST_ALTER_USER_CSDATA_REQUEST_TRAITS
Expand Down
2 changes: 1 addition & 1 deletion tests/user/test_user_result_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_user_admin_can_parse_extract_user_base_omvs_csdata_success_xml(
call_racf_mock: Mock,
):
user_admin = UserAdmin(
add_field_data=TestUserConstants.TEST_USER_UPDATE_SEGMENTS
update_existing_segment_traits=TestUserConstants.TEST_USER_UPDATE_SEGMENTS
)
call_racf_mock.return_value = (
TestUserConstants.TEST_EXTRACT_USER_RESULT_BASE_OMVS_CSDATA_SUCCESS_XML
Expand Down

0 comments on commit 0564b2b

Please sign in to comment.