Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename LogService methods and api endpoint url. Fixes #74 Closes #73 #75

Merged
merged 3 commits into from
Feb 8, 2024
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
12 changes: 6 additions & 6 deletions pocketbase/services/log_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class HourlyStats:


class LogService(BaseService):
def get_request_list(
def get_list(
self, page: int = 1, per_page: int = 30, query_params: dict = {}
) -> ListResult:
"""Returns paginated logged requests list."""
query_params.update({"page": page, "perPage": per_page})
response_data = self.client.send(
"/api/logs/requests",
"/api/logs/",
{"method": "GET", "params": query_params},
)
items: list[LogRequest] = []
Expand All @@ -40,21 +40,21 @@ def get_request_list(
items,
)

def get_request(self, id: str, query_params: dict = {}) -> LogRequest:
def get(self, id: str, query_params: dict = {}) -> LogRequest:
"""Returns a single logged request by its id."""
return LogRequest(
self.client.send(
"/api/logs/requests/" + quote(id),
"/api/logs/" + quote(id),
{"method": "GET", "params": query_params},
)
)

def get_requests_stats(self, query_params: dict = {}) -> list[HourlyStats]:
def get_stats(self, query_params: dict = {}) -> list[HourlyStats]:
"""Returns request logs statistics."""
return [
HourlyStats(total=stat["total"], date=to_datetime(stat["date"]))
for stat in self.client.send(
"/api/logs/requests/stats",
"/api/logs/stats",
{"method": "GET", "params": query_params},
)
]
14 changes: 7 additions & 7 deletions tests/integration/test_log_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@


class TestLogService:
def test_get_request_list(self, client: PocketBase, state):
state.list = client.logs.get_request_list()
def test_log_get_list(self, client: PocketBase, state):
state.list = client.logs.get_list()

def test_get_request(self, client: PocketBase, state):
def test_log_get(self, client: PocketBase, state):
if len(state.list.items) > 0:
v = state.list.items[0]
r = client.logs.get_request(v.id)
r = client.logs.get(v.id)
assert v.id == r.id
assert v.created == r.created

def test_log_request_stats(self, client: PocketBase, state):
state.stats = client.logs.get_requests_stats()
assert len(state.stats) > 0
def test_log_stats(self, client: PocketBase, state):
state.stats = client.logs.get_stats()
assert len(state.stats) >= 0
for v in state.stats:
assert v.total > 0
15 changes: 15 additions & 0 deletions tests/integration/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ def test_get_record_expand(self, client: PocketBase, state):
break
rel = rel.expand["rel"]

def test_get_record_backrelation_expand(self, client: PocketBase, state):
backrel_field = "%s(rel)" % state.coll.id
rel = client.collection(state.coll.id).get_one(
state.chained_records[0],
{"expand": ".".join([backrel_field] * 6)},
)
for i, r in enumerate(state.chained_records):
if isinstance(rel, list):
assert len(rel) == 1
rel = rel[0]
assert rel.id == r
if i > 5:
break
rel = rel.expand[backrel_field]

def test_get_record_expand_multirel(self, client: PocketBase, state):
rel = client.collection(state.coll.id).get_one(
state.chained_multi_records[-1],
Expand Down