Skip to content

Commit

Permalink
Merge pull request #41 from MisterY/con-str
Browse files Browse the repository at this point in the history
Avoiding duplicate protocol spec
  • Loading branch information
sdementen committed Dec 21, 2017
2 parents 3c2b994 + bce559d commit 2d9cba8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion piecash/core/commodity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion piecash/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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:"

Expand Down
1 change: 0 additions & 1 deletion tests/test_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:///some_file"
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

0 comments on commit 2d9cba8

Please sign in to comment.