def test_error_hydration(): error = Neo4jError.hydrate({"code": "Neo.ClientError.General.Error", "message": "Oops"}) assert isinstance(error, ClientError) assert error.code == "Neo.ClientError.General.Error" assert error.classification == "ClientError" assert error.category == "General" assert error.title == "Error" assert error.message == "Oops"
def test_unknown_error(): error = Neo4jError("Oops", "Neo.UnknownError.General.Error") assert isinstance(error, Neo4jError) assert error.code == "Neo.UnknownError.General.Error" assert error.classification == "UnknownError" assert error.category == "General" assert error.title == "Error" assert error.message == "Oops" assert str(error) == "[General.Error] Oops"
def test_transient_error(): error = Neo4jError("Oops", "Neo.TransientError.General.Error") assert isinstance(error, TransientError) assert error.code == "Neo.TransientError.General.Error" assert error.classification == "TransientError" assert error.category == "General" assert error.title == "Error" assert error.message == "Oops" assert str(error) == "[General.Error] Oops"
def test_database_error(): error = Neo4jError("Oops", "Neo.DatabaseError.General.Error") assert isinstance(error, DatabaseError) assert error.code == "Neo.DatabaseError.General.Error" assert error.classification == "DatabaseError" assert error.category == "General" assert error.title == "Error" assert error.message == "Oops" assert str(error) == "[General.Error] Oops"
def test_bad_code_part_count(): with raises(ValueError): _ = Neo4jError("Oops", "Neo.ClientError.Error")
def test_bad_code_prefix(): with raises(ValueError): _ = Neo4jError("Oops", "Fake.ClientError.General.Error")
def test_bad_code_type(): with raises(ValueError): _ = Neo4jError("Oops", None)
def test_lock_client_stopped_error_should_not_retry(): error = Neo4jError("Oops", "Neo.TransientError.Transaction.LockClientStopped") assert not error.should_retry()
def set_failure(self, **metadata): self._status = 2 self._failure = Neo4jError.hydrate(metadata)
def test_transient_error_should_not_invalidate_routing_table(): error = Neo4jError("Oops", "Neo.TransientError.General.Error") assert not error.should_invalidate_routing_table()
def test_database_error_should_not_invalidate_routing_table(): error = Neo4jError("Oops", "Neo.DatabaseError.General.Error") assert not error.should_invalidate_routing_table()
def test_transient_error_should_retry(): error = Neo4jError("Oops", "Neo.TransientError.General.Error") assert error.should_retry()
def test_database_error_should_not_retry(): error = Neo4jError("Oops", "Neo.DatabaseError.General.Error") assert not error.should_retry()
def test_not_a_leader_error_should_retry(): error = Neo4jError("Oops", "Neo.ClientError.Cluster.NotALeader") assert error.should_retry()
def test_base_error_should_not_retry(): error = Neo4jError("Oops", "Neo.UnknownError.General.Error") assert not error.should_retry()
def test_client_error_should_not_retry(): error = Neo4jError("Oops", "Neo.ClientError.General.Error") assert not error.should_retry()
def test_not_a_leader_error_should_invalidate_routing_table(): error = Neo4jError("Oops", "Neo.ClientError.Cluster.NotALeader") assert error.should_invalidate_routing_table()
def audit(self, tx=None): if self.errors(): failure = Neo4jError.hydrate(self.errors().pop(0)) if tx is not None: tx.mark_broken() raise failure
def test_transaction_terminated_error_should_not_retry(): error = Neo4jError("Oops", "Neo.TransientError.Transaction.Terminated") assert not error.should_retry()