<s> from __future__ import absolute_import , unicode_literals <EOL> import mock <EOL> from django . test import TestCase <EOL> from physical . tests import factory as factory_physical <EOL> from drivers . fake import FakeDriver <EOL> from . . models import Credential <EOL> from . import factory as factory_logical <EOL> class CredentialTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . instance = factory_physical . InstanceFactory ( ) <EOL> self . databaseinfra = self . instance . databaseinfra <EOL> self . database = factory_logical . DatabaseFactory ( <EOL> databaseinfra = self . databaseinfra ) <EOL> def tearDown ( self ) : <EOL> self . database . delete ( ) <EOL> def test_create_credential ( self ) : <EOL> credential = Credential . objects . create ( <EOL> user = "<STR_LIT>" , password = "<STR_LIT>" , database = self . database ) <EOL> self . assertTrue ( credential . pk ) <EOL> def test_slugify_user_credential ( self ) : <EOL> credential = Credential . create_new_credential ( <EOL> user = "<STR_LIT>" , database = self . database ) <EOL> self . assertTrue ( credential . pk ) <EOL> self . assertEqual ( credential . user , '<STR_LIT>' ) <EOL> def test_underscore_in_slugged_user_credential ( self ) : <EOL> credential = Credential . objects . create ( <EOL> user = "<STR_LIT>" , password = "<STR_LIT>" , database = self . database ) <EOL> self . assertTrue ( credential . pk ) <EOL> self . assertEqual ( credential . user , "<STR_LIT>" ) <EOL> def test_cannot_edit_user_credential ( self ) : <EOL> credential = factory_logical . CredentialFactory ( database = self . database ) <EOL> self . assertTrue ( credential . pk ) <EOL> credential . user = "<STR_LIT>" <EOL> self . assertRaises ( AttributeError , credential . save ) <EOL> def test_cannot_edit_database_credential ( self ) : <EOL> credential = factory_logical . CredentialFactory ( database = self . database ) <EOL> another_database = factory_logical . DatabaseFactory ( <EOL> databaseinfra = self . databaseinfra ) <EOL> credential . database = another_database <EOL> self . assertRaises ( AttributeError , credential . save ) <EOL> @ mock . patch . object ( FakeDriver , '<STR_LIT>' ) <EOL> def test_delete_model_remove_credentials_from_driver ( self , remove_user ) : <EOL> credential = factory_logical . CredentialFactory ( ) <EOL> credential . delete ( ) <EOL> remove_user . assert_called_once_with ( credential ) </s>
