#!/usr/bin/env python3
"""Tests for fetch_route53_conditions.py, on a page in the Route 53 developer guide's markup."""
from __future__ import annotations
import pytest
import fetch_route53_conditions as f
HEADER = "
| Route 53 Condition Key | API operations | Value type | Description |
"
def row(key: str, operations: str, description: str) -> str:
return (f"{key} | {operations} | Multi-valued | "
f"{description} |
")
VPCS = row("route53:VPCs", "AssociateVPCWithHostedZone
ListHostedZonesByVPC
",
'Represents a list of VPCs in the request of AssociateVPCWithHostedZone and ListHostedZonesByVPC, in the '
'format of "VPCId=<vpc-id>,VPCRegion=<region>')
ACTIONS = row("route53:ChangeResourceRecordSetsActions", "ChangeResourceRecordSets",
"Represents a list of actions in the request of ChangeResourceRecordSets.")
def page(rows: str = VPCS + ACTIONS) -> str:
return f''
def test_a_key_in_a_format_of_members_is_read_with_its_operations_and_members():
keys = {entry["key"]: entry for entry in f.build(lambda url: page())["keys"]}
assert keys["route53:VPCs"]["operations"] == ["AssociateVPCWithHostedZone", "ListHostedZonesByVPC"]
assert keys["route53:VPCs"]["format"] == "VPCId=,VPCRegion="
assert keys["route53:VPCs"]["members"] == ["VPCId", "VPCRegion"]
# A row giving no format of members is not read here.
assert "route53:ChangeResourceRecordSetsActions" not in keys
def test_a_page_whose_layout_changed_is_refused():
with pytest.raises(ValueError, match="no table"):
f.build(lambda url: '')
with pytest.raises(ValueError, match="no key in a format"):
f.build(lambda url: page(ACTIONS))
def test_the_file_is_stale_when_the_page_says_something_else():
vendored = f.build(lambda url: page())
assert not f.stale(vendored, page())
assert f.stale(vendored, page(VPCS.replace("VPCRegion=", "Region=") + ACTIONS))