<s> from __future__ import absolute_import <EOL> import mock <EOL> from django . core . urlresolvers import reverse <EOL> from exam import fixture <EOL> from social_auth . models import UserSocialAuth <EOL> from sentry . models import UserOption , LostPasswordHash , User , ProjectStatus <EOL> from sentry . testutils import TestCase <EOL> class AppearanceSettingsTest ( TestCase ) : <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def test_requires_authentication ( self ) : <EOL> self . assertRequiresAuthentication ( self . path ) <EOL> def test_does_use_template ( self ) : <EOL> self . login_as ( self . user ) <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> def test_does_save_settings ( self ) : <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( self . path , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : True <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> options = UserOption . objects . get_all_values ( user = self . user , project = None ) <EOL> assert options . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> assert options . get ( '<STR_LIT>' ) == '<STR_LIT:2>' <EOL> assert options . get ( '<STR_LIT>' ) is True <EOL> class SettingsTest ( TestCase ) : <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def params ( self , without = ( ) ) : <EOL> params = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> } <EOL> return dict ( ( k , v ) for k , v in params . iteritems ( ) if k not in without ) <EOL> def test_requires_authentication ( self ) : <EOL> self . assertRequiresAuthentication ( self . path ) <EOL> def test_renders_with_required_context ( self ) : <EOL> self . login_as ( self . user ) <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> def test_requires_email ( self ) : <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( self . path , self . params ( without = [ '<STR_LIT:email>' ] ) ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> assert '<STR_LIT:email>' in resp . context [ '<STR_LIT>' ] . errors <EOL> def test_requires_name ( self ) : <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( self . path , self . params ( without = [ '<STR_LIT:name>' ] ) ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> assert '<STR_LIT:name>' in resp . context [ '<STR_LIT>' ] . errors <EOL> def test_minimum_valid_params ( self ) : <EOL> self . login_as ( self . user ) <EOL> params = self . params ( ) <EOL> resp = self . client . post ( self . path , params ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> user = User . objects . get ( id = self . user . id ) <EOL> assert user . name == params [ '<STR_LIT:name>' ] <EOL> assert user . email == params [ '<STR_LIT:email>' ] <EOL> def test_can_change_password ( self ) : <EOL> self . login_as ( self . user ) <EOL> params = self . params ( ) <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> resp = self . client . post ( self . path , params ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> user = User . objects . get ( id = self . user . id ) <EOL> assert user . check_password ( '<STR_LIT>' ) <EOL> class NotificationSettingsTest ( TestCase ) : <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def params ( self , without = ( ) ) : <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> return dict ( ( k , v ) for k , v in params . iteritems ( ) if k not in without ) <EOL> def test_requires_authentication ( self ) : <EOL> self . assertRequiresAuthentication ( self . path ) <EOL> def test_renders_with_required_context ( self ) : <EOL> user = self . create_user ( '<STR_LIT>' ) <EOL> organization = self . create_organization ( ) <EOL> team = self . create_team ( organization = organization ) <EOL> project = self . create_project ( organization = organization , team = team ) <EOL> team2 = self . create_team ( organization = organization ) <EOL> self . create_project ( organization = organization , team = team , status = ProjectStatus . PENDING_DELETION ) <EOL> self . create_project ( organization = organization , team = team2 ) <EOL> self . create_member ( organization = organization , user = user , teams = [ project . team ] ) <EOL> self . login_as ( user ) <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> assert len ( resp . context [ '<STR_LIT>' ] ) == <NUM_LIT:1> <EOL> def test_valid_params ( self ) : <EOL> self . login_as ( self . user ) <EOL> params = self . params ( ) <EOL> resp = self . client . post ( self . path , params ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> options = UserOption . objects . get_all_values ( user = self . user , project = None ) <EOL> assert options . get ( '<STR_LIT>' ) == '<STR_LIT>' <EOL> class ListIdentitiesTest ( TestCase ) : <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def test_requires_authentication ( self ) : <EOL> self . assertRequiresAuthentication ( self . path ) <EOL> def test_renders_with_required_context ( self ) : <EOL> self . login_as ( self . user ) <EOL> UserSocialAuth . objects . create ( user = self . user , provider = '<STR_LIT>' ) <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> assert '<STR_LIT>' in resp . context <EOL> class RecoverPasswordTest ( TestCase ) : <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def test_renders_with_required_context ( self ) : <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> def test_invalid_username ( self ) : <EOL> resp = self . client . post ( self . path , { <EOL> '<STR_LIT:user>' : '<STR_LIT>' <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert '<STR_LIT>' in resp . context <EOL> assert '<STR_LIT:user>' in resp . context [ '<STR_LIT>' ] . errors <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_valid_username ( self , send_recover_mail ) : <EOL> resp = self . client . post ( self . path , { <EOL> '<STR_LIT:user>' : self . user . username <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert '<STR_LIT:email>' in resp . context <EOL> send_recover_mail . assert_called_once_with ( ) <EOL> class RecoverPasswordConfirmTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RecoverPasswordConfirmTest , self ) . setUp ( ) <EOL> self . password_hash = LostPasswordHash . objects . create ( user = self . user ) <EOL> @ fixture <EOL> def path ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . user . id , self . password_hash . hash ] ) <EOL> def test_valid_token ( self ) : <EOL> resp = self . client . get ( self . path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> def test_invalid_token ( self ) : <EOL> resp = self . client . get ( reverse ( '<STR_LIT>' , args = [ <NUM_LIT:1> , '<STR_LIT>' ] ) ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> def test_change_password ( self ) : <EOL> resp = self . client . post ( self . path , { <EOL> '<STR_LIT:password>' : '<STR_LIT:bar>' , <EOL> '<STR_LIT>' : '<STR_LIT:bar>' <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> user = User . objects . get ( id = self . user . id ) <EOL> assert user . check_password ( '<STR_LIT:bar>' ) </s>
