1
+ # -*- coding: utf-8 -*-
1
2
# MySQL Connector/Python - MySQL driver written in Python.
2
3
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
4
33
34
34
35
LOGGER = logging .getLogger (tests .LOGGER_NAME )
35
36
37
+ _URI_TEST_RESULTS = ( # (uri, result)
38
+ ("127.0.0.1" , None ),
39
+ ("localhost" , None ),
40
+ ("domain.com" , None ),
41
+ (
"user:[email protected] " , {
"database" :
"" ,
"host" :
"127.0.0.1" ,
42
+ "password" : "password" , "port" : 33060 ,
43
+ "user" : "user" }),
44
+ ("user:@127.0.0.1" , {"database" : "" , "host" : "127.0.0.1" , "password" : "" ,
45
+ "port" : 33060 , "user" : "user" }),
46
+ ("mysqlx://user:@127.0.0.1" , {"database" : "" , "host" : "127.0.0.1" ,
47
+ "password" : "" , "port" : 33060 ,
48
+ "user" : "user" }),
49
+ ("mysqlx://user@[2001:db8:85a3:8d3:1319:8a2e:370:7348]:1" , None ),
50
+ ("mysqlx://user:password@[2001:db8:85a3:8d3:1319:8a2e:370:7348]:1" ,
51
+ {"database" : "" , "host" : "2001:db8:85a3:8d3:1319:8a2e:370:7348" ,
52
+ "password" : "password" , "port" : 1 , "user" : "user" }),
53
+
54
+ {"database" : "" , "host" : "127.0.0.1" , "password" : "unicode" ,
55
+ "port" : 33060 , "user" : "áé'í'óú" }),
56
+ )
57
+
36
58
37
59
@unittest .skipIf (tests .MYSQL_VERSION < (5 , 7 , 12 ), "XPlugin not compatible" )
38
60
class MySQLxXSessionTests (tests .MySQLxTests ):
@@ -54,6 +76,24 @@ def test___init__(self):
54
76
}
55
77
self .assertRaises (TypeError , mysqlx .XSession , bad_config )
56
78
79
+ def test_connection_uri (self ):
80
+ uri = ("mysqlx://{user}:{password}@{host}:{port}/{schema}"
81
+ "" .format (user = self .connect_kwargs ["user" ],
82
+ password = self .connect_kwargs ["password" ],
83
+ host = self .connect_kwargs ["host" ],
84
+ port = self .connect_kwargs ["port" ],
85
+ schema = self .connect_kwargs ["database" ]))
86
+ session = mysqlx .get_session (uri )
87
+ self .assertIsInstance (session , mysqlx .XSession )
88
+
89
+ # Test URI parser function
90
+ for uri , res in _URI_TEST_RESULTS :
91
+ try :
92
+ settings = mysqlx ._get_connection_settings (uri )
93
+ self .assertEqual (res , settings )
94
+ except mysqlx .Error :
95
+ self .assertEqual (res , None )
96
+
57
97
def test_get_schema (self ):
58
98
schema = self .session .get_schema (self .schema_name )
59
99
self .assertTrue (schema , mysqlx .Schema )
@@ -96,6 +136,24 @@ def test___init__(self):
96
136
}
97
137
self .assertRaises (TypeError , mysqlx .NodeSession , bad_config )
98
138
139
+ def test_connection_uri (self ):
140
+ uri = ("mysqlx://{user}:{password}@{host}:{port}/{schema}"
141
+ "" .format (user = self .connect_kwargs ["user" ],
142
+ password = self .connect_kwargs ["password" ],
143
+ host = self .connect_kwargs ["host" ],
144
+ port = self .connect_kwargs ["port" ],
145
+ schema = self .connect_kwargs ["database" ]))
146
+ session = mysqlx .get_node_session (uri )
147
+ self .assertIsInstance (session , mysqlx .NodeSession )
148
+
149
+ # Test URI parser function
150
+ for uri , res in _URI_TEST_RESULTS :
151
+ try :
152
+ settings = mysqlx ._get_connection_settings (uri )
153
+ self .assertEqual (res , settings )
154
+ except mysqlx .Error :
155
+ self .assertEqual (res , None )
156
+
99
157
def test_get_schema (self ):
100
158
schema = self .session .get_schema (self .schema_name )
101
159
self .assertTrue (schema , mysqlx .Schema )
0 commit comments