Skip to content

Commit

Permalink
[tests] Print versions being used; add test for PG: copying JSON to J…
Browse files Browse the repository at this point in the history
…SON (disabled, since it fails for now)
  • Loading branch information
gacarrillor committed Dec 14, 2023
1 parent 0103289 commit e06d3ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import qgis.core
from qgis.PyQt.sip import SIP_VERSION_STR
from qgis.PyQt.QtCore import QT_VERSION_STR
from qgis.PyQt.Qt import PYQT_VERSION_STR
from qgis.core import Qgis

print("# # # # # # # # # # # # # # #")
print("QGIS version:", Qgis.QGIS_VERSION)
print("Qt version:", QT_VERSION_STR)
print("SIP version:", SIP_VERSION_STR)
print("PyQt version:", PYQT_VERSION_STR)
print("# # # # # # # # # # # # # # #")
24 changes: 24 additions & 0 deletions tests/test_pg_table_pg_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ def test_copy_all(self):
self.assertEqual(layer.featureCount(), 2)
self.assertEqual(res[APPENDED_COUNT], 2)

def _test_copy_all_json_to_json(self):
print('\nINFO: Validating gpkg table - pg table copy&paste all (JSON to JSON)...')
conn = get_pg_conn(PG_BD_1)
self.assertIsNotNone(conn)
cur = conn.cursor()
cur.execute("""ALTER TABLE target_table ADD COLUMN json_value JSON;""")
cur.close()
conn.commit()

pg_layer = get_qgis_pg_layer(PG_BD_1, 'target_table')
self.assertTrue(pg_layer.isValid())
self.assertEqual(pg_layer.featureCount(), 0)
self.assertTrue(pg_layer.fields().indexOf("json_value") != -1)

res = self.common._test_copy_all('source_table', pg_layer)
layer = res['TARGET_LAYER']
self.assertEqual(layer.featureCount(), 2)
self.assertEqual(res[APPENDED_COUNT], 2)

expected_json_values = {'abc': JSON_VALUE_1, 'def': JSON_VALUE_2}

for f in layer.getFeatures():
self.assertEqual(f['json_value'], expected_json_values[f['name']])

def test_copy_all_string_to_json(self):
print('\nINFO: Validating gpkg table - pg table copy&paste all (String to JSON)...')
conn = get_pg_conn(PG_BD_1)
Expand Down

0 comments on commit e06d3ef

Please sign in to comment.