Skip to content

Commit

Permalink
WIP on #791.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Aug 6, 2024
1 parent 6138984 commit 393b1a8
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,64 @@ def test_fixed_string_templates(self):

for fixture in fixtures:
output_row = workbench_utils.apply_csv_value_templates(
fixture["config"], fixture["row"]
fixture["config"], "csv_value_templates", fixture["row"]
)
self.assertEqual(fixture["control"], output_row)

def test_fixed_string_templates_in_paged_content(self):
"""Tests $filename_without_extension and $weight templates."""
fixtures = [
{
"config": {
"subdelimiter": "|",
"csv_value_templates_for_paged_content": [
{"field_foo_1": "$filename_without_extension, bar"}
],
"allow_csv_value_templates_if_field_empty": [],
"csv_value_templates_rand_length": 5,
},
"row": {
"title": "Title 1",
"field_foo_1": "I am foo",
"file": "baz.jpg",
"field_weight": 1,
},
"control": {
"title": "Title 1",
"field_foo_1": "baz, bar",
"file": "baz.jpg",
"field_weight": 1,
},
},
{
"config": {
"subdelimiter": "|",
"csv_value_templates_for_paged_content": [
{"field_foo_2": "pre-$weight"}
],
"allow_csv_value_templates_if_field_empty": [],
"csv_value_templates_rand_length": 5,
},
"row": {
"title": "Title 1",
"field_foo_2": "I am foo",
"file": "foo.jpg",
"field_weight": 2,
},
"control": {
"title": "Title 1",
"field_foo_2": "pre-2",
"file": "foo.jpg",
"field_weight": 2,
},
},
]

for fixture in fixtures:
output_row = workbench_utils.apply_csv_value_templates(
fixture["config"],
"csv_value_templates_for_paged_content",
fixture["row"],
)
self.assertEqual(fixture["control"], output_row)

Expand Down Expand Up @@ -1183,7 +1240,7 @@ def test_alphanumeric_string_template(self):
for fixture in fixtures:
rand_str_length = fixture["config"]["csv_value_templates_rand_length"]
output_row = workbench_utils.apply_csv_value_templates(
fixture["config"], fixture["row"]
fixture["config"], "csv_value_templates", fixture["row"]
)
# Sorry for the inscrutible {{{}}} in the regex quantifier...
self.assertRegex(
Expand Down Expand Up @@ -1231,7 +1288,7 @@ def test_numeric_string_template(self):
for fixture in fixtures:
rand_str_length = fixture["config"]["csv_value_templates_rand_length"]
output_row = workbench_utils.apply_csv_value_templates(
fixture["config"], fixture["row"]
fixture["config"], "csv_value_templates", fixture["row"]
)
# Sorry about the inscrutible {{{rand_str_length}}} in the regex quantifier...
self.assertRegex(
Expand Down Expand Up @@ -1274,7 +1331,7 @@ def test_uuid_template(self):

for fixture in fixtures:
output_row = workbench_utils.apply_csv_value_templates(
fixture["config"], fixture["row"]
fixture["config"], "csv_value_templates", fixture["row"]
)
self.assertRegex(
fixture["row"]["field_foo_3"],
Expand Down

0 comments on commit 393b1a8

Please sign in to comment.