From 393b1a80f3d6974cb93383dafc40bcc284d233f5 Mon Sep 17 00:00:00 2001 From: Mark Jordan Date: Mon, 5 Aug 2024 19:41:06 -0700 Subject: [PATCH] WIP on #791. --- tests/unit_tests.py | 65 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 3af9283..b9effc4 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -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) @@ -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( @@ -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( @@ -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"],