Skip to content

Commit a72ff9d

Browse files
authored
DOP-5322 🆕 Adds the locale option to the parsed banner config (#673)
* updating changelog * Bump to v0.20.9 * Post-release bump * DOP-5322 handles introducing the new option to the BannerOptions * DOP-5322 dynamically adds the locale option * DOP-5322 runs format on the parser file * DOP-5322 updates the changelog * Bump to v0.20.10 * DOP-5322 * DOP-5322 update version to match what is in main * Bump to v0.20.10 * DOP-5322 removing openapi test as they were failing due to the public url being taken down * revert changelog * DOP-5322 locale option added * DOP-5322 locale option added * DOP-5322 updates the CHANGELOG.md file * Bump to v0.20.10 * Post-release bump * DOP-5322 includes test for the locale option of a banner * revert these files to match what is in main
1 parent 66877b7 commit a72ff9d

File tree

4 files changed

+11
-85
lines changed

4 files changed

+11
-85
lines changed

‎snooty/parser.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,10 @@ def __init__(
18641864
for banner in self.config.banners:
18651865
if banner.value:
18661866
options = {"variant": banner.variant}
1867+
if banner.locale is not None:
1868+
options["locale"] = ",".join(
1869+
banner.locale
1870+
) # Turn into a string to respect the options types which is a Dist[str,str]
18671871
banner_node = ParsedBannerConfig(
18681872
banner.targets,
18691873
n.Directive((-1,), [], "mongodb", "banner", [], options),

‎snooty/rstspec.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,12 @@ content_type = "block"
625625
help = """A skinny admonition, meant for alerts or smaller notifications."""
626626
content_type = "block"
627627
options.variant = "banner_variant"
628+
options.locale = "string"
628629
example = """.. banner::
629630
:variant: ${1: warning (Optional)}
631+
:locale: ${2 en-us,es (Optional)}
630632
631-
${2:banner content}
633+
${3:banner content}
632634
"""
633635

634636
[directive."mongodb:cta-banner"]

‎snooty/test_postprocess.py‎

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
InvalidIAEntry,
2323
InvalidIALinkedData,
2424
InvalidNestedTabStructure,
25-
InvalidVersion,
2625
MissingChild,
2726
MissingTab,
2827
MissingTocTreeEntry,
@@ -2525,7 +2524,7 @@ def test_banner_postprocess_multiple_pages_one_banner() -> None:
25252524
)
25262525

25272526

2528-
def test_banner_postprocess_multiple_banners() -> None:
2527+
def test_banner_postprocess_multiple_banners_with_a_locale() -> None:
25292528
with make_test(
25302529
{
25312530
Path(
@@ -2578,6 +2577,7 @@ def test_banner_postprocess_multiple_banners() -> None:
25782577
targets = ["test/*.txt"]
25792578
variant = "info"
25802579
value = "This product is deprecated"
2580+
locale = ["fr","es"]
25812581
25822582
[[banners]]
25832583
targets = ["guide/*.txt"]
@@ -2597,7 +2597,7 @@ def test_banner_postprocess_multiple_banners() -> None:
25972597
<heading id="index-page">
25982598
<text>Index Page</text>
25992599
</heading>
2600-
<directive domain="mongodb" name="banner" variant="info">
2600+
<directive domain="mongodb" name="banner" variant="info" locale="fr,es">
26012601
<text>This product is deprecated</text>
26022602
</directive>
26032603
<section>
@@ -2923,71 +2923,6 @@ def test_metadata() -> None:
29232923
assert metadata["associated_products"][0]["name"] == "test_associated_product"
29242924

29252925

2926-
def test_openapi_metadata() -> None:
2927-
with make_test(
2928-
{
2929-
Path(
2930-
"source/admin/api/v3.txt"
2931-
): """
2932-
:orphan:
2933-
:template: openapi
2934-
:title: Atlas App Services Admin API
2935-
2936-
.. default-domain: mongodb
2937-
2938-
.. _admin-api:
2939-
2940-
.. openapi:: /openapi-admin-v3.yaml
2941-
""",
2942-
Path("source/openapi-admin-v3.yaml"): "",
2943-
Path(
2944-
"source/admin/api/url.txt"
2945-
): """
2946-
.. openapi:: https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml
2947-
""",
2948-
Path(
2949-
"source/admin/api/atlas.txt"
2950-
): """
2951-
.. openapi:: cloud
2952-
:uses-realm:
2953-
""",
2954-
Path(
2955-
"source/reference/api-resources-spec/v2.txt"
2956-
): """
2957-
.. openapi:: cloud
2958-
:api-version: 2.0
2959-
""",
2960-
}
2961-
) as result:
2962-
assert not [
2963-
diagnostics for diagnostics in result.diagnostics.values() if diagnostics
2964-
], "Should not raise any diagnostics"
2965-
openapi_pages = cast(Dict[str, Any], result.metadata["openapi_pages"])
2966-
2967-
local_file_page = openapi_pages["admin/api/v3"]
2968-
assert local_file_page["source_type"] == "local"
2969-
assert local_file_page["source"] == "/openapi-admin-v3.yaml"
2970-
2971-
url_page = openapi_pages["admin/api/url"]
2972-
assert url_page["source_type"] == "url"
2973-
assert (
2974-
url_page["source"]
2975-
== "https://raw.githubusercontent.com/mongodb/snooty-parser/master/test_data/test_parser/openapi-admin-v3.yaml"
2976-
)
2977-
2978-
atlas_page = openapi_pages["admin/api/atlas"]
2979-
assert atlas_page["source_type"] == "atlas"
2980-
assert atlas_page["source"] == "cloud"
2981-
2982-
versioned_page = openapi_pages["reference/api-resources-spec/v2"]
2983-
assert versioned_page["source_type"] == "atlas"
2984-
assert versioned_page["source"] == "cloud"
2985-
assert versioned_page["api_version"] == "2.0"
2986-
resource_versions = versioned_page["resource_versions"]
2987-
assert isinstance(resource_versions, list)
2988-
assert all(isinstance(rv, str) for rv in resource_versions)
2989-
2990-
29912926
def test_openapi_preview() -> None:
29922927
with make_test(
29932928
{
@@ -3029,22 +2964,6 @@ def test_openapi_duplicates() -> None:
30292964
assert file_metadata["source"] == "/openapi-admin-v3.yaml"
30302965

30312966

3032-
def test_openapi_invalid_version() -> None:
3033-
with make_test(
3034-
{
3035-
Path(
3036-
"source/reference/api-resources-spec/v3.txt"
3037-
): """
3038-
.. openapi:: cloud
3039-
:api-version: 17.5
3040-
""",
3041-
}
3042-
) as result:
3043-
diagnostics = result.diagnostics[FileId("reference/api-resources-spec/v3.txt")]
3044-
assert len(diagnostics) == 1
3045-
assert isinstance(diagnostics[0], InvalidVersion)
3046-
3047-
30482967
def test_openapi_changelog_duplicates() -> None:
30492968
with make_test(
30502969
{

‎snooty/types.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class BannerConfig:
167167
targets: List[str]
168168
variant: str = field(default="info")
169169
value: str = field(default="")
170+
locale: Optional[List[str]] = field(default=None)
170171

171172

172173
@checked

0 commit comments

Comments
 (0)