From 8164ca5aaa5a6949fd38a5c8da4ce29ff6e474da Mon Sep 17 00:00:00 2001 From: enrico ferreguti Date: Wed, 4 Sep 2024 17:14:37 +0200 Subject: [PATCH] extend tests --- webapp/djakart/tests.py | 87 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/webapp/djakart/tests.py b/webapp/djakart/tests.py index c5e1f97..f723578 100755 --- a/webapp/djakart/tests.py +++ b/webapp/djakart/tests.py @@ -134,7 +134,7 @@ def test_insert(self): cursor.execute(sql_add) conn.commit() self.clone.salva_cache() - self.assertTrue(self.clone.cambiamenti_non_registrati, "Cloned version %s" % self.clone.nome) + self.assertTrue(self.clone.cambiamenti_non_registrati, "Insert in version %s" % self.clone.nome) def test_update(self): @@ -153,7 +153,27 @@ def test_update(self): cursor.execute(sql_updt) conn.commit() self.clone.salva_cache() - self.assertTrue(self.clone.cambiamenti_non_registrati, "Cloned version %s" % self.clone.nome) + self.assertTrue(self.clone.cambiamenti_non_registrati, "Updated version %s" % self.clone.nome) + + + def test_restore(self): + with get_pg_versions_connection() as conn: + with conn.cursor() as cursor: + self.clone = version.objects.create( + nome=uuid.uuid4().hex[0:4], + crs=self.testver.crs, + base=self.testver + ) + + sql_updt = """ +UPDATE "{schema}"."b0101011_Vincolo" +SET "ARTICOLO" = 'TEST' WHERE "N_AREAV"='0015'; +""".format(schema=self.clone.schema) + cursor.execute(sql_updt) + conn.commit() + self.clone.salva_cache() + self.clone.restore() + self.assertTrue(self.clone.is_clean_(), "Restore version %s" % self.clone.nome) def test_commit(self): @@ -183,3 +203,66 @@ def test_commit(self): self.clone.commit("TEST COMMIT %s" % self.clone.schema) self.assertTrue(self.clone.is_clean_(), "Cloned version %s" % self.clone.nome) + + + + def test_undo(self): + with get_pg_versions_connection() as conn: + with conn.cursor() as cursor: + self.clone = version.objects.create( + nome=uuid.uuid4().hex[0:4], + crs=self.testver.crs, + base=self.testver + ) + + sql_updt = """ + UPDATE "{schema}"."b0101031_VincDestForestale" + SET "ARTICOLO" = 'TEST' WHERE "SHAPE_AREA" > 10000; + """.format(schema=self.clone.schema) + cursor.execute(sql_updt) + + sql_add = """ + INSERT INTO "{schema}"."b0101011_Vincolo"(fid, "ARTICOLO", "DETTVINC", geom) VALUES (nextval('"{schema}"."b0101011_Vincolo_fid_seq"'::regclass), '{schema}', 99, 'MultiPolygon (((1722916.68287772010080516 5034227.90152797847986221, 1724565.71380323800258338 5035908.84918108768761158, 1725235.96508264215663075 5033802.34516010340303183, 1722916.68287772010080516 5034227.90152797847986221)))'); + """.format(schema=self.clone.schema) + print (sql_add) + cursor.execute(sql_add) + + conn.commit() + self.clone.salva_cache() + + self.clone.commit("TEST COMMIT %s" % self.clone.schema) + + self.clone.undo() + + self.assertTrue(self.clone.is_clean_(), "Undo version %s" % self.clone.nome) + + + def test_merge(self): + with get_pg_versions_connection() as conn: + with conn.cursor() as cursor: + self.clone = version.objects.create( + nome=uuid.uuid4().hex[0:4], + crs=self.testver.crs, + base=self.testver + ) + + sql_updt = """ + UPDATE "{schema}"."b0101031_VincDestForestale" + SET "ARTICOLO" = 'TEST' WHERE "SHAPE_AREA" > 10000; + """.format(schema=self.clone.schema) + cursor.execute(sql_updt) + + sql_add = """ + INSERT INTO "{schema}"."b0101011_Vincolo"(fid, "ARTICOLO", "DETTVINC", geom) VALUES (nextval('"{schema}"."b0101011_Vincolo_fid_seq"'::regclass), '{schema}', 99, 'MultiPolygon (((1722916.68287772010080516 5034227.90152797847986221, 1724565.71380323800258338 5035908.84918108768761158, 1725235.96508264215663075 5033802.34516010340303183, 1722916.68287772010080516 5034227.90152797847986221)))'); + """.format(schema=self.clone.schema) + print (sql_add) + cursor.execute(sql_add) + + conn.commit() + self.clone.salva_cache() + + self.clone.commit("TEST COMMIT %s" % self.clone.schema) + + self.clone.merge() + + self.assertTrue(self.testver.is_clean_(), "Merged %s version in %s" % (self.clone, self.testver.nome))