<s> from tests import BaseTestCase <EOL> import mock <EOL> import time <EOL> from redash . models import User <EOL> from redash . authentication . account import invite_token <EOL> from tests . handlers import get_request , post_request <EOL> class TestInvite ( BaseTestCase ) : <EOL> def test_expired_invite_token ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as patched_time : <EOL> patched_time . return_value = time . time ( ) - ( <NUM_LIT:7> * <NUM_LIT> * <NUM_LIT> ) - <NUM_LIT:10> <EOL> token = invite_token ( self . factory . user ) <EOL> response = get_request ( '<STR_LIT>' . format ( token ) , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_invalid_invite_token ( self ) : <EOL> response = get_request ( '<STR_LIT>' , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_valid_token ( self ) : <EOL> token = invite_token ( self . factory . user ) <EOL> response = get_request ( '<STR_LIT>' . format ( token ) , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_already_active_user ( self ) : <EOL> pass <EOL> class TestInvitePost ( BaseTestCase ) : <EOL> def test_empty_password ( self ) : <EOL> token = invite_token ( self . factory . user ) <EOL> response = post_request ( '<STR_LIT>' . format ( token ) , data = { '<STR_LIT:password>' : '<STR_LIT>' } , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_invalid_password ( self ) : <EOL> token = invite_token ( self . factory . user ) <EOL> response = post_request ( '<STR_LIT>' . format ( token ) , data = { '<STR_LIT:password>' : '<STR_LIT>' } , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_bad_token ( self ) : <EOL> response = post_request ( '<STR_LIT>' . format ( '<STR_LIT>' ) , data = { '<STR_LIT:password>' : '<STR_LIT>' } , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_already_active_user ( self ) : <EOL> pass <EOL> def test_valid_password ( self ) : <EOL> token = invite_token ( self . factory . user ) <EOL> password = '<STR_LIT>' <EOL> response = post_request ( '<STR_LIT>' . format ( token ) , data = { '<STR_LIT:password>' : password } , org = self . factory . org ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . factory . user = User . get_by_id ( self . factory . user . id ) <EOL> self . assertTrue ( self . factory . user . verify_password ( password ) ) </s>
