From c7f58006b1175ebc80292b230231cd9ed3e43503 Mon Sep 17 00:00:00 2001 From: Alen Siljak Date: Sat, 18 Nov 2017 21:52:05 +0100 Subject: [PATCH 1/4] Avoiding duplicate sqlite:/// in building the connection string when used from the reports. --- piecash/core/session.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/piecash/core/session.py b/piecash/core/session.py index 09c6388d..3c0fd7e2 100644 --- a/piecash/core/session.py +++ b/piecash/core/session.py @@ -89,7 +89,11 @@ def build_uri(sqlite_file=None, if uri_conn is None: if sqlite_file: - uri_conn = "sqlite:///{}".format(sqlite_file) + if sqlite_file.startswith("sqlite:///"): + # already have the protocol specified. + uri_conn = sqlite_file + else: + uri_conn = "sqlite:///{}".format(sqlite_file) else: uri_conn = "sqlite:///:memory:" From a618f32a7f4ec6283301497232a79ed1a46a7d8c Mon Sep 17 00:00:00 2001 From: Alen Siljak Date: Sat, 18 Nov 2017 22:15:18 +0100 Subject: [PATCH 2/4] test for the new code that avoids generation of sqlite:///sqlite:/// connection strings --- tests/test_book.py | 1 - tests/test_session.py | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_book.py b/tests/test_book.py index 864d9a74..68f6d21d 100644 --- a/tests/test_book.py +++ b/tests/test_book.py @@ -125,7 +125,6 @@ def test_create_without_FK(self): fk = insp.get_foreign_keys(tbl) assert len(fk) == 0 - class TestBook_open_book(object): def test_open_noarg(self): with pytest.raises(ValueError): diff --git a/tests/test_session.py b/tests/test_session.py index 96d98ee1..3d20f58b 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -54,3 +54,12 @@ def test_build_uri(self): db_name="pqsd", db_host="qsdqs", db_port=3434) == "mysql+pymysql://foo:pp@qsdqs:3434/pqsd?charset=utf8" + + ### Test duplicate protocol spec. This happens when the open_book is called + ### from GnuCash reports (.scm), gnucash-utilities. + sqlite_uri = "sqlite:///some_file" + uri = sqlite_uri + assert build_uri(sqlite_file=uri) == sqlite_uri + # When run with just the name (without sqlite:// prefix): + uri = "some_file" + assert build_uri(sqlite_file=uri) == sqlite_uri From b54e3aa25e16d70e3ec923cbd93401a0f8560753 Mon Sep 17 00:00:00 2001 From: Alen Siljak Date: Sat, 18 Nov 2017 22:17:21 +0100 Subject: [PATCH 3/4] making the test code easier to understand --- tests/test_session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_session.py b/tests/test_session.py index 3d20f58b..29b88095 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -58,7 +58,7 @@ def test_build_uri(self): ### Test duplicate protocol spec. This happens when the open_book is called ### from GnuCash reports (.scm), gnucash-utilities. sqlite_uri = "sqlite:///some_file" - uri = sqlite_uri + uri = "sqlite:///some_file" assert build_uri(sqlite_file=uri) == sqlite_uri # When run with just the name (without sqlite:// prefix): uri = "some_file" From bce559db6bb31a35b9ca74342a52b6e0cce87cef Mon Sep 17 00:00:00 2001 From: Alen Siljak Date: Sat, 25 Nov 2017 13:31:25 +0100 Subject: [PATCH 4/4] minor syntax correction --- piecash/core/commodity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piecash/core/commodity.py b/piecash/core/commodity.py index ae54846e..5f8f1513 100644 --- a/piecash/core/commodity.py +++ b/piecash/core/commodity.py @@ -127,7 +127,7 @@ class Commodity(DeclarativeBaseGuid): def base_currency(self): b = self.book if b is None: - raise GnucashException("The commodity should be link to a session to have a 'base_currency'") + raise GnucashException("The commodity should be linked to a session to have a 'base_currency'") if self.namespace == "CURRENCY": # get the base currency as first commodity in DB