Skip to content

Commit

Permalink
style: use single quotation marks in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
luislhl committed Oct 18, 2023
1 parent 84a8eb7 commit 52d742d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
42 changes: 21 additions & 21 deletions hathor/healthcheck/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class ComponentType(str, Enum):
"""Enum used to store the component types that can be used in the HealthCheckComponentStatus class."""

DATASTORE = "datastore"
INTERNAL = "internal"
FULLNODE = "fullnode"
DATASTORE = 'datastore'
INTERNAL = 'internal'
FULLNODE = 'fullnode'


class HealthCheckStatus(str, Enum):
"""Enum used to store the component status that can be used in the HealthCheckComponentStatus class."""

PASS = "pass"
WARN = "warn"
FAIL = "fail"
PASS = 'pass'
WARN = 'warn'
FAIL = 'fail'


@dataclass
Expand All @@ -35,29 +35,29 @@ class ComponentHealthCheck:
observed_unit: Optional[str] = None

def __post_init__(self) -> None:
self.time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
self.time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

def to_json(self) -> dict[str, str]:
"""Return a dict representation of the object. All field names are converted to camel case."""
json = {
"componentType": self.component_type.value,
"status": self.status.value,
"output": self.output,
'componentType': self.component_type.value,
'status': self.status.value,
'output': self.output,
}

if self.time:
json["time"] = self.time
json['time'] = self.time

if self.component_id:
json["componentId"] = self.component_id
json['componentId'] = self.component_id

if self.observed_value:
assert (
self.observed_unit is not None
), "observed_unit must be set if observed_value is set"
), 'observed_unit must be set if observed_value is set'

json["observedValue"] = self.observed_value
json["observedUnit"] = self.observed_unit
json['observedValue'] = self.observed_value
json['observedUnit'] = self.observed_unit

return json

Expand All @@ -71,7 +71,7 @@ class ServiceHealthCheck:

@property
def status(self) -> HealthCheckStatus:
"Return the status of the health check based on the status of the components."
"""Return the status of the health check based on the status of the components."""
status = HealthCheckStatus.PASS

for component_checks in self.checks.values():
Expand All @@ -87,7 +87,7 @@ def __post_init__(self) -> None:
"""Perform some validations after the object is initialized."""
# Make sure the checks dict is not empty
if not self.checks:
raise ValueError("checks dict cannot be empty")
raise ValueError('checks dict cannot be empty')

def get_http_status_code(self) -> int:
"""Return the HTTP status code for the status."""
Expand All @@ -96,14 +96,14 @@ def get_http_status_code(self) -> int:
elif self.status in [HealthCheckStatus.WARN, HealthCheckStatus.FAIL]:
return 503
else:
raise ValueError(f"Missing treatment for status {self.status}")
raise ValueError(f'Missing treatment for status {self.status}')

def to_json(self) -> dict[str, Any]:
"""Return a dict representation of the object. All field names are converted to camel case."""
return {
"status": self.status.value,
"description": self.description,
"checks": {k: [c.to_json() for c in v] for k, v in self.checks.items()},
'status': self.status.value,
'description': self.description,
'checks': {k: [c.to_json() for c in v] for k, v in self.checks.items()},
}


Expand Down
6 changes: 3 additions & 3 deletions hathor/healthcheck/resources/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def build_sync_health_status(manager: HathorManager) -> ComponentHealthCheck:
healthy, reason = manager.is_sync_healthy()

return ComponentHealthCheck(
component_name="sync",
component_name='sync',
component_type=ComponentType.INTERNAL,
status=HealthCheckStatus.PASS if healthy else HealthCheckStatus.FAIL,
output=reason or "Healthy",
output=reason or 'Healthy',
)


Expand Down Expand Up @@ -43,7 +43,7 @@ def render_GET(self, request):
]

health_check = ServiceHealthCheck(
description=f"Hathor-core {hathor.__version__}",
description=f'Hathor-core {hathor.__version__}',
checks={c.component_name: [c] for c in components_health_checks},
)

Expand Down
10 changes: 5 additions & 5 deletions tests/resources/healthcheck/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):
def test_get_no_recent_activity(self):
"""Scenario where the node doesn't have a recent block
"""
response = yield self.web.get("/health")
response = yield self.web.get('/health')
data = response.json_value()

self.assertEqual(response.responseCode, 503)
Expand All @@ -43,7 +43,7 @@ def test_strict_status_code(self):
"""Make sure the 'strict_status_code' parameter is working.
The node should return 200 even if it's not ready.
"""
response = yield self.web.get("/health", {b'strict_status_code': b'1'})
response = yield self.web.get('/health', {b'strict_status_code': b'1'})
data = response.json_value()

self.assertEqual(response.responseCode, 200)
Expand All @@ -69,7 +69,7 @@ def test_get_no_connected_peer(self):

self.assertEqual(self.manager.has_recent_activity(), True)

response = yield self.web.get("/health")
response = yield self.web.get('/health')
data = response.json_value()

self.assertEqual(response.responseCode, 503)
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_get_peer_out_of_sync(self):

self.assertEqual(self.manager2.state, self.manager2.NodeState.READY)

response = yield self.web.get("/health")
response = yield self.web.get('/health')
data = response.json_value()

self.assertEqual(response.responseCode, 503)
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_get_ready(self):
self.conn1.run_one_step(debug=True)
self.clock.advance(0.1)

response = yield self.web.get("/health")
response = yield self.web.get('/health')
data = response.json_value()

self.assertEqual(response.responseCode, 200)
Expand Down

0 comments on commit 52d742d

Please sign in to comment.