Repository: FOLIO-FSE/folio_migration_tools (language: python)

Issue:
Increase test coverage in src/folio_migration_tools/marc_rules_transformation/rules_mapper_holdings.py
# Description
Your task is to create happy path tests for the methods _remove_from_id_map_ and _set_default_call_number_type_if_empty_ in rules_mapper_holdings.py.
You will need to mock RulesMapperHoldings.

# DoD
- [ ] You have read the testing section in https://github.com/FOLIO-FSE/folio_migration_tools/blob/main/CONTRIBUTING.md#testing
- [ ] You have created a branch from this issue and checked it out locally
- [ ] You have run the entire test suite as described in Contributing.md making sure the code works before you start working on it
- [ ] You have written the test outlined in the description above
- [ ] You have successfully run the test
- [ ] You have performed all steps outlined in the [Github workflow](https://github.com/FOLIO-FSE/folio_migration_tools/blob/main/CONTRIBUTING.md#github-workflow) section in the Contributing.md file, including creating a pull request.

Change heading from "Git(hub) workflow" to "Code contribution workflow" to avoid confusion with git workflows
Change heading from "Git(hub) workflow" to "Code contribution workflow" to avoid confusion with git workflows in CONTRIBUTING.md.

Complete this issue in accordance with the GitHub flow.


Discussion / hints:

Fix patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 718e8cda..1767255a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -34,7 +34,9 @@ When you make edits to this document, make sure you update the Table of contents
   - [Writing tests](#writing-tests)
   - [Code coverage](#code-coverage)
   - [Running an end-to-end transformation](#running-an-end-to-end-transformation)
-# Writing Issues.
+
+
+# Writing issues
 Writing good issues is key.
 Both for sharing to the larger group of users what is needed or not working, but also for helping the developer working on the issue to reach the Definition Of Done (DoD) and beyond.
 
@@ -43,7 +45,7 @@ For the developer writing the issue, it is good practice to share a screenshot o
 Formulating a DoD is good practice. Take a moment to do this properly.   
 
 
-# Git(hub) workflow
+# Code contribution workflow
 We use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow)
 In the ideal situation, this is what you do:
 ## 1. Create a branch off of main and name it according to the feature you are working on
@@ -71,6 +73,7 @@ Run
 pipenv run safety check
 ```
 and update any packages with a vulnerability.
+
 ### 3.2. :monocle_face: Check and format your code
 The following command runs Flake8 with plugins on your code. It:
 * Uses black to format the code. The Line-lenght is to be 99 characters
@@ -108,7 +111,7 @@ optional arguments:
 ```
 
 ## 3.5. Create a pull request in GitHub
-## 3.6. :people_holding_hands: Code review.
+## 3.6. :people_holding_hands: Code review
 
 # Create release
 ## Create the release on Github


Test patch:
diff --git a/tests/test_rules_mapper_holdings.py b/tests/test_rules_mapper_holdings.py
index 3daff3ed..711b9676 100644
--- a/tests/test_rules_mapper_holdings.py
+++ b/tests/test_rules_mapper_holdings.py
@@ -1,11 +1,14 @@
 import pymarc
 
+from unittest.mock import Mock
+
 from folio_migration_tools.marc_rules_transformation.holdings_statementsparser import (
     HoldingsStatementsParser,
 )
 from folio_migration_tools.marc_rules_transformation.rules_mapper_holdings import (
     RulesMapperHoldings,
 )
+from folio_migration_tools.marc_rules_transformation.conditions import Conditions
 
 
 def test_get_marc_textual_stmt_correct_order_and_not_deduped():
@@ -29,3 +32,44 @@ def test_get_marc_textual_stmt_correct_order_and_not_deduped():
         all_stmts = [f["statement"] for f in rec["holdingsStatements"]]
         all_94s = [f for f in all_stmts if stmt == f]
         assert len(all_94s) == 2
+
+
+def test_remove_from_id_map():
+    mocked_rules_mapper_holdings = Mock(spec=RulesMapperHoldings)
+    mocked_rules_mapper_holdings.holdings_id_map = {
+        "h15066915": "5a0af31f-aa4a-5215-8a60-712b38cd6cb6",
+        "h14554914": "c9c44650-11e2-5534-ae50-01a1aa0fbd66",
+    }
+
+    former_ids = ["h15066915"]
+
+    RulesMapperHoldings.remove_from_id_map(mocked_rules_mapper_holdings, former_ids)
+
+    # The ids in the former_ids have been removed, any others are still there
+    assert "h15066915" not in mocked_rules_mapper_holdings.holdings_id_map.keys()
+    assert "h14554914" in mocked_rules_mapper_holdings.holdings_id_map.keys()
+
+
+def test_set_default_call_number_type_if_empty():
+    mocked_rules_mapper_holdings = Mock(spec=RulesMapperHoldings)
+    mocked_rules_mapper_holdings.conditions = Mock(spec=Conditions)
+    mocked_rules_mapper_holdings.conditions.default_call_number_type = {
+        "id": "b8992e1e-1757-529f-9238-147703864635"
+    }
+
+    without_callno_type_specified = {"callNumberTypeId": ""}
+    with_callno_type_specified = {"callNumberTypeId": "22156b02-785f-51c0-8723-416512cd42d9"}
+
+    # The default callNumberTypeId is assigned when no callNumberTypeId is specified
+    RulesMapperHoldings.set_default_call_number_type_if_empty(
+        mocked_rules_mapper_holdings, without_callno_type_specified
+    )
+    assert (
+        without_callno_type_specified["callNumberTypeId"] == "b8992e1e-1757-529f-9238-147703864635"
+    )
+
+    # The default callNumberTypeId is not replaced with the default if one is already specified
+    RulesMapperHoldings.set_default_call_number_type_if_empty(
+        mocked_rules_mapper_holdings, with_callno_type_specified
+    )
+    assert with_callno_type_specified["callNumberTypeId"] == "22156b02-785f-51c0-8723-416512cd42d9"