Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion natsapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class JsonRPCError(BaseModel):
...,
description="A message providing a short description of the error. SHOULD be limited to a concise single sentence",
)
timestamp: datetime = Field(datetime.now().isoformat(), description="Timestamp of when the error occured")
timestamp: datetime = Field(default_factory=datetime.now, description="Timestamp of when the error occured")
data: Any = Field(None, description="Additional information about the error")


Expand Down
8 changes: 7 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel, ValidationError
from pydantic.fields import Field

from natsapi.models import JsonRPCReply, JsonRPCRequest
from natsapi.models import JsonRPCError, JsonRPCReply, JsonRPCRequest


def test_change_param_type_of_model_should_change():
Expand Down Expand Up @@ -34,3 +34,9 @@ def test_result_and_error_should_not_be_provided_at_same_time_in_jsonrpcreply():
with pytest.raises(AttributeError) as e:
JsonRPCReply(error={"code": 1, "message": "foobar"}, result={"status": "OK"})
assert "An RPC reply MUST NOT have an error and a result" in str(e)


def test_jsponrpcerror_timestamp_is_generated_on_creation():
error_1 = JsonRPCError(code=1, message="", data=None)
error_2 = JsonRPCError(code=1, message="", data=None)
assert error_1.timestamp != error_2.timestamp