Skip to content

Commit

Permalink
redirect QGIS to internal host for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ferregutie committed Jul 3, 2024
1 parent c85c1d7 commit 51ba115
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
15 changes: 12 additions & 3 deletions webapp/djakart/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
SRID = os.environ.get("REPO_CRS")
#SRID_CODE = SRID.split(":")[1]

if settings.TEST:
QGIS_HOST = "%s:%s" % (os.environ.get("QGIS_SERVER", 'qgis_host_internal'),os.environ.get("QGIS_PORT", 'qgis_port_internal'))
PG_HOST = os.environ.get("POSTGRES_SERVER", 'postgres_host_internal')
PG_PORT = os.environ.get("POSTGRES_PORT", 'postgres_port_internal')
else:
QGIS_HOST = os.environ.get("QGIS_SERVER_EXTERNAL", 'qgis_host_external')
PG_HOST = os.environ.get("HOST_EXTERNAL", 'postgres_host_external')
PG_PORT = os.environ.get("POSTGRES_PORT_EXTERNAL", 'postgres_port_external')

def can_modify(u,v):
return (v.riservato and u == v.referente) or not v.riservato or u.is_superuser

Expand Down Expand Up @@ -96,8 +105,8 @@ def getQgsProject(versione_obj):
#if len(vtab) == 1 and table == 'md':
# continue
table_pg_connection = {
"host": os.environ.get("HOST_EXTERNAL", 'host_external'),
"port": os.environ.get("POSTGRES_PORT_EXTERNAL", 'postgres_port_external'),
"host": PG_HOST,
"port": PG_PORT,
"dbname": os.environ.get("VERSION_DB", 'version_db'),
"user": os.environ.get("VERSION_VIEWER", 'version_viewer'),
"password": os.environ.get("VERSION_VIEWER_PASSWORD", 'version_viewer_password'),
Expand Down Expand Up @@ -128,7 +137,7 @@ def getQgsProject(versione_obj):
GROUP=VERSION&
OVERWRITE=true""".format(**wms_params)
wms_get_qgis_params = wms_get_qgis_params.replace("\n","")
host = os.environ.get("QGIS_SERVER_EXTERNAL", '')
host = QGIS_HOST
r = requests.get(host, params=wms_get_qgis_params)
if r.status_code == 200:
progetto = r.text
Expand Down
32 changes: 31 additions & 1 deletion webapp/djakart/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def destroy_kart_version(ver):
os.system('rm -f %s*.*' % version_path)
elimina_pg_schema(ver)


@override_settings(TEST=True)
class versioniTests(TestCase):

databases = '__all__'
Expand Down Expand Up @@ -157,3 +157,33 @@ def test_update(self):
connection.commit()
self.clone.salva_cache()
self.assertTrue(self.clone.cambiamenti_non_registrati, "Cloned version %s" % self.clone.nome)


def test_commit(self):
connection = get_pg_versions_connection()

cursor = connection.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)

connection.commit()
self.clone.salva_cache()

self.clone.commit("TEST COMMIT %s" % self.clone.schema)

self.assertTrue(self.clone.is_clean_(), "Cloned version %s" % self.clone.nome)
1 change: 1 addition & 0 deletions webapp/main_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

ALLOWED_HOSTS = ['*']

TEST=False

# Application definition

Expand Down

0 comments on commit 51ba115

Please sign in to comment.