Skip to content

Commit

Permalink
refactor(robot-server): add time endpoint link to /health & refactor …
Browse files Browse the repository at this point in the history
…system/time links

Addresses #6501
  • Loading branch information
sanni-t committed Sep 10, 2020
1 parent d615d2d commit 7589ffd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 29 deletions.
6 changes: 5 additions & 1 deletion robot-server/robot_server/service/legacy/models/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Links(BaseModel):
apiSpec: str = \
Field(...,
description="The URI to this API specification")
systemTime: str = \
Field(...,
description="The URI for system time information")


class Health(BaseModel):
Expand Down Expand Up @@ -60,7 +63,8 @@ class Config:
"links": {
"apiLog": "/logs/api.log",
"serialLog": "/logs/serial.log",
"apiSpec": "/openapi.json"
"apiSpec": "/openapi.json",
"systemTime": "/system/time"
}
}
}
3 changes: 2 additions & 1 deletion robot-server/robot_server/service/legacy/routers/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ async def get_health(
links=Links(
apiLog='/logs/api.log',
serialLog='/logs/serial.log',
apiSpec="/openapi.json"
apiSpec="/openapi.json",
systemTime="/system/time"
))
9 changes: 8 additions & 1 deletion robot-server/robot_server/service/system/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from pydantic import BaseModel
from pydantic import BaseModel, Field

from robot_server.service.json_api import ResponseModel, ResponseDataModel, \
RequestDataModel, RequestModel
Expand All @@ -9,6 +9,13 @@ class SystemTimeAttributes(BaseModel):
systemTime: datetime


class SystemTimeLinks(BaseModel):
"""A set of useful links"""
systemTime: str = \
Field(...,
description="The URI for system time information")


SystemTimeResponseDataModel = ResponseDataModel[SystemTimeAttributes]

SystemTimeResponse = ResponseModel[SystemTimeResponseDataModel, dict]
Expand Down
13 changes: 4 additions & 9 deletions robot-server/robot_server/service/system/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from datetime import datetime
from fastapi import APIRouter
from robot_server.system import time
from typing import Dict
from robot_server.service.system import models as time_models
from robot_server.service.json_api import ResourceLink

router = APIRouter()
log = logging.getLogger(__name__)
Expand All @@ -28,14 +26,11 @@ def _create_response(dt: datetime) \
)


def _get_valid_time_links(api_router: APIRouter) -> Dict[str, ResourceLink]:
def _get_valid_time_links(api_router: APIRouter) \
-> time_models.SystemTimeLinks:
""" Get valid links for time resource"""
return {
"GET": ResourceLink(href=api_router.url_path_for(
get_time.__name__)),
"PUT": ResourceLink(href=api_router.url_path_for(
set_time.__name__))
}
return time_models.SystemTimeLinks(systemTime=api_router.url_path_for(
get_time.__name__))


@router.get("/system/time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ stages:
id: 'time'
type: 'SystemTimeAttributes'
links:
GET:
href: "/system/time"
meta: null
PUT:
href: "/system/time"
meta: null
systemTime: '/system/time'
meta: null

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ stages:
serialLog: /logs/serial.log
# Specific link can change.
apiSpec: !re_match "/openapi.*"
systemTime: /system/time
3 changes: 2 additions & 1 deletion robot-server/tests/service/legacy/routers/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_health(api_client, hardware):
"links": {
"apiLog": "/logs/api.log",
"serialLog": "/logs/serial.log",
"apiSpec": "/openapi.json"
"apiSpec": "/openapi.json",
"systemTime": "/system/time"
}
}
resp = api_client.get('/health')
Expand Down
11 changes: 1 addition & 10 deletions robot-server/tests/service/system/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ def mock_set_system_time(mock_system_time):

@pytest.fixture
def response_links():
return {
"GET": {
"href": "/system/time",
"meta": None
},
"PUT": {
"href": "/system/time",
"meta": None
}
}
return {'systemTime': '/system/time'}


def test_raise_system_synchronized_error(api_client,
Expand Down

0 comments on commit 7589ffd

Please sign in to comment.