File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
piccolo/apps/user/commands Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 11import sys
2- from getpass import getpass
32
43from piccolo .apps .user .tables import BaseUser
4+ from piccolo .apps .user .commands .create import (
5+ get_username ,
6+ get_password ,
7+ get_confirmed_password ,
8+ )
59
610
711def change_password ():
812 """
913 Change a user's password.
1014 """
11- username = input ("Enter username:\n " )
12-
13- password = getpass ("Enter password:\n " )
14- confirmed_password = getpass ("Confirm password:\n " )
15+ username = get_username ()
16+ password = get_password ()
17+ confirmed_password = get_confirmed_password ()
1518
1619 if not password == confirmed_password :
1720 print ("Passwords don't match!" )
Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+ from unittest .mock import patch
3+
4+ from piccolo .apps .user .commands .change_password import change_password
5+ from piccolo .apps .user .tables import BaseUser
6+
7+
8+ class TestChangePassword (TestCase ):
9+ def setUp (self ):
10+ BaseUser .create_table (if_not_exists = True ).run_sync ()
11+
12+ def tearDown (self ):
13+ BaseUser .alter ().drop_table ().run_sync ()
14+
15+ @patch (
16+ "piccolo.apps.user.commands.change_password.get_username" ,
17+ return_value = "bob123" ,
18+ )
19+ @patch (
20+ "piccolo.apps.user.commands.change_password.get_password" ,
21+ return_value = "new_password" ,
22+ )
23+ @patch (
24+ "piccolo.apps.user.commands.change_password.get_confirmed_password" ,
25+ return_value = "new_password" ,
26+ )
27+ def test_create (self , * args , ** kwargs ):
28+ user = BaseUser (username = "bob123" , password = "old_password" )
29+ user .save ().run_sync ()
30+
31+ change_password ()
32+
33+ self .assertTrue (
34+ BaseUser .login_sync (username = "bob123" , password = "new_password" )
35+ is not None
36+ )
You can’t perform that action at this time.
0 commit comments