From 7af4fff76ec8d731ff03cdbd1aeef6489e81ddc4 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 10 Aug 2020 11:10:12 -0700 Subject: [PATCH 1/2] Use parametize to add more test inputs --- .../platform/dbutils/test_postgresqlfuncts.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/volttrontesting/platform/dbutils/test_postgresqlfuncts.py b/volttrontesting/platform/dbutils/test_postgresqlfuncts.py index b0aa9f4d72..ca793123c8 100644 --- a/volttrontesting/platform/dbutils/test_postgresqlfuncts.py +++ b/volttrontesting/platform/dbutils/test_postgresqlfuncts.py @@ -539,8 +539,18 @@ def test_get_agg_topic_map_should_return_dict(get_container_func, ports_config): @pytest.mark.postgresqlfuncts @pytest.mark.dbutils +@pytest.mark.parametrize( + "topic_1, topic_2, topic_3, topic_pattern, expected_result", + [("'football'", "'foobar'", "'xzxzxccx'", "foo", {"football": 1, "foobar": 2})], +) def test_query_topics_by_pattern_should_return_matching_results( - get_container_func, ports_config + get_container_func, + ports_config, + topic_1, + topic_2, + topic_3, + topic_pattern, + expected_result, ): get_container, image = get_container_func @@ -550,23 +560,20 @@ def test_query_topics_by_pattern_should_return_matching_results( port_on_host = ports_config["port_on_host"] wait_for_connection(container, port_on_host) create_all_tables(container) - with get_postgresqlfuncts(port_on_host) as postgresqlfuncts: query = f""" INSERT INTO {TOPICS_TABLE} (topic_name) - VALUES ('football'); + VALUES ({topic_1}); INSERT INTO {TOPICS_TABLE} (topic_name) - VALUES ('foobar'); + VALUES ({topic_2}); INSERT INTO {TOPICS_TABLE} (topic_name) - VALUES ('xyzzzzzzzz'); + VALUES ({topic_3}); """ seed_database(container, query) - expected = {"football": 1, "foobar": 2} - topic_pattern = "foo" - actual = postgresqlfuncts.query_topics_by_pattern(topic_pattern) + actual_result = postgresqlfuncts.query_topics_by_pattern(topic_pattern) - assert actual == expected + assert actual_result == expected_result @pytest.mark.postgresqlfuncts From 696b55afff4fb577edd0d14ace90aab95eddede5 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 10 Aug 2020 12:39:32 -0700 Subject: [PATCH 2/2] Add cases for middle, suffix, case-insensitive --- .../platform/dbutils/test_postgresqlfuncts.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/volttrontesting/platform/dbutils/test_postgresqlfuncts.py b/volttrontesting/platform/dbutils/test_postgresqlfuncts.py index ca793123c8..2e6e89accf 100644 --- a/volttrontesting/platform/dbutils/test_postgresqlfuncts.py +++ b/volttrontesting/platform/dbutils/test_postgresqlfuncts.py @@ -541,7 +541,20 @@ def test_get_agg_topic_map_should_return_dict(get_container_func, ports_config): @pytest.mark.dbutils @pytest.mark.parametrize( "topic_1, topic_2, topic_3, topic_pattern, expected_result", - [("'football'", "'foobar'", "'xzxzxccx'", "foo", {"football": 1, "foobar": 2})], + [ + ("'football'", "'foobar'", "'xzxzxccx'", "foo", {"football": 1, "foobar": 2}), + ("'football'", "'foobar'", "'xzxzxccx'", "ba", {"football": 1, "foobar": 2}), + ("'football'", "'foobar'", "'xzxzxccx'", "ccx", {"xzxzxccx": 3}), + ("'fotball'", "'foobar'", "'xzxzxccx'", "foo", {"foobar": 2}), + ("'football'", "'foooobar'", "'xzxzxccx'", "foooo", {"foooobar": 2}), + ( + "'FOOtball'", + "'ABCFOOoXYZ'", + "'XXXfOoOo'", + "foo", + {"FOOtball": 1, "ABCFOOoXYZ": 2, "XXXfOoOo": 3}, + ), + ], ) def test_query_topics_by_pattern_should_return_matching_results( get_container_func,