Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enricofer committed Sep 4, 2024
1 parent 7872ef2 commit 8164ca5
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions webapp/djakart/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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))

0 comments on commit 8164ca5

Please sign in to comment.