From 6a1d376eade9d9c164d5dfe903b9e9f9bdc0a553 Mon Sep 17 00:00:00 2001 From: Alejandro Gonzalez Barriga <46691497+Alejandro-Gonzalez-Barriga@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:56:05 -0600 Subject: [PATCH 01/12] Update __init__.py made project_name optional --- scaleapi/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index 53d232f..0ff8d3b 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -320,7 +320,7 @@ def tasks(self, **kwargs) -> Tasklist: def get_tasks( self, - project_name: str, + project_name: str = None, batch_name: str = None, task_type: TaskType = None, status: TaskStatus = None, @@ -548,7 +548,7 @@ def get_tasks_count( @staticmethod def _process_tasks_endpoint_args( - project_name: str, + project_name: str = None, batch_name: str = None, task_type: TaskType = None, status: TaskStatus = None, From 8626879ea280a8122b46eab7627c3ef7e7a4aa91 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:09:30 -0600 Subject: [PATCH 02/12] Update _version.py new release tag --- scaleapi/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scaleapi/_version.py b/scaleapi/_version.py index b899919..187da73 100644 --- a/scaleapi/_version.py +++ b/scaleapi/_version.py @@ -1,2 +1,2 @@ -__version__ = "2.15.10" +__version__ = "2.15.11" __package_name__ = "scaleapi" From 720cb09348920c2db53e600ce025648f565a7fe5 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:41:31 -0600 Subject: [PATCH 03/12] Update test_client.py tests first draft --- tests/test_client.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 672fc4f..7b19d7f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -503,3 +503,19 @@ def test_list_teammates(): # assert len(new_teammates) >= len( # old_teammates # ) # needs to sleep for teammates list to be updated + +def test_get_tasks_without_project_name(): + tasks = client.get_tasks() + assert isinstance(tasks, list) + +def test_get_tasks_with_optional_project_name(): + tasks = client.get_tasks(project_name=None) + assert isinstance(tasks, list) + +def test_process_tasks_endpoint_args_without_project_name(): + args = client._process_tasks_endpoint_args() + assert args["project_name"] is None + +def test_process_tasks_endpoint_args_with_optional_project_name(): + args = client._process_tasks_endpoint_args(project_name=None) + assert args["project_name"] is None From 29d398b86062714eec64e1a6c9770938e5f76225 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:24:08 -0600 Subject: [PATCH 04/12] updated comment --- scaleapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index 0ff8d3b..732c8d8 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -345,7 +345,7 @@ def get_tasks( `task_list = list(get_tasks(...))` Args: - project_name (str): + project_name (str, optional): Project Name batch_name (str, optional): From a5c4dd71311eee922395db98a8a48bf42188b844 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:36:34 -0600 Subject: [PATCH 05/12] either project name or batch name must be provided --- scaleapi/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index 732c8d8..5777daf 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -412,6 +412,9 @@ def get_tasks( Yields Task objects, can be iterated. """ + if not project_name and not batch_name: + raise ValueError("Either project_name or batch_name must be provided") + next_token = None has_more = True From c042f23d0c67fa91f31e4a085242809c6faf3520 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:14:45 -0600 Subject: [PATCH 06/12] updated tests --- tests/test_client.py | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 7b19d7f..76b3da7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -505,17 +505,40 @@ def test_list_teammates(): # ) # needs to sleep for teammates list to be updated def test_get_tasks_without_project_name(): - tasks = client.get_tasks() - assert isinstance(tasks, list) + with pytest.raises(ValueError): + list(client.get_tasks()) def test_get_tasks_with_optional_project_name(): - tasks = client.get_tasks(project_name=None) - assert isinstance(tasks, list) - -def test_process_tasks_endpoint_args_without_project_name(): - args = client._process_tasks_endpoint_args() - assert args["project_name"] is None + batch = create_a_batch() + tasks = [] + for _ in range(3): + tasks.append(make_a_task(batch=batch.name)) + task_ids = {task.id for task in tasks} + for task in client.get_tasks( + project_name=None, + batch_name=batch.name, + limit=1, + ): + assert task.id in task_ids def test_process_tasks_endpoint_args_with_optional_project_name(): - args = client._process_tasks_endpoint_args(project_name=None) - assert args["project_name"] is None + args = client._process_tasks_endpoint_args(project_name=None, batch_name="test_batch") + assert args["project"] is None + assert args["batch"] == "test_batch" + +def test_get_tasks_with_batch_name(): + batch = create_a_batch() + tasks = [] + for _ in range(3): + tasks.append(make_a_task(batch=batch.name)) + task_ids = {task.id for task in tasks} + for task in client.get_tasks( + batch_name=batch.name, + limit=1, + ): + assert task.id in task_ids + +def test_process_tasks_endpoint_args_with_batch_name(): + args = client._process_tasks_endpoint_args(batch_name="test_batch") + assert args["project"] is None + assert args["batch"] == "test_batch" From 6ba328c54a386e8fe47960c1967151cdec98f6ac Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:22:07 -0600 Subject: [PATCH 07/12] black formatted --- tests/test_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 76b3da7..8118a2a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -504,10 +504,12 @@ def test_list_teammates(): # old_teammates # ) # needs to sleep for teammates list to be updated + def test_get_tasks_without_project_name(): with pytest.raises(ValueError): list(client.get_tasks()) + def test_get_tasks_with_optional_project_name(): batch = create_a_batch() tasks = [] @@ -521,11 +523,15 @@ def test_get_tasks_with_optional_project_name(): ): assert task.id in task_ids + def test_process_tasks_endpoint_args_with_optional_project_name(): - args = client._process_tasks_endpoint_args(project_name=None, batch_name="test_batch") + args = client._process_tasks_endpoint_args( + project_name=None, batch_name="test_batch" + ) assert args["project"] is None assert args["batch"] == "test_batch" + def test_get_tasks_with_batch_name(): batch = create_a_batch() tasks = [] @@ -538,6 +544,7 @@ def test_get_tasks_with_batch_name(): ): assert task.id in task_ids + def test_process_tasks_endpoint_args_with_batch_name(): args = client._process_tasks_endpoint_args(batch_name="test_batch") assert args["project"] is None From a0ed92f683c3678aeefecce26d6b995054dc5d30 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:05:20 -0600 Subject: [PATCH 08/12] removed the explicit project_name=None parameter --- tests/test_client.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 8118a2a..c1491c6 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -525,9 +525,7 @@ def test_get_tasks_with_optional_project_name(): def test_process_tasks_endpoint_args_with_optional_project_name(): - args = client._process_tasks_endpoint_args( - project_name=None, batch_name="test_batch" - ) + args = client._process_tasks_endpoint_args(batch_name="test_batch") assert args["project"] is None assert args["batch"] == "test_batch" @@ -543,7 +541,7 @@ def test_get_tasks_with_batch_name(): limit=1, ): assert task.id in task_ids - + def test_process_tasks_endpoint_args_with_batch_name(): args = client._process_tasks_endpoint_args(batch_name="test_batch") From 334fe61462871dd40a1891a5fa1d1629c37884d3 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:09:33 -0600 Subject: [PATCH 09/12] removed test_process_tasks_endpoint_args_with_batch_name --- tests/test_client.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index c1491c6..68d320a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -542,8 +542,3 @@ def test_get_tasks_with_batch_name(): ): assert task.id in task_ids - -def test_process_tasks_endpoint_args_with_batch_name(): - args = client._process_tasks_endpoint_args(batch_name="test_batch") - assert args["project"] is None - assert args["batch"] == "test_batch" From b22b68180bbcf3b1e87a1743733a5144b955117b Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:17:41 -0600 Subject: [PATCH 10/12] formatted with black --- tests/test_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_client.py b/tests/test_client.py index 68d320a..e3a007d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -541,4 +541,3 @@ def test_get_tasks_with_batch_name(): limit=1, ): assert task.id in task_ids - From be3e4d803d86998d377a84c6ffab6ed2cb3509d1 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:55:02 -0600 Subject: [PATCH 11/12] updated logic --- scaleapi/__init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index 5777daf..8a7f6b7 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -413,11 +413,11 @@ def get_tasks( """ if not project_name and not batch_name: - raise ValueError("Either project_name or batch_name must be provided") - + raise ValueError("At least one of project_name or batch_name must be provided.") + next_token = None has_more = True - + tasks_args = self._process_tasks_endpoint_args( project_name, batch_name, @@ -435,13 +435,13 @@ def get_tasks( include_attachment_url, limited_response, ) - + if limit: tasks_args["limit"] = limit - + while has_more: tasks_args["next_token"] = next_token - + tasks = self.tasks(**tasks_args) for task in tasks.docs: yield task @@ -568,6 +568,9 @@ def _process_tasks_endpoint_args( limited_response: bool = None, ): """Generates args for /tasks endpoint.""" + if not project_name and not batch_name: + raise ValueError("At least one of project_name or batch_name must be provided.") + tasks_args = { "start_time": created_after, "end_time": created_before, @@ -581,7 +584,7 @@ def _process_tasks_endpoint_args( "unique_id": unique_id, "include_attachment_url": include_attachment_url, } - + if status: tasks_args["status"] = status.value if limited_response: @@ -593,9 +596,9 @@ def _process_tasks_endpoint_args( value = ",".join(map(lambda x: x.value, review_status)) else: value = review_status.value - + tasks_args["customer_review_status"] = value - + return tasks_args def create_task(self, task_type: TaskType, **kwargs) -> Task: From a07e45c3639753f4f0d973ea098e447da7f43ab0 Mon Sep 17 00:00:00 2001 From: alejandro-gonzalez-scale <133895523+alejandro-gonzalez-scale@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:03:09 -0600 Subject: [PATCH 12/12] formatted with black --- scaleapi/__init__.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index 8a7f6b7..838edfb 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -413,11 +413,13 @@ def get_tasks( """ if not project_name and not batch_name: - raise ValueError("At least one of project_name or batch_name must be provided.") - + raise ValueError( + "At least one of project_name or batch_name must be provided." + ) + next_token = None has_more = True - + tasks_args = self._process_tasks_endpoint_args( project_name, batch_name, @@ -435,13 +437,13 @@ def get_tasks( include_attachment_url, limited_response, ) - + if limit: tasks_args["limit"] = limit - + while has_more: tasks_args["next_token"] = next_token - + tasks = self.tasks(**tasks_args) for task in tasks.docs: yield task @@ -569,8 +571,10 @@ def _process_tasks_endpoint_args( ): """Generates args for /tasks endpoint.""" if not project_name and not batch_name: - raise ValueError("At least one of project_name or batch_name must be provided.") - + raise ValueError( + "At least one of project_name or batch_name must be provided." + ) + tasks_args = { "start_time": created_after, "end_time": created_before, @@ -584,7 +588,7 @@ def _process_tasks_endpoint_args( "unique_id": unique_id, "include_attachment_url": include_attachment_url, } - + if status: tasks_args["status"] = status.value if limited_response: @@ -596,9 +600,9 @@ def _process_tasks_endpoint_args( value = ",".join(map(lambda x: x.value, review_status)) else: value = review_status.value - + tasks_args["customer_review_status"] = value - + return tasks_args def create_task(self, task_type: TaskType, **kwargs) -> Task: