-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix initialization of Database sqlalchemy_uri and password (#1137)
* move initialization of Database sqlalchemy_uri and password from DatabaseView.pre_add to utils.get_or_create_main_db. Unit tests for mysql and postgres include username and password in the SQLALCHEMY_DATABASE_URI. * modified test_testconn to work with sqlalchemy uri with a username and password.
- Loading branch information
1 parent
afa1f09
commit ca66ba4
Showing
6 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,17 +115,30 @@ def test_misc(self): | |
assert self.client.get('/ping').data.decode('utf-8') == "OK" | ||
|
||
def test_testconn(self): | ||
data = json.dumps({'uri': 'sqlite:////tmp/caravel_unittests.db'}) | ||
database = ( | ||
db.session | ||
.query(models.Database) | ||
.filter_by(database_name='main') | ||
.first() | ||
) | ||
|
||
# validate that the endpoint works with the password-masked sqlalchemy uri | ||
data = json.dumps({ | ||
'uri': database.safe_sqlalchemy_uri(), | ||
'name': 'main' | ||
}) | ||
response = self.client.post('/caravel/testconn', data=data, content_type='application/json') | ||
assert response.status_code == 200 | ||
|
||
# validate that the endpoint works with the decrypted sqlalchemy uri | ||
data = json.dumps({ | ||
'uri': 'postgresql+psycopg2://foo:[email protected]/bar', | ||
'uri': database.sqlalchemy_uri_decrypted, | ||
'name': 'main' | ||
}) | ||
response = self.client.post('/caravel/testconn', data=data, content_type='application/json') | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_warm_up_cache(self): | ||
slice = db.session.query(models.Slice).first() | ||
resp = self.client.get( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters