def test_returns_true_when_username_and_password_are_equal(self): credential_a = credential.Credential( 'johndoe', 'password', ) credential_b = credential.Credential( 'johndoe', 'password', ) assert credential_a == credential_b
def test_returns_false_when_username_is_different(self): credential_a = credential.Credential( 'johndoe', 'password', ) credential_b = credential.Credential( 'fulano', 'password', ) assert credential_a != credential_b
def test_returns_false_when_password_is_different(self): credential_a = credential.Credential( 'johndoe', 'password1', ) credential_b = credential.Credential( 'johndoe', 'password2', ) assert credential_a != credential_b
def test_creates_credential_instance(self): my_credential = credential.Credential( 'username', 'password1', ) assert isinstance(my_credential, credential.Credential)
def test_set_active_to_false_when_deactivates(self): my_credential = credential.Credential( username='******', active=True ) my_credential.deactivate() assert not my_credential.active
def test_returns_true_when_password_matches(self): password = '******' my_credential = credential.Credential( username='******', ) my_credential.set_password(password) assert my_credential.verify_password(password)
def test_returns_false_when_password_does_not_match(self): my_credential = credential.Credential( username='******', ) my_credential.set_password("pass1word") assert not my_credential.verify_password('password')
def test_can_save_credential(session): _credential = credential.Credential(username='******', ) _credential.set_password('Password1') session.add(_credential) session.commit() assert session.query(credential.Credential).first() == _credential
def test_keeps_password_value_when_is_passed(self): password = '******' my_credential = credential.Credential( 'username', password, ) assert my_credential.password == password
def test_set_password(self): my_credential = credential.Credential( 'username', 'password1', ) old_pass = my_credential.password my_credential.set_password('new_password1') assert old_pass != my_credential.password
def test_can_verify_credential_retrieved(session): _credential = credential.Credential(username='******', ) _credential.set_password('Password1') session.add(_credential) session.commit() retrieved = session.query(credential.Credential).first() assert retrieved.verify_password('Password1')
def test_returns_true_when_object_is_the_same_after_retrieving(session): _credential = credential.Credential(username='******', ) _credential.set_password('Password1') session.add(_credential) session.commit() retrieved = session.query(credential.Credential).first() assert retrieved == _credential assert isinstance(retrieved._password, password.Password)
def setup(self): self.params = { "username": "******", "password": "******", "active": True } self.credential = credential.Credential( self.params['username'], self.params['password'], self.params['active'], )
def add_credential(username: str, password: str, uow: unit_of_work.AbstractUnitOfWork) -> str: with uow: new_credential = credential.Credential(username=username, ) new_credential.set_password(password) uow.credentials.add(new_credential) uow.commit() return f'Credential created for {username}'
def test_can_add_credential(self, session): _credential = credential.Credential( username='******', ) _credential.set_password('Password1') repo = repository.SqlAlchemyRepositoryCredentials(session) repo.add(_credential) session.commit() assert session.query(credential.Credential).first() == _credential
def test_raises_credential_value_error_when_has_no_username(self): with pytest.raises(exceptions.CredentialValueError, match='All arguments are required'): credential.Credential(None, 'password')