diff --git a/tests/api/v2/handlers/test_planners_api.py b/tests/api/v2/handlers/test_planners_api.py index 47afc2b22..b4702da46 100644 --- a/tests/api/v2/handlers/test_planners_api.py +++ b/tests/api/v2/handlers/test_planners_api.py @@ -13,6 +13,13 @@ def test_planner(event_loop, api_v2_client): return planner +@pytest.fixture +def updated_planner(test_planner): + planner_dict = test_planner.schema.dump(test_planner) + planner_dict.update(dict(description="a test planner with updated description")) + return planner_dict + + @pytest.fixture def test_planner_2(event_loop, api_v2_client): planner = Planner(name="atomic", planner_id="456", description="an alphabetically superior test planner (fake)", @@ -57,3 +64,20 @@ async def test_planner_defaults(self, api_v2_client, api_cookies, test_planner, assert len(planners_list) == 2 assert planners_list[0]["id"] == "456" assert planners_list[0]["name"][0] > planners_list[1]["name"][0] # prove that this wasn't an alphabetical sort + + async def test_update_planner(self, api_v2_client, api_cookies, test_planner, updated_planner, mocker): + with mocker.patch('app.api.v2.managers.base_api_manager.BaseApiManager.strip_yml') as mock_strip_yml: + mock_strip_yml.return_value = [test_planner.schema.dump(test_planner)] + resp = await api_v2_client.patch('/api/v2/planners/123', cookies=api_cookies, json=updated_planner) + assert resp.status == HTTPStatus.OK + planner = (await BaseService.get_service('data_svc').locate('planners'))[0] + assert planner.description == updated_planner["description"] + + async def test_unauthorized_update_planner(self, api_v2_client, updated_planner): + resp = await api_v2_client.patch('/api/v2/planners/123', json=updated_planner) + assert resp.status == HTTPStatus.UNAUTHORIZED + + async def test_update_nonexistent_planner(self, api_v2_client, api_cookies, updated_planner): + resp = await api_v2_client.patch('/api/v2/planners/999', cookies=api_cookies, json=updated_planner) + assert resp.status == HTTPStatus.NOT_FOUND +