From 00d392a4777425c413720f952314ced56450143e Mon Sep 17 00:00:00 2001 From: merlos <404446+merlos@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:34:13 +0300 Subject: [PATCH] fix get report list --- explorations/primero.ipynb | 185 ++++++++++++------ primero-api/.coverage | Bin 0 -> 53248 bytes .../integration_tests/test_primero_api.py | 2 + primero-api/primero_api/primero_api.py | 51 ++--- primero-api/primero_api/version.py | 2 +- primero-api/setup.py | 2 +- 6 files changed, 153 insertions(+), 89 deletions(-) create mode 100644 primero-api/.coverage diff --git a/explorations/primero.ipynb b/explorations/primero.ipynb index ac13a26..a92cec5 100644 --- a/explorations/primero.ipynb +++ b/explorations/primero.ipynb @@ -21,59 +21,96 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Obtaining file:///Users/jmerlostevar/src/magasin/primero/primero_api\n", - " Installing build dependencies ... \u001b[?25ldone\n", - "\u001b[?25h Checking if build backend supports build_editable ... \u001b[?25ldone\n", - "\u001b[?25h Getting requirements to build editable ... \u001b[?25lerror\n", - " \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n", - " \n", - " \u001b[31m×\u001b[0m \u001b[32mGetting requirements to build editable\u001b[0m did not run successfully.\n", - " \u001b[31m│\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n", - " \u001b[31m╰─>\u001b[0m \u001b[31m[27 lines of output]\u001b[0m\n", - " \u001b[31m \u001b[0m Traceback (most recent call last):\n", - " \u001b[31m \u001b[0m File \"/Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py\", line 353, in \n", - " \u001b[31m \u001b[0m main()\n", - " \u001b[31m \u001b[0m File \"/Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py\", line 335, in main\n", - " \u001b[31m \u001b[0m json_out['return_val'] = hook(**hook_input['kwargs'])\n", - " \u001b[31m \u001b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " \u001b[31m \u001b[0m File \"/Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py\", line 132, in get_requires_for_build_editable\n", - " \u001b[31m \u001b[0m return hook(config_settings)\n", - " \u001b[31m \u001b[0m ^^^^^^^^^^^^^^^^^^^^^\n", - " \u001b[31m \u001b[0m File \"/private/var/folders/sx/mgw7pc4s3_933zkvp879hzd00000gn/T/pip-build-env-7uh3upr0/overlay/lib/python3.12/site-packages/setuptools/build_meta.py\", line 477, in get_requires_for_build_editable\n", - " \u001b[31m \u001b[0m return self.get_requires_for_build_wheel(config_settings)\n", - " \u001b[31m \u001b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " \u001b[31m \u001b[0m File \"/private/var/folders/sx/mgw7pc4s3_933zkvp879hzd00000gn/T/pip-build-env-7uh3upr0/overlay/lib/python3.12/site-packages/setuptools/build_meta.py\", line 332, in get_requires_for_build_wheel\n", - " \u001b[31m \u001b[0m return self._get_build_requires(config_settings, requirements=[])\n", - " \u001b[31m \u001b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " \u001b[31m \u001b[0m File \"/private/var/folders/sx/mgw7pc4s3_933zkvp879hzd00000gn/T/pip-build-env-7uh3upr0/overlay/lib/python3.12/site-packages/setuptools/build_meta.py\", line 302, in _get_build_requires\n", - " \u001b[31m \u001b[0m self.run_setup()\n", - " \u001b[31m \u001b[0m File \"/private/var/folders/sx/mgw7pc4s3_933zkvp879hzd00000gn/T/pip-build-env-7uh3upr0/overlay/lib/python3.12/site-packages/setuptools/build_meta.py\", line 516, in run_setup\n", - " \u001b[31m \u001b[0m super().run_setup(setup_script=setup_script)\n", - " \u001b[31m \u001b[0m File \"/private/var/folders/sx/mgw7pc4s3_933zkvp879hzd00000gn/T/pip-build-env-7uh3upr0/overlay/lib/python3.12/site-packages/setuptools/build_meta.py\", line 318, in run_setup\n", - " \u001b[31m \u001b[0m exec(code, locals())\n", - " \u001b[31m \u001b[0m File \"\", line 3, in \n", - " \u001b[31m \u001b[0m File \"/Users/jmerlostevar/src/magasin/primero/primero_api/primero_api/__init__.py\", line 3, in \n", - " \u001b[31m \u001b[0m from .primero_api import PrimeroAPI\n", - " \u001b[31m \u001b[0m File \"/Users/jmerlostevar/src/magasin/primero/primero_api/primero_api/primero_api.py\", line 1, in \n", - " \u001b[31m \u001b[0m import requests\n", - " \u001b[31m \u001b[0m ModuleNotFoundError: No module named 'requests'\n", - " \u001b[31m \u001b[0m \u001b[31m[end of output]\u001b[0m\n", - " \n", - " \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n", - "\u001b[?25h\u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n", - "\n", - "\u001b[31m×\u001b[0m \u001b[32mGetting requirements to build editable\u001b[0m did not run successfully.\n", - "\u001b[31m│\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n", - "\u001b[31m╰─>\u001b[0m See above for output.\n", - "\n", - "\u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n" + "Found existing installation: primero-api 0.2.0\n", + "Uninstalling primero-api-0.2.0:\n", + " Would remove:\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/integration_tests/*\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/primero_api-0.2.0.dist-info/*\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/primero_api/*\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/*\n", + " Would not remove (might be manually added):\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/aiohttp.jpg\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/aiohttp.png\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/Dockerfile.aiohttp\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/Dockerfile.autobahn\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/client/client.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/client/fuzzingserver.json\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/server/fuzzingclient.json\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/server/server.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/autobahn/test_autobahn.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/conftest.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/data.unknown_mime_type\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/data.zero_bytes\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/hello.txt.gz\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/sample.txt\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_base_protocol.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_circular_imports.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_classbasedview.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_connection.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_exceptions.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_fingerprint.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_proto.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_request.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_response.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_session.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_ws.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_client_ws_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_connector.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_cookiejar.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_flowcontrol_streams.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_formdata.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_helpers.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_http_exceptions.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_http_parser.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_http_writer.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_imports.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_locks.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_loop.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_multipart.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_multipart_helpers.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_payload.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_proxy.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_proxy_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_pytest_plugin.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_resolver.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_route_def.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_run_app.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_streams.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_tcp_helpers.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_test_utils.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_tracing.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_urldispatch.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_app.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_cli.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_exceptions.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_log.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_middleware.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_request.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_request_handler.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_response.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_runner.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_sendfile.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_sendfile_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_server.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_urldispatcher.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_websocket.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_web_websocket_functional.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_websocket_handshake.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_websocket_parser.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_websocket_writer.py\n", + " /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages/tests/test_worker.py\n", + "Proceed (Y/n)? ^C\n", + "\u001b[31mERROR: Operation cancelled by user\u001b[0m\u001b[31m\n", + "\u001b[0m" ] } ], @@ -83,15 +120,23 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[33mWARNING: Package(s) not found: primero_api\u001b[0m\u001b[33m\n", - "\u001b[0m" + "Name: primero-api\n", + "Version: 0.2.0\n", + "Summary: A simple client for consuming data from Primero API\n", + "Home-page: https://github.com/unicef/magasin-primero-paquet\n", + "Author: merlos\n", + "Author-email: merlos@users.github.com\n", + "License: \n", + "Location: /Users/jmerlostevar/Library/Caches/pypoetry/virtualenvs/dxint-hpo8hiaR-py3.12/lib/python3.12/site-packages\n", + "Requires: pandas, python-slugify, requests, requests-cache, requests-ratelimiter\n", + "Required-by: \n" ] } ], @@ -108,7 +153,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Primero API library version 0.1.2\n", + "Primero API library version 0.2.0\n", + "{'name': 'administrator', 'created_at': '2024-10-11T09:40:36.969Z', 'updated_at': '2024-10-11T09:40:36.969Z', 'system_version': '2.11.0-rc3'}\n", "Primero Server version 2.11.0-rc3\n" ] } @@ -146,19 +192,32 @@ "name": "stdout", "output_type": "stream", "text": [ - "1 Registration CP\n", - "2 Caseload Summary CP\n", - "3 Case status by case worker CP\n", - "4 Cases by Agency CP\n", - "5 Cases by Nationality\n", - "6 Cases by Age and Sex\n", - "7 Cases by Protection Concern\n", - "8 Current Care Arrangements\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "error calling primero server: %s: %s, url: %s 404 {\"errors\":[{\"status\":404,\"resource\":\"/api/v2/reports/%3Cbuilt-in%20function%20id%3E\",\"detail\":\"Couldn't find Report with 'id'=\\u003cbuilt-in function id\\u003e\",\"message\":\"Not Found\"}]} http://localhost/api/v2/reports/\n", + "1 ** This report has no data **\n", + "2 ** This report has no data **\n", + "3 ** This report has no data **\n", + "4 ** This report has no data **\n", + "5 ** This report has no data **\n", + "6 ** This report has no data **\n", + "7 ** This report has no data **\n", + "8 ** This report has no data **\n", "9 ** This report has no data **\n", - "10 Follow up by month by Agency\n", - "11 Follow up by week by Agency\n", - "12 Cases per Month\n", - "13 Cases with case plans\n" + "10 ** This report has no data **\n", + "11 ** This report has no data **\n", + "12 ** This report has no data **\n", + "13 ** This report has no data **\n" ] } ], diff --git a/primero-api/.coverage b/primero-api/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..088d835acb8bf8312f18127cbc505e4d3cd8ffde GIT binary patch literal 53248 zcmeI)+iw(A90%~Z?JV2dfpA$#LwX2kY3PMUiBTT}wTVOoxfu+GWp?+p9o(JS&de4t zQCTn{G4aVqjn6)*&n6nfA7J8xi4P_s4@e9~O_XRb>hCv~ZWmfYD29}NC*9e(o!^}E znRD6M?e3uid)-LMNk6DNk$hBJt?9b9OG-`C3iRluM>geY!OB+XS)aGO*kVB&eSM}^ zysY)u?`ql+JOlI5P$##R<=OvKu^B7aif0jjmRn2 zR1`QB6(sZCXAe&7K0F~0?|x?QgiN-{ZC#S4krBCD2L378P=TCuYf8Fa)vY*@>rKgM zT4hH!LsjL0j<(TI#|Mta>3ON-Rw-4arYJ-saO+NRM!u%b495qgXN%P7DA_b zb6*Y|uQIK|Vd>13u;NobPe(~<1HV2N`LgDEaWTEnja=W8>a?mfBUN3nfWwTIO@ueU zG!*Lu7wANiGCkKkop#~{Ql^Kei6<#@o}aO{6Y{AkahzwbSuYd$$!5L57l%?LCyxBZ zQZAM@^3%fJ@wHjtTDHsEaXB+`zM@I0rsvKy)!fA&mhF_oaWOo9SaKn#20Ywt7oS+G zYg8-M>2Rh-ueVB0GxFp05?%b#IL&(AUb8A+92n3q%)}Lic}itB3g;FI9hGKo^CDG; z_b*;=xRrEP5^hDcn)D~*Cc~*^a&f3O&u=qh8HN*ZLz8}bAm#MF);7*81C3@lc4=Bhwxd~UI; zwb9NO`}_5Cg}54}S1WzWcT}P5N-ofiX1nUj37bLIk=(A6%u=*_$*hf}d#E@gdAqo~ zf3f1E$Cbv@g;lM*l`pPeueXvG!Tl0Havg=>E$t?7(?D?N*>5<}w7fO%yqPjSn6ryd ztzRtToQ2Xj&+YTaj5x~|HpcpO>h$?xc4V2iw6pwzIx{ls)TlRUIBq~qmipji1dx1S z)uDr(vfqs2`pc_v_2jXqo!=xtdp)zKqlV(csd>NThoMWuDi2%Xli5}|IPHYo3x$KS z?E5w4c*)p6DfWbPPB)Zs9&R0#o^Hno&v1;X*}*tZ+2F$6{9$TzS^J`edfoA=>3GG% za1xdJer}w6o}?3@gmRD?Wk^l*rkGjKbT9W^!X=~8 zb55ipx2_}~5@#l^Sf`v&RsuykX)GNYG;dc8_-d8LdCqsqtN5i{Ye3Hzw{O>5&9pHl z{Y)vOLA~x|*-lrDj!JUV&USs-PaQ73+L>QZ*lr#NuO?^U&Mmoud%uvVZZ|A#}69nEn&M{p1liTbea8y^i2T%{NL_dtBFsYxCHVkiLFDcCxO5njc1L)(OVKpfXl>rkv3A#`srq zRN!aNBTmE3mP@>x-e1yJ@{i^y-p-}Q3sl1oqEaL9=?8W~KL{!Eixx#5xHpkGoOv(8 z)%+>?6(I_D(4cTbOU+&C%%&7`zfLi?EH!4SJXr=YQHzuuVS9yt31v=bG`=H%6SXFV|^r9-laCT+4m&=Mnv%>&8c8+IQV2 z^h;}wYL^P5!6tBD)pck#2hBEF{;Ob~zo1Rwwb2tWV= z5P$##AOHafEDHgC4?(x%w-WSRE?%>&_{lWmC&RGl4S@Lbe{J=$C=xOW0SG_<0uX=z z1Rwwb2tWV=5P-m43h?Luxc|RPJS2kv1Rwwb2tWV=5P$##AOHafEE9p``~R2u|NpOx z-^4ZXqqw|GvW{#*00Izz00bZa0SG_<0uX=z1RyXcVA}LE|7MP77SBwc89d|P|Njpa CA;MJv literal 0 HcmV?d00001 diff --git a/primero-api/integration_tests/test_primero_api.py b/primero-api/integration_tests/test_primero_api.py index 87031ef..175d01a 100644 --- a/primero-api/integration_tests/test_primero_api.py +++ b/primero-api/integration_tests/test_primero_api.py @@ -27,6 +27,7 @@ def test_get_cases_raw(primero_api): cases = primero_api.get_cases_raw() assert cases is not None assert type(cases) is list + assert cases[0] is not None def test_get_cases(primero_api): cases = primero_api.get_cases() @@ -49,6 +50,7 @@ def test_get_reports(primero_api): reports = primero_api.get_reports() assert reports is not None + def test_get_version(primero_api): version = primero_api.get_server_version() # check is a string diff --git a/primero-api/primero_api/primero_api.py b/primero-api/primero_api/primero_api.py index cf1bc53..67a4189 100644 --- a/primero-api/primero_api/primero_api.py +++ b/primero-api/primero_api/primero_api.py @@ -155,8 +155,6 @@ def _call_api_get(self, url): response = self.session.get( url, headers=self.headers, auth=HTTPBasicAuth(self.user, self.password)) if response.status_code != 200: - print('error calling primero server: %s: %s, url: %s', - response.status_code, response.text, url) logger.error('error calling primero server: %s: %s, url: %s', response.status_code, response.text, url) return None @@ -205,7 +203,6 @@ def _call_paginated_api(self, url: str): json_data = response.json() # extend the existing list to include new data data.extend(json_data['data']) - # print(json_data) # check if we are at the last page logger.debug('page=%s metadata=%s', page, json_data["metadata"]) if self._is_last_page(json_data['metadata']): @@ -305,48 +302,53 @@ def get_report_raw(self, report_id: int): returns a dictionary with the content of the report or None if there is an error. """ - url = self.api_url + 'reports/' + str(id) + url = self.api_url + 'reports/' + str(report_id) logger.debug('report_id: %s, get_report url=%s', report_id, url) return self._call_api_get(url) def get_report_list(self): """ - **Returns a dictionary** with the report id as key and the report as value - The content of the report is a dictionary - If while fetching the report there is an error (f.i no data), the content of that id is None. - For example if there is an error in report 10, then - ``` - reports = primero.get_report_list() - reports[10]== None # True - ``` + Returns a list of reports. + The content of each report is a dictionary with some metadata. """ url = self.api_url + 'reports' return self._call_paginated_api(url) def get_reports_raw(self): """" - Gets the list of reports for the given page and page_size. - Returns a dictionary with the id as key and the report cibtebt in Dict format as value + Gets the list of reports for the given. + + Returns a dictionary with the id as key and the report in Dict format as value The content of the report is a dictionary + + If while fetching the report there is an error (f.i no data), the content of that id is None. + For example if there is an error in report 10, then + ``` + reports = primero.get_report_raw() + reports[10]== None # True + ``` + """ reports = {} - report_list_dict = self.get_report_list() - for id, report in report_list_dict.items(): - report = self.get_report(id) + report_list= self.get_report_list() + for report in report_list: + report_id = report['id'] + logger.debug(f'getting report {report_id}') + report = self.get_report_raw(report_id) # report is None if there is an error, we remove it from the list of reports. if report: - reports[id] = report['data'] + reports[report_id] = report return reports - def get_report(self, id: int, lang='en'): + def get_report(self, report_id: int, lang='en'): """" Gets the report with the given id returns a object of the Report class or None if there is an error. """ - logger.debug(f'get_report id={id}, lang={lang}') - report_json_dict = self.get_report_raw(id) + logger.debug(f'get_report id={report_id}, lang={lang}') + report_json_dict = self.get_report_raw(report_id) if report_json_dict is None: - logger.error(f'Did not get report {id}') + logger.error(f'Did not get report {report_id}') return None return Report(report_json_dict, lang) @@ -360,7 +362,8 @@ def get_reports(self, lang='en'): for report in report_list: id = report['id'] report = self.get_report(id, lang) - reports[id] = report + if report: + reports[id] = report return reports def get_lookups(self): @@ -371,5 +374,5 @@ def get_lookups(self): def get_server_version(self): url = self.api_url + 'contact_information' contact_information = self._call_api_get(url) - print (contact_information) + logger.debug('contact_information_full_response: %s', contact_information) return contact_information['system_version'] diff --git a/primero-api/primero_api/version.py b/primero-api/primero_api/version.py index aa70592..b72bd09 100644 --- a/primero-api/primero_api/version.py +++ b/primero-api/primero_api/version.py @@ -1 +1 @@ -VERSION='0.2.0' \ No newline at end of file +VERSION='0.2.1' \ No newline at end of file diff --git a/primero-api/setup.py b/primero-api/setup.py index 61c4c00..68587b4 100644 --- a/primero-api/setup.py +++ b/primero-api/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.2.0' +VERSION = '0.2.1' setup( name='primero-api',