Skip to content

Commit

Permalink
Merge pull request #3361 from HHS/OPS-310/3207_can_nickname_required_…
Browse files Browse the repository at this point in the history
…for_patch

feat: make nickname required for can patch
  • Loading branch information
weimiao67 authored Jan 27, 2025
2 parents 099076f + 08f7107 commit 225923c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,7 @@ components:
required:
- number
- portfolio_id
- nick_name
CAN:
description: Common Accounting Number (CAN) Object
type: object
Expand Down
2 changes: 1 addition & 1 deletion backend/ops_api/ops/schemas/cans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GetCANListRequestSchema(Schema):


class CreateUpdateCANRequestSchema(Schema):
nick_name = fields.String(load_default=None)
nick_name = fields.String(required=True)
number = fields.String(required=True)
description = fields.String(allow_none=True, load_default=None)
portfolio_id = fields.Integer(required=True)
Expand Down
11 changes: 8 additions & 3 deletions backend/ops_api/tests/ops/can/test_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,25 @@ def test_can_post_creates_can(budget_team_auth_client, mocker, loaded_db):
"portfolio_id": 6,
"number": "G998235",
"description": "Test CAN Created by unit test",
"nick_name": "MockNickname",
}

mock_output_data = CAN(id=517, portfolio_id=6, number="G998235", description="Test CAN Created by unit test")
mock_output_data = CAN(
id=517, portfolio_id=6, number="G998235", description="Test CAN Created by unit test", nick_name="MockNickname"
)
mocker_create_can = mocker.patch("ops_api.ops.services.cans.CANService.create")
mocker_create_can.return_value = mock_output_data
response = budget_team_auth_client.post("/api/v1/cans/", json=input_data)

# Add fields that are default populated on load.
input_data["nick_name"] = None
input_data["funding_details_id"] = None
assert response.status_code == 201
mocker_create_can.assert_called_once_with(input_data)
assert response.json["id"] == mock_output_data.id
assert response.json["portfolio_id"] == mock_output_data.portfolio_id
assert response.json["number"] == mock_output_data.number
assert response.json["description"] == mock_output_data.description
assert response.json["nick_name"] == mock_output_data.nick_name


@pytest.mark.usefixtures("app_ctx")
Expand Down Expand Up @@ -299,18 +302,19 @@ def test_can_put(budget_team_auth_client, mocker, unadded_can):
"description": "Test CAN Created by unit test",
"portfolio_id": 6,
"funding_details_id": 1,
"nick_name": "MockNickname",
}

mocker_update_can = mocker.patch("ops_api.ops.services.cans.CANService.update")
unadded_can.description = update_data["description"]
mocker_update_can.return_value = unadded_can
response = budget_team_auth_client.put(f"/api/v1/cans/{test_can_id}", json=update_data)

update_data["nick_name"] = None
assert response.status_code == 200
mocker_update_can.assert_called_once_with(update_data, test_can_id)
assert response.json["number"] == unadded_can.number
assert response.json["description"] == unadded_can.description
assert response.json["nick_name"] == unadded_can.nick_name


@pytest.mark.usefixtures("app_ctx")
Expand All @@ -331,6 +335,7 @@ def test_can_put_404(budget_team_auth_client):
"description": "Test CAN Created by unit test",
"portfolio_id": 6,
"funding_details_id": 1,
"nick_name": "MockNickname",
}

response = budget_team_auth_client.put(f"/api/v1/cans/{test_can_id}", json=update_data)
Expand Down

0 comments on commit 225923c

Please sign in to comment.