diff --git a/bx_django_utils/test_utils/assert_queries.py b/bx_django_utils/test_utils/assert_queries.py index 761c107..7651c10 100644 --- a/bx_django_utils/test_utils/assert_queries.py +++ b/bx_django_utils/test_utils/assert_queries.py @@ -77,7 +77,7 @@ def get_table_name(query): # transaction statements return - table_names = re.findall(r'(FROM|INSERT INTO|UPDATE) \"(.+?)\"', sql) + table_names = re.findall(r'(FROM|INSERT[A-Z ]+?INTO|UPDATE) \"(.+?)\"', sql) assert len(table_names) >= 1, f'Error parsing: {sql!r}' # Use only the first table name (e.g.: ignore names in inner join) table_name = table_names[0][1] diff --git a/bx_django_utils_tests/tests/test_assert_queries.py b/bx_django_utils_tests/tests/test_assert_queries.py index 6096d4f..1d62698 100644 --- a/bx_django_utils_tests/tests/test_assert_queries.py +++ b/bx_django_utils_tests/tests/test_assert_queries.py @@ -37,6 +37,20 @@ def test_assert_queries(self): similar=True, ) + def test_get_table_name(self): + self.assertEqual( + AssertQueries.get_table_name( + query={'sql': 'INSERT INTO "table_name1" ("foo_id", "bar_id") VALUES (1, 2)'} + ), + 'table_name1', + ) + self.assertEqual( + AssertQueries.get_table_name( + query={'sql': 'INSERT OR IGNORE INTO "table_name2" ("foo_id", "bar_id") VALUES (1, 2)'} + ), + 'table_name2', + ) + def test_assert_table_names(self): queries = self.get_instance() queries.assert_table_names('auth_permission') diff --git a/pyproject.toml b/pyproject.toml index 6f934e9..b69d115 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'bx_django_utils' -version = "63" +version = "64" description = 'Various Django utility functions' homepage = "https://github.com/boxine/bx_django_utils/" authors = [