Skip to content

Commit

Permalink
Update test_planners_api.py to include tests for new update_planner f…
Browse files Browse the repository at this point in the history
…unctionality
  • Loading branch information
L015H4CK committed Jul 22, 2024
1 parent e2997d8 commit 34f3fcd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/api/v2/handlers/test_planners_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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

0 comments on commit 34f3fcd

Please sign in to comment.