#!/usr/bin/env python3 """Tests for fetch_lambda_layer_permissions.py, on pages in the AWS Lambda Developer Guide's markup.""" from __future__ import annotations import pytest import fetch_lambda_layer_permissions as f ASKS = ("

Make sure that you have permission to call the GetLayerVersion API on the\n" " layer version. For Event Functions in your AWS account, you must have this permission in\n" " your user policy. To use a layer in another account, the owner of that account must " "grant your account permission in a resource-based policy.

") def page(*paragraphs: str) -> str: return (f'

Adding layers

You can add layers.

{"".join(paragraphs)}' f'

Finding layer information

') def test_the_sentence_asking_for_permission_to_call_an_api_is_read_with_its_action_and_resource(): built = f.build(page(ASKS)) assert built["apiPermissions"] == [{ "paragraph": "Make sure that you have permission to call the GetLayerVersion API on the layer version. For " "Event Functions in your AWS account, you must have this permission in your user policy. To use " "a layer in another account, the owner of that account must grant your account permission in a " "resource-based policy.", "sentence": "Make sure that you have permission to call the GetLayerVersion API on the layer version.", "action": "lambda:GetLayerVersion", "on": "layer version"}] def test_a_page_whose_layout_or_wording_changed_is_refused(): with pytest.raises(ValueError, match="asks for permission to call no API"): f.build(page("

Layers are versioned.

")) # A sentence asking for an API AWS rewords is refused rather than dropping its action. with pytest.raises(ValueError, match="in no wording it used"): f.build(page(ASKS.replace("Make sure that you have", "You need"))) def test_the_file_is_stale_when_the_page_says_something_else(): vendored = f.build(page(ASKS)) assert not f.stale(vendored, page(ASKS)) assert f.stale(vendored, page(ASKS.replace("on the\n layer version", "on the\n layer")))