Skip to content

Commit 0a2359c

Browse files
authored
DOP-3197: persist associated_products from snooty.toml (#420)
* add associated_products into project config * add postprocess for metadata and add unit tests * remove unused test detail
1 parent f262611 commit 0a2359c

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

snooty/postprocess.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,8 @@ def generate_metadata(cls, context: Context) -> n.SerializedNode:
15101510
document["eol"] = project_config.eol if project_config.eol else False
15111511
if project_config.deprecated_versions:
15121512
document["deprecated_versions"] = project_config.deprecated_versions
1513+
if project_config.associated_products:
1514+
document["associated_products"] = project_config.associated_products
15131515
# Update metadata document with key-value pairs defined in event parser
15141516
document["slugToTitle"] = {
15151517
k: [node.serialize() for node in v]

snooty/test_postprocess.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,3 +2422,32 @@ def test_target_quotes() -> None:
24222422
</target>
24232423
</root>""",
24242424
)
2425+
2426+
2427+
def test_metadata() -> None:
2428+
with make_test(
2429+
{
2430+
Path(
2431+
"source/index.txt"
2432+
): """
2433+
======
2434+
Test
2435+
======
2436+
2437+
This is a test intro
2438+
""",
2439+
Path(
2440+
"snooty.toml"
2441+
): """
2442+
name = "test_name"
2443+
title = "MongoDB title"
2444+
2445+
[[associated_products]]
2446+
name = "test_associated_product"
2447+
versions = ["v1", "v2"]
2448+
""",
2449+
}
2450+
) as result:
2451+
metadata = cast(Dict[str, Any], result.metadata)
2452+
assert len(metadata["associated_products"]) == 1
2453+
assert len(metadata["associated_products"][0]["versions"]) == 2

snooty/test_types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ def test_project() -> None:
2727
assert project_config.name == "unnamed"
2828
assert project_config.title == "untitled"
2929
assert project_config.deprecated_versions == None
30+
assert project_config.associated_products == []
3031
assert len(project_diagnostics) == 0
3132

33+
# Test valid project
34+
path = Path("test_data/test_project")
35+
project_config, project_diganostics = ProjectConfig.open(path)
36+
assert len(project_diganostics) == 0
37+
assert len(project_config.associated_products) > 0
38+
assert project_config.associated_products[0]["name"] == "test-name"
39+
assert project_config.associated_products[0]["versions"] == ["v1.0", "v1.2"]
40+
assert project_config.name == "test_data"
41+
3242

3343
def test_static_asset() -> None:
3444
path = Path("test_data/compass-explain-plan-with-index-raw-json.png")

snooty/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class ProjectConfig:
148148
manpages: Dict[str, ManPageConfig] = field(default_factory=dict)
149149
bundle: BundleConfig = field(default_factory=BundleConfig)
150150
data: Dict[str, object] = field(default_factory=dict)
151+
associated_products: List[Dict[str, object]] = field(default_factory=list)
151152

152153
@property
153154
def source_path(self) -> Path:

test_data/test_postprocessor/snooty.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ mms = ["v1.1", "v1.2", "v1.3"]
1616
[[banners]]
1717
targets = ["*/get-started/*.txt"]
1818
variant = "info"
19-
value = "This product is deprecated"
19+
value = "This product is deprecated"
20+
21+
[[associated_products]]
22+
name = "test_associated_name"
23+
versions = ["v1.1", "v1.2"]

test_data/test_project/snooty.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ title = "MongoDB title"
33

44
[substitutions]
55
guides = "MongoDB Guides"
6+
7+
[[associated_products]]
8+
name = "test-name"
9+
versions = ["v1.0", "v1.2"]

0 commit comments

Comments
 (0)