-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_parse_uri.py
More file actions
147 lines (122 loc) · 4.94 KB
/
test_parse_uri.py
File metadata and controls
147 lines (122 loc) · 4.94 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import os
from sqlobject.dbconnection import DBConnection
from sqlobject.sqlite.sqliteconnection import SQLiteConnection
########################################
# Test _parseURI
########################################
def test_parse():
_parseURI = DBConnection._parseURI
user, password, host, port, path, args = _parseURI("mysql://host/database")
assert user is None
assert password is None
assert host == "host"
assert port is None
assert path == "/database"
assert args == {}
user, password, host, port, path, args = _parseURI(
"mysql://user:pass%20word@host/database?unix_socket=/var/mysql/socket")
assert user == "user"
assert password == "pass word"
assert host == "host"
assert port is None
assert path == "/database"
assert args == {"unix_socket": "/var/mysql/socket"}
user, password, host, port, path, args = \
_parseURI("postgres://user@host/database")
assert user == "user"
assert password is None
assert host == "host"
assert port is None
assert path == "/database"
assert args == {}
user, password, host, port, path, args = \
_parseURI("postgres://host:5432/database")
assert user is None
assert password is None
assert host == "host"
assert port == 5432
assert path == "/database"
assert args == {}
user, password, host, port, path, args = \
_parseURI("postgres:///full/path/to/socket/database")
assert user is None
assert password is None
assert host is None
assert port is None
assert path == "/full/path/to/socket/database"
assert args == {}
user, password, host, port, path, args = \
_parseURI("postgres://us%3Aer:p%40ssword@host/database")
assert user == "us:er"
assert password == "p@ssword"
assert host == "host"
assert port is None
assert path == "/database"
assert args == {}
user, password, host, port, path, args = \
_parseURI("sqlite:///full/path/to/database")
assert user is None
assert password is None
assert host is None
assert port is None
assert path == "/full/path/to/database"
assert args == {}
user, password, host, port, path, args = _parseURI("sqlite:/:memory:")
assert user is None
assert password is None
assert host is None
assert port is None
assert path == "/:memory:"
assert args == {}
if os.name == 'nt':
user, password, host, port, path, args = \
_parseURI("sqlite:/C|/full/path/to/database")
assert user is None
assert password is None
assert host is None
assert port is None
assert path == "C:/full/path/to/database"
assert args == {}
user, password, host, port, path, args = \
_parseURI("sqlite:///C:/full/path/to/database")
assert user is None
assert password is None
assert host is None
assert port is None
assert path == "C:/full/path/to/database"
assert args == {}
def test_uri():
connection = DBConnection()
connection.close = lambda: None
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'mysql', 'host', None, None, None, 'database'
assert connection.uri() == "mysql://host/database"
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'mysql', 'host', None, 'user', 'pass word', 'database'
assert connection.uri() == "mysql://user:pass%20word@host/database"
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'postgres', 'host', None, 'user', None, 'database'
assert connection.uri() == "postgres://user@host/database"
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'postgres', 'host', 5432, None, None, 'database'
assert connection.uri() == "postgres://host:5432/database"
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'postgres', None, None, None, None, '/full/path/to/socket/database'
assert connection.uri() == "postgres:///full/path/to/socket/database"
connection.dbName, connection.host, connection.port, \
connection.user, connection.password, connection.db = \
'postgres', 'host', None, 'us:er', 'p@ssword', 'database'
assert connection.uri() == "postgres://us%3Aer:p%40ssword@host/database"
connection = SQLiteConnection(None)
connection.filename = '/full/path/to/database'
assert connection.uri() == "sqlite:///full/path/to/database"
connection.filename = ':memory:'
assert connection.uri() == "sqlite:/:memory:"
if os.name == 'nt':
connection.filename = 'C:/full/path/to/database'
assert connection.uri() == "sqlite:///C%3A/full/path/to/database"