diff --git a/constructor_io/modules/tasks.py b/constructor_io/modules/tasks.py index c980864..d1096d0 100644 --- a/constructor_io/modules/tasks.py +++ b/constructor_io/modules/tasks.py @@ -75,7 +75,7 @@ def get_all_tasks(self, parameters=None): json = response.json() if json: - if json.get('total_count'): + if json.get('total_count') is not None: return json raise ConstructorException('get_all_tasks response data is malformed') diff --git a/tests/modules/test_autocomplete.py b/tests/modules/test_autocomplete.py index 210c115..6b7dea8 100644 --- a/tests/modules/test_autocomplete.py +++ b/tests/modules/test_autocomplete.py @@ -258,7 +258,7 @@ def test_with_no_query(): def test_with_invalid_num_results(): '''Should raise exception when invalid num_results parameter is provided''' - with raises(HttpException, match=r'num_results must be an integer'): + with raises(HttpException, match=r'num_results: value is not a valid integer'): autocomplete = ConstructorIO(VALID_OPTIONS).autocomplete autocomplete.get_autocomplete_results(QUERY, { 'num_results': 'abc' }) diff --git a/tests/modules/test_tasks.py b/tests/modules/test_tasks.py index 68eea01..67a7d9f 100644 --- a/tests/modules/test_tasks.py +++ b/tests/modules/test_tasks.py @@ -93,6 +93,18 @@ def test_get_all_tasks_with_type(): assert isinstance(response.get('total_count'), int) assert len(response.get('tasks')) <= 50 and len(response.get('tasks')) >= 1 +def test_get_all_tasks_with_zero_tasks(): + '''Should return a valid response when there are zero tasks''' + + past_end_date = '2000-01-01' + tasks = ConstructorIO(VALID_OPTIONS).tasks + response = tasks.get_all_tasks({ 'end_date': past_end_date }) + + assert isinstance(response.get('status_counts'), dict) + assert isinstance(response.get('tasks'), list) + assert isinstance(response.get('total_count'), int) + assert len(response.get('tasks')) == 0 + def test_get_all_tasks_with_invalid_api_key(): '''Should raise exception when invalid api_key is provided'''