def test_update_password(self, update_user): instance = DjangoCredentialRepository() credential = Credential('john.smith', uuid=UUID_MOCK) credential.set_password('P@ssw0rd') credential = instance.update_password(credential) assert bool(credential.password) is True
def test_update_active_attribute(self, update_user): instance = DjangoCredentialRepository() credential = Credential('john.smith', 'P@ssw0rd', uuid=UUID_MOCK) credential.deactivate() credential = instance.update_status(credential) assert credential.active is False
def _factory_credential(self, user: UserAccount) -> Credential: if user: return Credential( user.username, user.password, uuid=user.uuid, active=user.is_active )
def test_return_credential(self, mocker): user = UserAccount(username='******', password='******') mocker.patch.object(UserAccount, 'save', return_value=user) instance = DjangoCredentialRepository() new_credential = instance.create( Credential(user.username, user.password)) assert isinstance(new_credential, Credential)
def test_when_username_does_not_exists_persists_the_data( self, get_instance, mocker): instance = get_instance EmptyRepository.create = mocker.MagicMock( return_value=Credential('smith')) instance.execute() assert EmptyRepository.create.called
def create_credential_response(mocker): credential = Credential('john.smith', 'P@ssw0rd') mocker.patch.object(DjangoCredentialRepository, 'create', return_value=credential) mocker.patch.object(DjangoCredentialRepository, 'find_by', return_value=None) instance = AuthService() return instance.create_credential('john.smith', 'P@ssw0rd')
def test_persist_user_account(self, update_user): instance = DjangoCredentialRepository() instance.update_password( Credential('john.smith4', 'P@ssw0rd', uuid=UUID_MOCK)) assert update_user.called is True
def test_persist_user_account(self, mocker): create_user = mocker.patch.object(UserAccount, 'save') instance = DjangoCredentialRepository() instance.create(Credential('john.smith4', 'P@ssw0rd')) assert create_user.called is True
def find_by(self, username): return Credential(username, 'P@ssw0rd')
def _factory_credential(self) -> Credential: instance = Credential(self.__username) instance.set_password(self.__password) return instance
def get_instance(): return Credential('john.smith')
def test_when_password_is_provided_set_credential_password(self): instance = Credential('john.smith', 'P@ssw0rd') assert isinstance(instance.password, Password)
def test_when_active_is_provided_set_credential_active(self): expected_result = False instance = Credential('john.smith', active=expected_result) assert instance.active == expected_result
def test_when_username_is_not_provided_raise_exception(self): with pytest.raises(ValueError): Credential(None)
def test_when_uuid_is_provided_set_credential_uuid(self): expected_result = uuid4() instance = Credential('john.smith', uuid=expected_result) assert instance.uuid == expected_result