1+ """
2+ Collection of test cases to test connection module.
3+ """
4+
5+ import datajoint as dj
6+ from datajoint import DataJointError
7+ import numpy as np
8+ from . import CONN_INFO_ROOT , connection_root , connection_test
9+
10+ from . import PREFIX
11+ import pymysql
12+ import pytest
13+
14+
15+ def test_set_password_prompt_match (monkeypatch ):
16+ """
17+ Should be able to change the password using user prompt
18+ """
19+ c = dj .conn (** CONN_INFO_ROOT )
20+ c .query ("CREATE USER 'alice'@'%' IDENTIFIED BY 'pass';" )
21+ # prompt responses: new password / confirm password / update local setting?
22+ responses = ["newpass" , "newpass" , "yes" ]
23+ monkeypatch .setattr ('getpass.getpass' , lambda _ : next (responses ))
24+ monkeypatch .setattr ('input' , lambda _ : next (responses ))
25+
26+ dj .set_password ()
27+
28+ with pytest .raises (pymysql .err .OperationalError ):
29+ # should not be able to log in with old credentials
30+ dj .conn (host = CONN_INFO_ROOT ["host" ], user = "alice" , password = "pass" )
31+
32+ # should be able to log in with new credentials
33+ dj .conn (host = CONN_INFO_ROOT ["host" ], user = "alice" , password = "newpass" )
34+
35+ assert dj .config ["database.password" ] == "newpass"
36+
37+ def test_set_password_prompt_mismatch (monkeypatch ):
38+ """
39+ Should not be able to change the password when passwords do not match
40+ """
41+ pass
42+
43+ def test_set_password_arg (monkeypatch ):
44+ """
45+ Should be able to change the password with an argument
46+ """
47+ pass
48+
49+ def test_set_password_no_update_config (monkeypatch ):
50+ """
51+ Should be able to change the password without updating local config
52+ """
53+ pass
0 commit comments