-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from aldbr/main_FEAT_pagination
feat(jobs): pagination
- Loading branch information
Showing
23 changed files
with
722 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,122 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
from pytest import raises | ||
|
||
from diracx import cli | ||
from diracx.core.models import ScalarSearchSpec | ||
from diracx.core.preferences import get_diracx_preferences | ||
|
||
TEST_JDL = """ | ||
Arguments = "jobDescription.xml -o LogLevel=INFO"; | ||
Executable = "dirac-jobexec"; | ||
JobGroup = jobGroup; | ||
JobName = jobName; | ||
JobType = User; | ||
LogLevel = INFO; | ||
OutputSandbox = | ||
{ | ||
Script1_CodeOutput.log, | ||
std.err, | ||
std.out | ||
}; | ||
Priority = 1; | ||
Site = ANY; | ||
StdError = std.err; | ||
StdOutput = std.out; | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
async def jdl_file(): | ||
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as temp_file: | ||
temp_file.write(TEST_JDL) | ||
temp_file.flush() | ||
yield temp_file.name | ||
|
||
|
||
async def test_submit(with_cli_login, jdl_file, capfd): | ||
"""Test submitting a job using a JDL file.""" | ||
|
||
with open(jdl_file, "r") as temp_file: | ||
await cli.jobs.submit([temp_file]) | ||
|
||
async def test_search(with_cli_login, capfd): | ||
await cli.jobs.search() | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
assert "Inserted 1 jobs with ids" in cap.out | ||
|
||
|
||
async def test_search(with_cli_login, jdl_file, capfd): | ||
"""Test searching for jobs.""" | ||
|
||
# Submit 20 jobs | ||
with open(jdl_file, "r") as temp_file: | ||
await cli.jobs.submit([temp_file] * 20) | ||
|
||
cap = capfd.readouterr() | ||
|
||
# By default the output should be in JSON format as capfd is not a TTY | ||
json.loads(cap.out) | ||
await cli.jobs.search() | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
jobs = json.loads(cap.out) | ||
|
||
# There should be 10 jobs by default | ||
assert len(jobs) == 10 | ||
assert "JobID" in jobs[0] | ||
assert "JobGroup" in jobs[0] | ||
|
||
# Change per-page to a very large number to get all the jobs at once: the caption should change | ||
await cli.jobs.search(per_page=9999) | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
jobs = json.loads(cap.out) | ||
|
||
# There should be 20 jobs at least now | ||
assert len(jobs) >= 20 | ||
assert "JobID" in cap.out | ||
assert "JobGroup" in cap.out | ||
|
||
# Search for a job that doesn't exist | ||
condition = ScalarSearchSpec(parameter="Status", operator="eq", value="nonexistent") | ||
await cli.jobs.search(condition=[condition]) | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
assert "[]" == cap.out.strip() | ||
|
||
# Switch to RICH output | ||
get_diracx_preferences.cache_clear() | ||
os.environ["DIRACX_OUTPUT_FORMAT"] = "RICH" | ||
|
||
await cli.jobs.search() | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
|
||
with raises(json.JSONDecodeError): | ||
json.loads(cap.out) | ||
|
||
assert "JobID" in cap.out | ||
assert "JobGroup" in cap.out | ||
assert "Showing 0-9 of " in cap.out | ||
|
||
# Change per-page to a very large number to get all the jobs at once: the caption should change | ||
await cli.jobs.search(per_page=9999) | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
|
||
with raises(json.JSONDecodeError): | ||
json.loads(cap.out) | ||
|
||
assert "JobID" in cap.out | ||
assert "JobGroup" in cap.out | ||
assert "Showing all jobs" in cap.out | ||
|
||
# Search for a job that doesn't exist | ||
await cli.jobs.search(condition=[condition]) | ||
cap = capfd.readouterr() | ||
assert cap.err == "" | ||
assert "No jobs found" in cap.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# pylint: disable=too-many-lines,too-many-statements | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].9) | ||
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.10.2, generator: @autorest/[email protected].17) | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
from io import IOBase | ||
|
@@ -2072,7 +2072,7 @@ async def search( | |
self, | ||
body: Optional[_models.JobSearchParams] = None, | ||
*, | ||
page: int = 0, | ||
page: int = 1, | ||
per_page: int = 100, | ||
content_type: str = "application/json", | ||
**kwargs: Any, | ||
|
@@ -2085,7 +2085,7 @@ async def search( | |
:param body: Default value is None. | ||
:type body: ~client.models.JobSearchParams | ||
:keyword page: Default value is 0. | ||
:keyword page: Default value is 1. | ||
:paramtype page: int | ||
:keyword per_page: Default value is 100. | ||
:paramtype per_page: int | ||
|
@@ -2102,7 +2102,7 @@ async def search( | |
self, | ||
body: Optional[IO[bytes]] = None, | ||
*, | ||
page: int = 0, | ||
page: int = 1, | ||
per_page: int = 100, | ||
content_type: str = "application/json", | ||
**kwargs: Any, | ||
|
@@ -2115,7 +2115,7 @@ async def search( | |
:param body: Default value is None. | ||
:type body: IO[bytes] | ||
:keyword page: Default value is 0. | ||
:keyword page: Default value is 1. | ||
:paramtype page: int | ||
:keyword per_page: Default value is 100. | ||
:paramtype per_page: int | ||
|
@@ -2132,7 +2132,7 @@ async def search( | |
self, | ||
body: Optional[Union[_models.JobSearchParams, IO[bytes]]] = None, | ||
*, | ||
page: int = 0, | ||
page: int = 1, | ||
per_page: int = 100, | ||
**kwargs: Any, | ||
) -> List[JSON]: | ||
|
@@ -2144,7 +2144,7 @@ async def search( | |
:param body: Is either a JobSearchParams type or a IO[bytes] type. Default value is None. | ||
:type body: ~client.models.JobSearchParams or IO[bytes] | ||
:keyword page: Default value is 0. | ||
:keyword page: Default value is 1. | ||
:paramtype page: int | ||
:keyword per_page: Default value is 100. | ||
:paramtype per_page: int | ||
|
@@ -2199,18 +2199,27 @@ async def search( | |
|
||
response = pipeline_response.http_response | ||
|
||
if response.status_code not in [200]: | ||
if response.status_code not in [200, 206]: | ||
if _stream: | ||
await response.read() # Load the body in memory and close the socket | ||
map_error( | ||
status_code=response.status_code, response=response, error_map=error_map | ||
) | ||
raise HttpResponseError(response=response) | ||
|
||
deserialized = self._deserialize("[object]", pipeline_response) | ||
response_headers = {} | ||
if response.status_code == 200: | ||
deserialized = self._deserialize("[object]", pipeline_response) | ||
|
||
if response.status_code == 206: | ||
response_headers["Content-Range"] = self._deserialize( | ||
"str", response.headers.get("Content-Range") | ||
) | ||
|
||
deserialized = self._deserialize("[object]", pipeline_response) | ||
|
||
if cls: | ||
return cls(pipeline_response, deserialized, {}) # type: ignore | ||
return cls(pipeline_response, deserialized, response_headers) # type: ignore | ||
|
||
return deserialized # type: ignore | ||
|
||
|
Oops, something went wrong.