Skip to content

Commit f6d64cb

Browse files
Make project name optional (#92)
* Update __init__.py made project_name optional * Update _version.py new release tag * Update test_client.py tests first draft * updated comment * either project name or batch name must be provided * updated tests * black formatted * removed the explicit project_name=None parameter * removed test_process_tasks_endpoint_args_with_batch_name * formatted with black * updated logic * formatted with black --------- Co-authored-by: Alejandro Gonzalez Barriga <46691497+Alejandro-Gonzalez-Barriga@users.noreply.github.com>
1 parent 5661ee8 commit f6d64cb

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

scaleapi/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def tasks(self, **kwargs) -> Tasklist:
320320

321321
def get_tasks(
322322
self,
323-
project_name: str,
323+
project_name: str = None,
324324
batch_name: str = None,
325325
task_type: TaskType = None,
326326
status: TaskStatus = None,
@@ -345,7 +345,7 @@ def get_tasks(
345345
`task_list = list(get_tasks(...))`
346346
347347
Args:
348-
project_name (str):
348+
project_name (str, optional):
349349
Project Name
350350
351351
batch_name (str, optional):
@@ -412,6 +412,11 @@ def get_tasks(
412412
Yields Task objects, can be iterated.
413413
"""
414414

415+
if not project_name and not batch_name:
416+
raise ValueError(
417+
"At least one of project_name or batch_name must be provided."
418+
)
419+
415420
next_token = None
416421
has_more = True
417422

@@ -548,7 +553,7 @@ def get_tasks_count(
548553

549554
@staticmethod
550555
def _process_tasks_endpoint_args(
551-
project_name: str,
556+
project_name: str = None,
552557
batch_name: str = None,
553558
task_type: TaskType = None,
554559
status: TaskStatus = None,
@@ -565,6 +570,11 @@ def _process_tasks_endpoint_args(
565570
limited_response: bool = None,
566571
):
567572
"""Generates args for /tasks endpoint."""
573+
if not project_name and not batch_name:
574+
raise ValueError(
575+
"At least one of project_name or batch_name must be provided."
576+
)
577+
568578
tasks_args = {
569579
"start_time": created_after,
570580
"end_time": created_before,

scaleapi/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.15.10"
1+
__version__ = "2.15.11"
22
__package_name__ = "scaleapi"

tests/test_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,41 @@ def test_list_teammates():
503503
# assert len(new_teammates) >= len(
504504
# old_teammates
505505
# ) # needs to sleep for teammates list to be updated
506+
507+
508+
def test_get_tasks_without_project_name():
509+
with pytest.raises(ValueError):
510+
list(client.get_tasks())
511+
512+
513+
def test_get_tasks_with_optional_project_name():
514+
batch = create_a_batch()
515+
tasks = []
516+
for _ in range(3):
517+
tasks.append(make_a_task(batch=batch.name))
518+
task_ids = {task.id for task in tasks}
519+
for task in client.get_tasks(
520+
project_name=None,
521+
batch_name=batch.name,
522+
limit=1,
523+
):
524+
assert task.id in task_ids
525+
526+
527+
def test_process_tasks_endpoint_args_with_optional_project_name():
528+
args = client._process_tasks_endpoint_args(batch_name="test_batch")
529+
assert args["project"] is None
530+
assert args["batch"] == "test_batch"
531+
532+
533+
def test_get_tasks_with_batch_name():
534+
batch = create_a_batch()
535+
tasks = []
536+
for _ in range(3):
537+
tasks.append(make_a_task(batch=batch.name))
538+
task_ids = {task.id for task in tasks}
539+
for task in client.get_tasks(
540+
batch_name=batch.name,
541+
limit=1,
542+
):
543+
assert task.id in task_ids

0 commit comments

Comments
 (0)