Skip to content

Commit

Permalink
Add test transactions for sql file
Browse files Browse the repository at this point in the history
  • Loading branch information
pdrillin committed Jul 27, 2021
1 parent a7dae29 commit 6103051
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gestion_base_adresse/test/test_migration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for migrations."""

from gestion_base_adresse.processing.structure.create_database_structure import SCHEMA
import os
import unittest

Expand Down Expand Up @@ -38,3 +39,32 @@ def test_transactions(self):
sql[-1],
'The last line in {} must be a COMMIT; on a single line.'.format(migration)
)

sql_files = [
"00_initialize_database.sql",
"{}/10_FUNCTION.sql".format(SCHEMA),
"{}/20_TABLE_SEQUENCE_DEFAULT.sql".format(SCHEMA),
"{}/30_VIEW.sql".format(SCHEMA),
"{}/40_INDEX.sql".format(SCHEMA),
"{}/50_TRIGGER.sql".format(SCHEMA),
"{}/60_CONSTRAINT.sql".format(SCHEMA),
"{}/70_COMMENT.sql".format(SCHEMA),
]

for sf in sql_files:
with self.subTest(test_file=sf):
sql_file = os.path.join(plugin_path(), "install/sql/{}".format(sf))

with open(sql_file, "r") as f:
sql = f.readlines()

self.assertEqual(
'BEGIN;\n',
sql[0],
'The first line in {} must be a BEGIN; on a single line.'.format(sf)
)
self.assertEqual(
'COMMIT;\n',
sql[-1],
'The last line in {} must be a COMMIT; on a single line.'.format(sf)
)

0 comments on commit 6103051

Please sign in to comment.