Skip to content
This repository has been archived by the owner on Jun 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #88 from Oslandia/qgis2to3
Browse files Browse the repository at this point in the history
Migrate plugin from QGIS2 to QGIS3
  • Loading branch information
troopa81 authored Mar 13, 2019
2 parents f971c38 + e513bec commit 62ce1e9
Show file tree
Hide file tree
Showing 33 changed files with 641 additions and 639 deletions.
17 changes: 4 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
dist: trusty
language: ruby

services:
- postgresql

addons:
postgresql: "9.6"
apt:
packages:
- postgresql-9.6-postgis-2.3
- docker

before_install:
- sudo apt search gdal libspatialite
- sudo apt-get install -y gdal-bin python-pyspatialite python-psycopg2 python-pip libspatialite5
- docker build . -t qgis-versioning-test

script:
- python --version
- cd test
- python ./tests.py 127.0.0.1 postgres -v
- docker run qgis-versioning-test
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM debian:buster

RUN apt-get update \
&& apt-get install -y postgresql-11-postgis-2.5 libsqlite3-mod-spatialite python3-psycopg2 gdal-bin

# to be able to connect locally
RUN echo "host all all 127.0.0.1/32 trust" > /etc/postgresql/11/main/pg_hba.conf

COPY . qgis-versioning
WORKDIR qgis-versioning/test

CMD service postgresql start && python3 tests.py 127.0.0.1 postgres -v
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[general]
name=versioning
qgisMinimumVersion=2.8
qgisMinimumVersion=3.4
description=postgis database versioning
version=0.9
author=Oslandia
Expand Down
2 changes: 1 addition & 1 deletion package.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def install(install_dir, zip_filename):
uninstall(install_dir)
with zipfile.ZipFile(zip_filename, "r") as z:
z.extractall(install_dir)
print "installed in", install_dir
print("installed in", install_dir)

def zip_(zip_filename):
"""the zip file include tests"""
Expand Down
614 changes: 284 additions & 330 deletions plugin.py

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions test/abbreviation_bug_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
from __future__ import absolute_import
import sys
sys.path.insert(0, '..')

from versioningDB import versioning
from pyspatialite import dbapi2
from sqlite3 import dbapi2
import psycopg2
import os
import shutil
Expand Down Expand Up @@ -48,6 +48,8 @@ def test(host, pguser):
assert( os.path.isfile(sqlite_test_filename) and "sqlite file must exist at this point" )

scon = dbapi2.connect(sqlite_test_filename)
scon.enable_load_extension(True)
scon.execute("SELECT load_extension('mod_spatialite')")
scur = scon.cursor()
scur.execute("SELECT * from junctions")
for rec in scur:
Expand All @@ -56,21 +58,21 @@ def test(host, pguser):

scur.execute("update junctions_view set id='this_is_another_edited_very_long_name_that should_be_trunctated_if_buggy' where ogc_fid > 8")

scur.execute("insert into junctions_view(id, elevation, geometry) select 'newly inserted with long name', elevation, geometry from junctions_view where ogc_fid=4")
scur.execute("insert into junctions_view(id, elevation, geom) select 'newly inserted with long name', elevation, geom from junctions_view where ogc_fid=4")
scon.commit()

spversioning.commit('a commit msg')

pcur.execute("select jid, id from epanet_trunk_rev_head.junctions")
for row in pcur:
print row
print(row)
if row[0] > 8:
assert row[1].find('this_is_another_edited_very_long_name_that should_be_trunctated_if_buggy') != -1\
or row[1].find('newly inserted with long name') != -1

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python2 versioning_base_test.py host pguser")
print("Usage: python3 versioning_base_test.py host pguser")
else:
test(*sys.argv[1:])

19 changes: 7 additions & 12 deletions test/archiving_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python2
#!/usr/bin/env python3
from __future__ import absolute_import
import sys
sys.path.insert(0, '..')
Expand All @@ -20,8 +20,7 @@ def printTab(pcur, schema, table):
pcur.execute("""SELECT column_name FROM information_schema.columns WHERE
table_schema = '{schema}' AND table_name = '{table}'""".format(schema=schema,
table=table))
lcols = pcur.fetchall()
cols = ', '.join(list(zip(*lcols)[0]))
cols = ",".join([i[0] for i in pcur.fetchall()])
print(cols)

pcur.execute("""SELECT * FROM {schema}.{table} ORDER BY {pk}""".format(schema=schema, table=table, pk=pk))
Expand Down Expand Up @@ -103,31 +102,27 @@ def test(host, pguser):
[ret] = pcur.fetchone()
assert(ret == 9)
pcur.execute("SELECT pid FROM epanet.pipes ORDER BY pid")
ret = pcur.fetchall()
assert(list(zip(*ret)[0]) == [1, 2, 4, 6, 7, 8, 9, 10, 11])
assert([i[0] for i in pcur.fetchall()] == [1, 2, 4, 6, 7, 8, 9, 10, 11])
printTab(pcur, 'epanet_archive', 'pipes')
pcur.execute("SELECT count(*) FROM epanet_archive.pipes")
[ret] = pcur.fetchone()
assert(ret == 2)
pcur.execute("SELECT pid FROM epanet_archive.pipes ORDER BY pid")
ret = pcur.fetchall()
assert(list(zip(*ret)[0]) == [3, 5])
assert([i[0] for i in pcur.fetchall()] == [3, 5])

versioning.archive(pg_conn_info, 'epanet', 11)
printTab(pcur, 'epanet', 'pipes')
pcur.execute("SELECT count(*) FROM epanet.pipes")
[ret] = pcur.fetchone()
assert(ret == 7)
pcur.execute("SELECT pid FROM epanet.pipes ORDER BY pid")
ret = pcur.fetchall()
assert(list(zip(*ret)[0]) == [2, 4, 6, 8, 9, 10, 11])
assert([i[0] for i in pcur.fetchall()] == [2, 4, 6, 8, 9, 10, 11])
printTab(pcur, 'epanet_archive', 'pipes')
pcur.execute("SELECT count(*) FROM epanet_archive.pipes")
[ret] = pcur.fetchone()
assert(ret == 4)
pcur.execute("SELECT pid FROM epanet_archive.pipes ORDER BY pid")
ret = pcur.fetchall()
assert(list(zip(*ret)[0]) == [1, 3, 5, 7])
assert([i[0] for i in pcur.fetchall()] == [1, 3, 5, 7])

# view
printTab(pcur, 'epanet_archive', 'pipes_all')
Expand All @@ -141,6 +136,6 @@ def test(host, pguser):
pcur.close()
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python2 archiving_test.py host pguser")
print("Usage: python3 archiving_test.py host pguser")
else:
test(*sys.argv[1:])
8 changes: 4 additions & 4 deletions test/bug_in_branch_after_commit.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
from __future__ import absolute_import
import sys
sys.path.insert(0, '..')

from versioningDB import versioning
from pyspatialite import dbapi2
from sqlite3 import dbapi2
import os
import tempfile

Expand Down Expand Up @@ -42,6 +42,6 @@ def test(host, pguser):

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python2 versioning_base_test.py host pguser")
print("Usage: python3 versioning_base_test.py host pguser")
else:
test(*sys.argv[1:])
test(*sys.argv[1:])
17 changes: 17 additions & 0 deletions test/create_db_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

SCRIPT_DIR=$(dirname $(readlink -f $0))

for db in epanet_test_db epanet_test_db_copy;
do
dropdb --if-exists -h 127.0.01 -U postgres $db
createdb -h 127.0.01 -U postgres $db
psql -h 127.0.01 -U postgres $db -c 'CREATE EXTENSION postgis'
psql -h 127.0.01 -U postgres $db -f $SCRIPT_DIR/epanet_test_db_wo_versioning.sql
done

EMPTY_DB="qgis_versioning_empty_db"
dropdb --if-exists -h 127.0.01 -U postgres $EMPTY_DB
createdb -h 127.0.01 -U postgres $EMPTY_DB
psql -h 127.0.01 -U postgres $EMPTY_DB -c 'CREATE EXTENSION postgis'

39 changes: 39 additions & 0 deletions test/epanet_test_db_wo_versioning.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE SCHEMA epanet;

CREATE TABLE epanet.junctions (
jid serial PRIMARY KEY,
id varchar,
elevation float,
base_demand_flow float,
demand_pattern_id varchar,
geom geometry('POINT',2154)
);

INSERT INTO epanet.junctions
(id, elevation, geom)
VALUES
('0',0,ST_GeometryFromText('POINT(1 0)',2154));

INSERT INTO epanet.junctions
(id, elevation, geom)
VALUES
('1',1,ST_GeometryFromText('POINT(0 1)',2154));

CREATE TABLE epanet.pipes (
pid serial PRIMARY KEY,
id varchar,
start_node varchar,
end_node varchar,
length float,
diameter float,
roughness float,
minor_loss_coefficient float,
status varchar,
geom geometry('LINESTRING',2154)
);

INSERT INTO epanet.pipes
(id, start_node, end_node, length, diameter, geom)
VALUES
('0','0','1',1,2,ST_GeometryFromText('LINESTRING(1 0,0 1)',2154));
4 changes: 2 additions & 2 deletions test/history_creation_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
from __future__ import absolute_import
import sys
sys.path.insert(0, '..')
Expand Down Expand Up @@ -107,6 +107,6 @@ def test(host, pguser):

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python2 versioning_base_test.py host pguser")
print("Usage: python3 versioning_base_test.py host pguser")
else:
test(*sys.argv[1:])
Loading

0 comments on commit 62ce1e9

Please sign in to comment.