forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parse.py
More file actions
41 lines (36 loc) · 1.54 KB
/
Copy pathtest_parse.py
File metadata and controls
41 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from sql.parse import parse
from six.moves import configparser
try:
from traitlets.config.configurable import Configurable
except ImportError:
from IPython.config.configurable import Configurable
empty_config = Configurable()
default_flags = {'persist': False, 'result_var': None}
def test_parse_no_sql():
assert parse("will:longliveliz@localhost/shakes", empty_config) == \
{'connection': "will:longliveliz@localhost/shakes",
'sql': '',
'flags': default_flags}
def test_parse_with_sql():
assert parse("postgresql://will:longliveliz@localhost/shakes SELECT * FROM work",
empty_config) == \
{'connection': "postgresql://will:longliveliz@localhost/shakes",
'sql': 'SELECT * FROM work',
'flags': default_flags}
def test_parse_sql_only():
assert parse("SELECT * FROM work", empty_config) == \
{'connection': "",
'sql': 'SELECT * FROM work',
'flags': default_flags}
def test_parse_postgresql_socket_connection():
assert parse("postgresql:///shakes SELECT * FROM work", empty_config) == \
{'connection': "postgresql:///shakes",
'sql': 'SELECT * FROM work',
'flags': default_flags}
def test_expand_environment_variables_in_connection():
os.environ['DATABASE_URL'] = 'postgresql:///shakes'
assert parse("$DATABASE_URL SELECT * FROM work", empty_config) == \
{'connection': "postgresql:///shakes",
'sql': 'SELECT * FROM work',
'flags': default_flags}