Merge lp:~free.ekanayaka/storm/get-uri into lp:storm

Proposed by Free Ekanayaka
Status: Merged
Merged at revision: 476
Proposed branch: lp:~free.ekanayaka/storm/get-uri
Merge into: lp:storm
Diff against target: 70 lines (+17/-0)
5 files modified
storm/database.py (+7/-0)
storm/databases/mysql.py (+1/-0)
storm/databases/postgres.py (+1/-0)
storm/databases/sqlite.py (+1/-0)
tests/databases/base.py (+7/-0)
To merge this branch: bzr merge lp:~free.ekanayaka/storm/get-uri
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Review via email: mp+261950@code.launchpad.net

Description of the change

Add a Database.get_uri() method for returning the URI the database was created with. This is useful for code that needs to look at connection details.

To post a comment you must log in.
lp:~free.ekanayaka/storm/get-uri updated
477. By Free Ekanayaka

Improve test

Revision history for this message
Alberto Donato (ack) wrote :

Looks good, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/database.py'
2--- storm/database.py 2013-02-06 21:38:40 +0000
3+++ storm/database.py 2015-06-15 12:06:51 +0000
4@@ -479,6 +479,13 @@
5
6 connection_factory = Connection
7
8+ def __init__(self, uri):
9+ self._uri = uri
10+
11+ def get_uri(self):
12+ """Return the URI object this database was created with."""
13+ return self._uri
14+
15 def connect(self, event=None):
16 """Create a connection to the database.
17
18
19=== modified file 'storm/databases/mysql.py'
20--- storm/databases/mysql.py 2011-09-22 09:16:49 +0000
21+++ storm/databases/mysql.py 2015-06-15 12:06:51 +0000
22@@ -127,6 +127,7 @@
23 _converters = None
24
25 def __init__(self, uri):
26+ super(MySQL, self).__init__(uri)
27 if MySQLdb is dummy:
28 raise DatabaseModuleError("'MySQLdb' module not found")
29 self._connect_kwargs = {}
30
31=== modified file 'storm/databases/postgres.py'
32--- storm/databases/postgres.py 2015-06-04 13:22:54 +0000
33+++ storm/databases/postgres.py 2015-06-15 12:06:51 +0000
34@@ -377,6 +377,7 @@
35 _version = None
36
37 def __init__(self, uri):
38+ super(Postgres, self).__init__(uri)
39 if psycopg2 is dummy:
40 raise DatabaseModuleError(
41 "'psycopg2' >= %s not found. Found %s."
42
43=== modified file 'storm/databases/sqlite.py'
44--- storm/databases/sqlite.py 2013-09-30 13:48:38 +0000
45+++ storm/databases/sqlite.py 2015-06-15 12:06:51 +0000
46@@ -178,6 +178,7 @@
47 connection_factory = SQLiteConnection
48
49 def __init__(self, uri):
50+ super(SQLite, self).__init__(uri)
51 if sqlite is dummy:
52 raise DatabaseModuleError("'pysqlite2' module not found")
53 self._filename = uri.database or ":memory:"
54
55=== modified file 'tests/databases/base.py'
56--- tests/databases/base.py 2012-03-28 10:57:43 +0000
57+++ tests/databases/base.py 2015-06-15 12:06:51 +0000
58@@ -102,6 +102,13 @@
59 def test_create(self):
60 self.assertTrue(isinstance(self.database, Database))
61
62+ def test_get_uri(self):
63+ """
64+ The get_uri() method returns the URI the database with created with.
65+ """
66+ uri = self.database.get_uri()
67+ self.assertIsNotNone(uri.scheme)
68+
69 def test_connection(self):
70 self.assertTrue(isinstance(self.connection, Connection))
71

Subscribers

People subscribed via source and target branches

to status/vote changes: