From 84721f13f726d9229dadff2612cd09fc7efc4bf0 Mon Sep 17 00:00:00 2001 From: John Champion Date: Thu, 22 Feb 2024 14:50:49 -0500 Subject: [PATCH 01/14] expand the gravity forms package --- sat/gravity_forms.py | 160 +++++++++++++++++++++++++++++++++++- tests/test_gravity_forms.py | 68 +++++++++++++-- 2 files changed, 219 insertions(+), 9 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index 33404c0..a466ca7 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -7,6 +7,7 @@ """ import os +from typing import Optional import oauthlib from requests.exceptions import RequestException @@ -17,6 +18,104 @@ logger = SATLogger(name=__name__) +class Form: + """ + A form object from GravityForms. + """ + + id: int + title: str + description: str + date_created: str + is_active: bool + is_trash: bool + version: str + details: dict = {} + + def __init__(self, **kwargs): + self.id = kwargs.get("id", "") + self.title = kwargs.get("title", "") + self.description = kwargs.get("description", "") + self.date_created = kwargs.get("date_created", "") + self.date_updated = kwargs.get("date_updated", "") + self.is_active = kwargs.get("is_active", False) + self.is_trash = kwargs.get("is_trash", False) + self.version = kwargs.get("version", "") + + # Storing additional kwargs in a dictionary attribute called details + self.details = { + key: value + for key, value in kwargs.items() + if key + not in [ + "id", + "title", + "description", + "date_created", + "is_active", + "is_trash", + "version", + ] + } + + +class Entry: + """ + An entry object from GravityForms. + """ + + id: str + form_id: str + created_by: str + date_created: str + date_updated: str + is_starred: bool + is_read: bool + ip: str + source_url: str + post_id: int + user_agent: str + status: str + is_fulfilled: bool + details: dict = {} + + def __init__(self, **kwargs): + self.id = kwargs.get("id", "") + self.form_id = kwargs.get("form_id", "") + self.created_by = kwargs.get("created_by", "") + self.date_created = kwargs.get("date_created", "") + self.date_updated = kwargs.get("date_updated", "") + self.is_starred = kwargs.get("is_starred", False) + self.is_read = kwargs.get("is_read", False) + self.ip = kwargs.get("ip", "") + self.source_url = kwargs.get("source_url", "") + self.post_id = kwargs.get("post_id", 0) + self.user_agent = kwargs.get("user_agent", "") + self.status = kwargs.get("status", "") + self.is_fulfilled = kwargs.get("is_fulfilled", False) + + # Storing additional kwargs in a dictionary attribute called details + self.details = { + key: value + for key, value in kwargs.items() + if key + not in [ + "id", + "form_id", + "created_by", + "date_created", + "is_starred", + "is_read", + "ip", + "source_url", + "post_id", + "user_agent", + "status", + "is_fulfilled", + ] + } + + class GravityForms: """ A helper class for connecting to and calling the Gravity Forms API. @@ -24,6 +123,7 @@ class GravityForms: session = None base_url = None + page_size = 50 def __init__(self, **settings) -> None: """ @@ -39,6 +139,7 @@ def __init__(self, **settings) -> None: "consumer_secret", os.getenv("GRAVITY_FORMS_CONSUMER_SECRET") ) self.base_url = settings.get("base_url", os.getenv("GRAVITY_FORMS_BASE_URL")) + self.page_size = settings.get("page_size", self.page_size) if not consumer_key: raise ValueError( @@ -61,16 +162,67 @@ def __init__(self, **settings) -> None: signature_type=oauthlib.oauth1.SIGNATURE_TYPE_QUERY, ) - def get(self, endpoint: str): + def get(self, endpoint: str, params: Optional[dict] = None): """ Submits a GET request to a specified endpoint. Parameters: - endpoint: The string representing the endpoint URL. (ex. "/forms") """ + + param_string: str = "?" + if params is not None: + for param in params: + param_string += f"{param}={params[param]}&" + try: - response = self.session.get(self.base_url + endpoint) + response = self.session.get(self.base_url + endpoint + param_string) return response.json() except RequestException as e: - logger.error(str(e)) - return {} + raise e + + def get_forms(self, page: int = 1, page_size: int = 20): + """ + Gets and returns a list of forms. + """ + response = self.get( + "/forms", params={"paging[current_page]": page, "paging[page_size]": page_size} + ) + forms = [] + for form_id in response: + forms.append(Form(**response[form_id])) + return forms + + def get_form(self, form_id: int): + """ + Gets and returns a form. + + Parameters: + - form_id: The ID of the form. + """ + response = self.get(f"/forms/{form_id}") + entry = Form(**response) + return entry + + def get_entries(self, page: int = 1, page_size: int = 20): + """ + Gets and returns a list of entries. + """ + response = self.get( + "/entries", params={"paging[current_page]": page, "paging[page_size]": page_size} + ) + entries = [] + for entry in response["entries"]: + entries.append(Entry(**entry)) + return entries + + def get_entry(self, entry_id: int): + """ + Gets and returns an entry. + + Parameters: + - form_id: The ID of the entry. + """ + response = self.get(f"/entries/{entry_id}") + entry = Entry(**response) + return entry diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index e2df0b7..e2a9c64 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -7,18 +7,76 @@ def test_environment_variable_error(): try: gravity_forms = GravityForms() - gravity_forms.get("/forms/2/entries") + gravity_forms.get( + "/forms/2/entries", params={"paging[current_page]": 1, "paging[page_size]": 5} + ) assert False except ValueError: assert True -def test_request_exception_get(caplog): +def test_request_exception_get(): + with patch("requests_oauthlib.OAuth1Session.get") as mock_get: + mock_get.side_effect = RequestException("Simulated request exception.") + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + try: + _ = gravity_forms.get( + "/forms/2/entries", params={"paging[current_page]": 1, "paging[page_size]": 5} + ) + assert False + except RequestException as e: + assert str(e) == "Simulated request exception." + + +def test_get_forms_exception(): + with patch("requests_oauthlib.OAuth1Session.get") as mock_get: + mock_get.side_effect = RequestException("Simulated request exception.") + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + try: + _ = gravity_forms.get_forms() + assert False + except RequestException as e: + assert str(e) == "Simulated request exception." + + +def test_get_form_exception(): + with patch("requests_oauthlib.OAuth1Session.get") as mock_get: + mock_get.side_effect = RequestException("Simulated request exception.") + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + try: + _ = gravity_forms.get_form("1234") + assert False + except RequestException as e: + assert str(e) == "Simulated request exception." + + +def test_get_entries_exception(): + with patch("requests_oauthlib.OAuth1Session.get") as mock_get: + mock_get.side_effect = RequestException("Simulated request exception.") + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + try: + _ = gravity_forms.get_entries() + assert False + except RequestException as e: + assert str(e) == "Simulated request exception." + + +def test_get_entry_exception(): with patch("requests_oauthlib.OAuth1Session.get") as mock_get: mock_get.side_effect = RequestException("Simulated request exception.") gravity_forms = GravityForms( consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" ) - response = gravity_forms.get("/forms/2/entries") - assert response == {} - assert "Simulated request exception." in caplog.text + try: + _ = gravity_forms.get_entry("1234") + assert False + except RequestException as e: + assert str(e) == "Simulated request exception." From 1c68d5ec5efd088410387aa42495a56686c4576d Mon Sep 17 00:00:00 2001 From: John Champion Date: Thu, 22 Feb 2024 15:06:05 -0500 Subject: [PATCH 02/14] update version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4a60090..857002c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "sat-utils" -version = "1.2.1" +version = "1.3.0" authors = [ { name="Ryan Semmler", email="rsemmle@ncsu.edu" }, { name="Shawn Taylor", email="staylor8@ncsu.edu" }, From 4eafd6328814735c8ae8249787d5edc83981b482 Mon Sep 17 00:00:00 2001 From: John Champion Date: Thu, 22 Feb 2024 15:21:13 -0500 Subject: [PATCH 03/14] add more tests --- tests/test_gravity_forms.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index e2a9c64..891131b 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -1,7 +1,7 @@ from unittest.mock import patch from requests.exceptions import RequestException -from sat.gravity_forms import GravityForms +from sat.gravity_forms import Entry, Form, GravityForms def test_environment_variable_error(): @@ -80,3 +80,35 @@ def test_get_entry_exception(): assert False except RequestException as e: assert str(e) == "Simulated request exception." + + +def test_create_form_model(): + form_data = { + "id": "1", + "title": "form title", + "description": "form description", + "is_active": True, + "custom_field": "completely custom", + } + form = Form(**form_data) + assert form.id == "1" + assert form.title == "form title" + assert form.description == "form description" + assert form.is_active is True + assert form.details == {"custom_field": "completely custom"} + + +def test_create_entry_model(): + entry_data = { + "id": "1", + "form_id": "1", + "created_by": "yours truly", + "status": "alive", + "custom_field": "completely custom", + } + entry = Entry(**entry_data) + assert entry.id == "1" + assert entry.form_id == "1" + assert entry.created_by == "yours truly" + assert entry.status == "alive" + assert entry.details == {"custom_field": "completely custom"} From 49e6996cd86e0b40b183e5ce0ddcd27043ab421e Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Mon, 26 Feb 2024 10:06:37 -0500 Subject: [PATCH 04/14] Some enhancements to the project to add jupyter lab notebooks. --- Makefile | 4 + notebooks/Untitled.ipynb | 411 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- requirements/base/base.txt | 4 +- requirements/dev/dev.txt | 288 ++++++++++++++++++++++++-- 5 files changed, 694 insertions(+), 15 deletions(-) create mode 100644 notebooks/Untitled.ipynb diff --git a/Makefile b/Makefile index 792f3c3..d4a129a 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,10 @@ install-dev: @echo 'Installing requirements...' pip-sync requirements/base/base.txt requirements/dev/dev.txt +lab: + @echo 'Starting Jupyter Lab...' + jupyter lab + setup: @echo 'Setting up the environment...' pip config --site set global.extra-index-url https://pypi.ehps.ncsu.edu/ diff --git a/notebooks/Untitled.ipynb b/notebooks/Untitled.ipynb new file mode 100644 index 0000000..25c8c40 --- /dev/null +++ b/notebooks/Untitled.ipynb @@ -0,0 +1,411 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "b1db26d3-9f3f-48b5-9880-1bf64c61bdac", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import os, sys\n", + "from pathlib import Path\n", + "PROJECTPATH = '/home/jmgibso3/ncstate/projects/sat-utils/'\n", + "sys.path.insert(0, PROJECTPATH)\n", + "os.chdir(PROJECTPATH)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "81212050-3259-4c17-9844-5d2230cfcce0", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from urllib.parse import urlencode\n", + "from sat import gravity_forms" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1f4728d2-26b1-4cbb-b856-2e9b458b619d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "gravity = gravity_forms.GravityForms()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "fce9b5d2-d3ad-4f9e-b5ef-8ebc2743692f", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form = gravity.get_form(3)\n", + "form" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0b3e9de6-4170-4538-9e3b-d99d3ae2ceec", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gravity.get_forms()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "250b3874-8dcd-47d9-b321-41d767778bd9", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "ent = gravity.get_entries()[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "a184a4f1-c213-4f66-92a5-0a05b158fbf4", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'1'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dir(ent)\n", + "\n", + "ent.form_id" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "58ab3076-2274-4fa8-9517-3baa3bc0053b", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'NESTED - Request form - cardholder info'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form.title" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "198abbfe-6d57-414c-b1cd-e1004a14f4d6", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'labelPlacement': 'top_label',\n", + " 'descriptionPlacement': 'below',\n", + " 'button': {'type': 'text', 'text': 'Submit', 'imageUrl': ''},\n", + " 'fields': [{'type': 'name',\n", + " 'id': 2,\n", + " 'label': 'Name',\n", + " 'adminLabel': '',\n", + " 'isRequired': True,\n", + " 'size': 'medium',\n", + " 'errorMessage': '',\n", + " 'visibility': 'visible',\n", + " 'nameFormat': 'advanced',\n", + " 'inputs': [{'id': '2.2',\n", + " 'label': 'Prefix',\n", + " 'name': '',\n", + " 'choices': [{'text': 'Mr.',\n", + " 'value': 'Mr.',\n", + " 'isSelected': False,\n", + " 'price': ''},\n", + " {'text': 'Mrs.', 'value': 'Mrs.', 'isSelected': False, 'price': ''},\n", + " {'text': 'Miss', 'value': 'Miss', 'isSelected': False, 'price': ''},\n", + " {'text': 'Ms.', 'value': 'Ms.', 'isSelected': False, 'price': ''},\n", + " {'text': 'Dr.', 'value': 'Dr.', 'isSelected': False, 'price': ''},\n", + " {'text': 'Prof.', 'value': 'Prof.', 'isSelected': False, 'price': ''},\n", + " {'text': 'Rev.', 'value': 'Rev.', 'isSelected': False, 'price': ''}],\n", + " 'isHidden': True,\n", + " 'inputType': 'radio'},\n", + " {'id': '2.3', 'label': 'First', 'name': ''},\n", + " {'id': '2.4', 'label': 'Middle', 'name': '', 'isHidden': True},\n", + " {'id': '2.6', 'label': 'Last', 'name': ''},\n", + " {'id': '2.8', 'label': 'Suffix', 'name': '', 'isHidden': True}],\n", + " 'formId': 3,\n", + " 'description': '',\n", + " 'allowsPrepopulate': False,\n", + " 'inputMask': False,\n", + " 'inputMaskValue': '',\n", + " 'inputType': '',\n", + " 'labelPlacement': '',\n", + " 'descriptionPlacement': '',\n", + " 'subLabelPlacement': '',\n", + " 'placeholder': '',\n", + " 'cssClass': '',\n", + " 'inputName': '',\n", + " 'noDuplicates': False,\n", + " 'defaultValue': '',\n", + " 'choices': '',\n", + " 'conditionalLogic': '',\n", + " 'productField': '',\n", + " 'multipleFiles': False,\n", + " 'maxFiles': '',\n", + " 'calculationFormula': '',\n", + " 'calculationRounding': '',\n", + " 'enableCalculation': '',\n", + " 'disableQuantity': False,\n", + " 'displayAllCategories': False,\n", + " 'useRichTextEditor': False,\n", + " 'pageNumber': 1,\n", + " 'displayOnly': '',\n", + " 'fields': '',\n", + " 'inputMaskIsCustom': '',\n", + " 'maxLength': ''},\n", + " {'type': 'email',\n", + " 'id': 3,\n", + " 'label': 'Email',\n", + " 'adminLabel': '',\n", + " 'isRequired': True,\n", + " 'size': 'medium',\n", + " 'errorMessage': '',\n", + " 'visibility': 'visible',\n", + " 'inputs': None,\n", + " 'formId': 3,\n", + " 'description': '',\n", + " 'allowsPrepopulate': False,\n", + " 'inputMask': False,\n", + " 'inputMaskValue': '',\n", + " 'inputType': '',\n", + " 'labelPlacement': '',\n", + " 'descriptionPlacement': '',\n", + " 'subLabelPlacement': '',\n", + " 'placeholder': '',\n", + " 'cssClass': '',\n", + " 'inputName': '',\n", + " 'noDuplicates': False,\n", + " 'defaultValue': '',\n", + " 'choices': '',\n", + " 'conditionalLogic': '',\n", + " 'productField': '',\n", + " 'emailConfirmEnabled': '',\n", + " 'multipleFiles': False,\n", + " 'maxFiles': '',\n", + " 'calculationFormula': '',\n", + " 'calculationRounding': '',\n", + " 'enableCalculation': '',\n", + " 'disableQuantity': False,\n", + " 'displayAllCategories': False,\n", + " 'useRichTextEditor': False,\n", + " 'pageNumber': 1,\n", + " 'displayOnly': '',\n", + " 'fields': '',\n", + " 'inputMaskIsCustom': '',\n", + " 'maxLength': ''},\n", + " {'type': 'text',\n", + " 'id': 5,\n", + " 'label': 'Campus ID (if available)',\n", + " 'adminLabel': '',\n", + " 'isRequired': False,\n", + " 'size': 'medium',\n", + " 'errorMessage': '',\n", + " 'visibility': 'visible',\n", + " 'inputs': None,\n", + " 'formId': 3,\n", + " 'description': 'If the card holder already has an assigned 9-digit Campus ID number, please enter it here.',\n", + " 'allowsPrepopulate': False,\n", + " 'inputMask': True,\n", + " 'inputMaskValue': '999999999',\n", + " 'inputMaskIsCustom': True,\n", + " 'maxLength': '',\n", + " 'inputType': '',\n", + " 'labelPlacement': '',\n", + " 'descriptionPlacement': '',\n", + " 'subLabelPlacement': '',\n", + " 'placeholder': '',\n", + " 'cssClass': '',\n", + " 'inputName': '',\n", + " 'noDuplicates': False,\n", + " 'defaultValue': '',\n", + " 'choices': '',\n", + " 'conditionalLogic': '',\n", + " 'productField': '',\n", + " 'enablePasswordInput': '',\n", + " 'multipleFiles': False,\n", + " 'maxFiles': '',\n", + " 'calculationFormula': '',\n", + " 'calculationRounding': '',\n", + " 'enableCalculation': '',\n", + " 'disableQuantity': False,\n", + " 'displayAllCategories': False,\n", + " 'useRichTextEditor': False,\n", + " 'gp-unique-id_starting_number': '',\n", + " 'checkboxLabel': '',\n", + " 'pageNumber': 1,\n", + " 'fields': ''},\n", + " {'type': 'uid',\n", + " 'id': 4,\n", + " 'label': 'Unique ID',\n", + " 'adminLabel': '',\n", + " 'isRequired': False,\n", + " 'size': 'medium',\n", + " 'errorMessage': '',\n", + " 'visibility': 'hidden',\n", + " 'inputs': None,\n", + " 'gp-unique-id_type': 'sequential',\n", + " 'formId': 3,\n", + " 'description': '',\n", + " 'allowsPrepopulate': False,\n", + " 'inputMask': False,\n", + " 'inputMaskValue': '',\n", + " 'inputType': '',\n", + " 'labelPlacement': '',\n", + " 'descriptionPlacement': '',\n", + " 'subLabelPlacement': '',\n", + " 'placeholder': '',\n", + " 'cssClass': '',\n", + " 'inputName': '',\n", + " 'noDuplicates': False,\n", + " 'defaultValue': '',\n", + " 'choices': '',\n", + " 'conditionalLogic': {'actionType': 'hide',\n", + " 'logicType': 'all',\n", + " 'rules': [{'fieldId': '5', 'operator': '>', 'value': '0'}]},\n", + " 'productField': '',\n", + " 'multipleFiles': False,\n", + " 'maxFiles': '',\n", + " 'calculationFormula': '',\n", + " 'calculationRounding': '',\n", + " 'enableCalculation': '',\n", + " 'disableQuantity': False,\n", + " 'displayAllCategories': False,\n", + " 'useRichTextEditor': False,\n", + " 'gp-unique-id_starting_number': '100028400',\n", + " 'pageNumber': 1,\n", + " 'displayOnly': '',\n", + " 'fields': '',\n", + " 'inputMaskIsCustom': False,\n", + " 'maxLength': ''}],\n", + " 'useCurrentUserAsAuthor': True,\n", + " 'postContentTemplateEnabled': False,\n", + " 'postTitleTemplateEnabled': False,\n", + " 'postTitleTemplate': '',\n", + " 'postContentTemplate': '',\n", + " 'lastPageButton': None,\n", + " 'pagination': None,\n", + " 'firstPageCssClass': None,\n", + " 'nextFieldId': 6,\n", + " 'notifications': [],\n", + " 'confirmations': {'5acfbb44d680c': {'id': '5acfbb44d680c',\n", + " 'name': 'Default Confirmation',\n", + " 'isDefault': True,\n", + " 'type': 'message',\n", + " 'message': 'Thanks for contacting us! We will get in touch with you shortly.',\n", + " 'url': '',\n", + " 'pageId': '',\n", + " 'queryString': ''}}}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form.details" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff5e1405-3a4b-42c8-ba9a-7db99b7943b4", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/pyproject.toml b/pyproject.toml index 857002c..d9671db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dev = [ "pre-commit>=2.16.0, <3.0.0", "isort>=5.10.1, <6.0.0", "pyupgrade>=2.29.1, <3.0.0", - "ipython>=8.13.0, <9.0.0", + "jupyterlab>=3.2.0, <4.0.0", "flit>=3.8.0, <4.0.0", ] diff --git a/requirements/base/base.txt b/requirements/base/base.txt index faf840b..9d83492 100644 --- a/requirements/base/base.txt +++ b/requirements/base/base.txt @@ -4,6 +4,8 @@ # # pip-compile --output-file=requirements/base/base.txt pyproject.toml # +--extra-index-url https://pypi.ehps.ncsu.edu/ + certifi==2022.12.7 # via requests cffi==1.15.1 @@ -20,7 +22,7 @@ ldap3==2.9.1 # via sat-utils (pyproject.toml) oauthlib==3.2.2 # via requests-oauthlib -oracledb==1.4.1 +oracledb==2.0.1 # via sat-utils (pyproject.toml) pyasn1==0.5.0 # via ldap3 diff --git a/requirements/dev/dev.txt b/requirements/dev/dev.txt index d683e43..843bb3e 100644 --- a/requirements/dev/dev.txt +++ b/requirements/dev/dev.txt @@ -4,22 +4,48 @@ # # pip-compile --extra=dev --output-file=requirements/dev/dev.txt pyproject.toml # -appnope==0.1.3 - # via ipython +--extra-index-url https://pypi.ehps.ncsu.edu/ + +aiofiles==22.1.0 + # via ypy-websocket +aiosqlite==0.20.0 + # via ypy-websocket +anyio==4.3.0 + # via jupyter-server +argon2-cffi==23.1.0 + # via + # jupyter-server + # nbclassic + # notebook +argon2-cffi-bindings==21.2.0 + # via argon2-cffi +arrow==1.3.0 + # via isoduration asttokens==2.2.1 # via stack-data attrs==23.1.0 - # via pytest + # via + # jsonschema + # pytest + # referencing +babel==2.14.0 + # via jupyterlab-server backcall==0.2.0 # via ipython bandit==1.7.5 # via sat-utils (pyproject.toml) +beautifulsoup4==4.12.3 + # via nbconvert black==23.3.0 # via sat-utils (pyproject.toml) +bleach==6.1.0 + # via nbconvert certifi==2022.12.7 # via requests cffi==1.15.1 - # via cryptography + # via + # argon2-cffi-bindings + # cryptography cfgv==3.3.1 # via pre-commit charset-normalizer==3.1.0 @@ -30,29 +56,42 @@ click==8.1.3 # mkdocs colorama==0.4.6 # via mkdocs-material +comm==0.2.1 + # via ipykernel coverage[toml]==7.2.5 # via - # coverage # pytest-cov # sat-utils (pyproject.toml) cryptography==41.0.3 # via oracledb cx-oracle==8.3.0 # via sat-utils (pyproject.toml) +debugpy==1.8.1 + # via ipykernel decorator==5.1.1 # via ipython +defusedxml==0.7.1 + # via nbconvert distlib==0.3.6 # via virtualenv docutils==0.19 # via flit +entrypoints==0.4 + # via jupyter-client +exceptiongroup==1.2.0 + # via anyio executing==1.2.0 # via stack-data +fastjsonschema==2.19.1 + # via nbformat filelock==3.12.0 # via virtualenv flit==3.8.0 # via sat-utils (pyproject.toml) flit-core==3.8.0 # via flit +fqdn==1.5.1 + # via jsonschema ghp-import==2.1.0 # via mkdocs gitdb==4.0.10 @@ -62,19 +101,96 @@ gitpython==3.1.31 identify==2.5.24 # via pre-commit idna==3.4 - # via requests + # via + # anyio + # jsonschema + # requests iniconfig==2.0.0 # via pytest +ipykernel==6.29.2 + # via + # nbclassic + # notebook ipython==8.13.2 - # via sat-utils (pyproject.toml) + # via + # ipykernel + # jupyterlab +ipython-genutils==0.2.0 + # via + # nbclassic + # notebook +isoduration==20.11.0 + # via jsonschema isort==5.12.0 # via sat-utils (pyproject.toml) jedi==0.18.2 # via ipython jinja2==3.1.2 # via + # jupyter-server + # jupyterlab + # jupyterlab-server # mkdocs # mkdocs-material + # nbclassic + # nbconvert + # notebook +json5==0.9.17 + # via jupyterlab-server +jsonpointer==2.4 + # via jsonschema +jsonschema[format-nongpl]==4.21.1 + # via + # jupyter-events + # jupyterlab-server + # nbformat +jsonschema-specifications==2023.12.1 + # via jsonschema +jupyter-client==7.4.9 + # via + # ipykernel + # jupyter-server + # nbclassic + # nbclient + # notebook +jupyter-core==5.7.1 + # via + # ipykernel + # jupyter-client + # jupyter-server + # jupyterlab + # nbclassic + # nbclient + # nbconvert + # nbformat + # notebook +jupyter-events==0.9.0 + # via + # jupyter-server + # jupyter-server-fileid +jupyter-server==2.12.5 + # via + # jupyter-server-fileid + # jupyterlab + # jupyterlab-server + # nbclassic + # notebook-shim +jupyter-server-fileid==0.9.1 + # via jupyter-server-ydoc +jupyter-server-terminals==0.5.2 + # via jupyter-server +jupyter-server-ydoc==0.8.0 + # via jupyterlab +jupyter-ydoc==0.2.5 + # via + # jupyter-server-ydoc + # jupyterlab +jupyterlab==3.6.7 + # via sat-utils (pyproject.toml) +jupyterlab-pygments==0.3.0 + # via nbconvert +jupyterlab-server==2.24.0 + # via jupyterlab ldap3==2.9.1 # via sat-utils (pyproject.toml) markdown==3.3.7 @@ -85,13 +201,19 @@ markdown==3.3.7 markdown-it-py==2.2.0 # via rich markupsafe==2.1.2 - # via jinja2 + # via + # jinja2 + # nbconvert matplotlib-inline==0.1.6 - # via ipython + # via + # ipykernel + # ipython mdurl==0.1.2 # via markdown-it-py mergedeep==1.3.4 # via mkdocs +mistune==3.0.2 + # via nbconvert mkdocs==1.4.3 # via mkdocs-material mkdocs-material==9.1.9 @@ -104,17 +226,54 @@ mypy-extensions==1.0.0 # via # black # mypy +nbclassic==1.0.0 + # via + # jupyterlab + # notebook +nbclient==0.9.0 + # via nbconvert +nbconvert==7.16.1 + # via + # jupyter-server + # nbclassic + # notebook +nbformat==5.9.2 + # via + # jupyter-server + # nbclassic + # nbclient + # nbconvert + # notebook +nest-asyncio==1.6.0 + # via + # ipykernel + # jupyter-client + # nbclassic + # notebook nodeenv==1.7.0 # via pre-commit +notebook==6.5.6 + # via jupyterlab +notebook-shim==0.2.4 + # via nbclassic oauthlib==3.2.2 # via requests-oauthlib -oracledb==1.4.1 +oracledb==2.0.1 # via sat-utils (pyproject.toml) +overrides==7.7.0 + # via jupyter-server packaging==23.1 # via # black + # ipykernel + # jupyter-server + # jupyterlab + # jupyterlab-server # mkdocs + # nbconvert # pytest +pandocfilters==1.5.1 + # via nbconvert parso==0.8.3 # via jedi pathspec==0.11.1 @@ -128,15 +287,25 @@ pickleshare==0.7.5 platformdirs==3.5.0 # via # black + # jupyter-core # virtualenv pluggy==1.0.0 # via pytest pre-commit==2.21.0 # via sat-utils (pyproject.toml) +prometheus-client==0.20.0 + # via + # jupyter-server + # nbclassic + # notebook prompt-toolkit==3.0.38 # via ipython +psutil==5.9.8 + # via ipykernel ptyprocess==0.7.0 - # via pexpect + # via + # pexpect + # terminado pure-eval==0.2.2 # via stack-data py==1.11.0 @@ -149,6 +318,7 @@ pygments==2.15.1 # via # ipython # mkdocs-material + # nbconvert # rich # sat-utils (pyproject.toml) pymdown-extensions==9.11 @@ -165,44 +335,94 @@ pytest-cov==4.0.0 pytest-mock==3.10.0 # via sat-utils (pyproject.toml) python-dateutil==2.8.2 - # via ghp-import + # via + # arrow + # ghp-import + # jupyter-client +python-json-logger==2.0.7 + # via jupyter-events pyupgrade==2.38.4 # via sat-utils (pyproject.toml) pyyaml==6.0 # via # bandit + # jupyter-events # mkdocs # pre-commit # pymdown-extensions # pyyaml-env-tag pyyaml-env-tag==0.1 # via mkdocs +pyzmq==24.0.1 + # via + # ipykernel + # jupyter-client + # jupyter-server + # nbclassic + # notebook +referencing==0.33.0 + # via + # jsonschema + # jsonschema-specifications + # jupyter-events regex==2023.5.5 # via mkdocs-material requests==2.30.0 # via # flit + # jupyterlab-server # mkdocs-material # requests-oauthlib # sat-utils (pyproject.toml) requests-oauthlib==1.3.1 # via sat-utils (pyproject.toml) +rfc3339-validator==0.1.4 + # via + # jsonschema + # jupyter-events +rfc3986-validator==0.1.1 + # via + # jsonschema + # jupyter-events rich==13.3.5 # via bandit +rpds-py==0.18.0 + # via + # jsonschema + # referencing ruff==0.0.263 # via sat-utils (pyproject.toml) +send2trash==1.8.2 + # via + # jupyter-server + # nbclassic + # notebook six==1.16.0 # via # asttokens + # bleach # python-dateutil + # rfc3339-validator slack-sdk==3.21.3 # via sat-utils (pyproject.toml) smmap==5.0.0 # via gitdb +sniffio==1.3.1 + # via anyio +soupsieve==2.5 + # via beautifulsoup4 stack-data==0.6.2 # via ipython stevedore==5.0.0 # via bandit +terminado==0.18.0 + # via + # jupyter-server + # jupyter-server-terminals + # nbclassic + # notebook +tinycss2==1.2.1 + # via nbconvert tokenize-rt==4.2.1 # via pyupgrade toml==0.10.2 @@ -211,15 +431,43 @@ tomli==2.0.1 # via # black # coverage + # jupyterlab # mypy tomli-w==1.0.0 # via flit +tornado==6.4 + # via + # ipykernel + # jupyter-client + # jupyter-server + # jupyterlab + # nbclassic + # notebook + # terminado traitlets==5.9.0 # via + # comm + # ipykernel # ipython + # jupyter-client + # jupyter-core + # jupyter-events + # jupyter-server # matplotlib-inline + # nbclassic + # nbclient + # nbconvert + # nbformat + # notebook +types-python-dateutil==2.8.19.20240106 + # via arrow typing-extensions==4.5.0 - # via mypy + # via + # aiosqlite + # anyio + # mypy +uri-template==1.3.0 + # via jsonschema urllib3==2.0.2 # via requests virtualenv==20.23.0 @@ -228,6 +476,20 @@ watchdog==3.0.0 # via mkdocs wcwidth==0.2.6 # via prompt-toolkit +webcolors==1.13 + # via jsonschema +webencodings==0.5.1 + # via + # bleach + # tinycss2 +websocket-client==1.7.0 + # via jupyter-server +y-py==0.6.2 + # via + # jupyter-ydoc + # ypy-websocket +ypy-websocket==0.8.4 + # via jupyter-server-ydoc # The following packages are considered to be unsafe in a requirements file: # setuptools From a556231d7610f95d048a1ffa70c060b83deb313f Mon Sep 17 00:00:00 2001 From: John Champion Date: Tue, 27 Feb 2024 10:27:29 -0500 Subject: [PATCH 05/14] make tweaks --- sat/gravity_forms.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index a466ca7..a6bfa22 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -23,7 +23,7 @@ class Form: A form object from GravityForms. """ - id: int + id: str title: str description: str date_created: str @@ -171,9 +171,9 @@ def get(self, endpoint: str, params: Optional[dict] = None): """ param_string: str = "?" - if params is not None: - for param in params: - param_string += f"{param}={params[param]}&" + if params: + for key, value in params.items(): + param_string += f"{key}={value}&" try: response = self.session.get(self.base_url + endpoint + param_string) @@ -204,12 +204,16 @@ def get_form(self, form_id: int): entry = Form(**response) return entry - def get_entries(self, page: int = 1, page_size: int = 20): + def get_entries(self, page: int = 1, page_size: int = 20, form_id: Optional[str] = None): """ Gets and returns a list of entries. """ + url = "/entries" + if form_id: + url = f"/forms/{form_id}/entries" + response = self.get( - "/entries", params={"paging[current_page]": page, "paging[page_size]": page_size} + url, params={"paging[current_page]": page, "paging[page_size]": page_size} ) entries = [] for entry in response["entries"]: From a5e73e3f1475d8f636a9098cd383578838f47f82 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Wed, 28 Feb 2024 11:49:33 -0500 Subject: [PATCH 06/14] Adds jupyterlab as runner for notebooks --- notebooks/Untitled.ipynb | 411 ----------------------------- notebooks/test_gravity_forms.ipynb | 354 +++++++++++++++++++++++++ 2 files changed, 354 insertions(+), 411 deletions(-) delete mode 100644 notebooks/Untitled.ipynb create mode 100644 notebooks/test_gravity_forms.ipynb diff --git a/notebooks/Untitled.ipynb b/notebooks/Untitled.ipynb deleted file mode 100644 index 25c8c40..0000000 --- a/notebooks/Untitled.ipynb +++ /dev/null @@ -1,411 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "b1db26d3-9f3f-48b5-9880-1bf64c61bdac", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import os, sys\n", - "from pathlib import Path\n", - "PROJECTPATH = '/home/jmgibso3/ncstate/projects/sat-utils/'\n", - "sys.path.insert(0, PROJECTPATH)\n", - "os.chdir(PROJECTPATH)" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "81212050-3259-4c17-9844-5d2230cfcce0", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from urllib.parse import urlencode\n", - "from sat import gravity_forms" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "1f4728d2-26b1-4cbb-b856-2e9b458b619d", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "gravity = gravity_forms.GravityForms()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "fce9b5d2-d3ad-4f9e-b5ef-8ebc2743692f", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "form = gravity.get_form(3)\n", - "form" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "0b3e9de6-4170-4538-9e3b-d99d3ae2ceec", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[,\n", - " ,\n", - " ,\n", - " ,\n", - " ,\n", - " ]" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "gravity.get_forms()" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "250b3874-8dcd-47d9-b321-41d767778bd9", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "ent = gravity.get_entries()[0]" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "a184a4f1-c213-4f66-92a5-0a05b158fbf4", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'1'" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dir(ent)\n", - "\n", - "ent.form_id" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "58ab3076-2274-4fa8-9517-3baa3bc0053b", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'NESTED - Request form - cardholder info'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "form.title" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "198abbfe-6d57-414c-b1cd-e1004a14f4d6", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'labelPlacement': 'top_label',\n", - " 'descriptionPlacement': 'below',\n", - " 'button': {'type': 'text', 'text': 'Submit', 'imageUrl': ''},\n", - " 'fields': [{'type': 'name',\n", - " 'id': 2,\n", - " 'label': 'Name',\n", - " 'adminLabel': '',\n", - " 'isRequired': True,\n", - " 'size': 'medium',\n", - " 'errorMessage': '',\n", - " 'visibility': 'visible',\n", - " 'nameFormat': 'advanced',\n", - " 'inputs': [{'id': '2.2',\n", - " 'label': 'Prefix',\n", - " 'name': '',\n", - " 'choices': [{'text': 'Mr.',\n", - " 'value': 'Mr.',\n", - " 'isSelected': False,\n", - " 'price': ''},\n", - " {'text': 'Mrs.', 'value': 'Mrs.', 'isSelected': False, 'price': ''},\n", - " {'text': 'Miss', 'value': 'Miss', 'isSelected': False, 'price': ''},\n", - " {'text': 'Ms.', 'value': 'Ms.', 'isSelected': False, 'price': ''},\n", - " {'text': 'Dr.', 'value': 'Dr.', 'isSelected': False, 'price': ''},\n", - " {'text': 'Prof.', 'value': 'Prof.', 'isSelected': False, 'price': ''},\n", - " {'text': 'Rev.', 'value': 'Rev.', 'isSelected': False, 'price': ''}],\n", - " 'isHidden': True,\n", - " 'inputType': 'radio'},\n", - " {'id': '2.3', 'label': 'First', 'name': ''},\n", - " {'id': '2.4', 'label': 'Middle', 'name': '', 'isHidden': True},\n", - " {'id': '2.6', 'label': 'Last', 'name': ''},\n", - " {'id': '2.8', 'label': 'Suffix', 'name': '', 'isHidden': True}],\n", - " 'formId': 3,\n", - " 'description': '',\n", - " 'allowsPrepopulate': False,\n", - " 'inputMask': False,\n", - " 'inputMaskValue': '',\n", - " 'inputType': '',\n", - " 'labelPlacement': '',\n", - " 'descriptionPlacement': '',\n", - " 'subLabelPlacement': '',\n", - " 'placeholder': '',\n", - " 'cssClass': '',\n", - " 'inputName': '',\n", - " 'noDuplicates': False,\n", - " 'defaultValue': '',\n", - " 'choices': '',\n", - " 'conditionalLogic': '',\n", - " 'productField': '',\n", - " 'multipleFiles': False,\n", - " 'maxFiles': '',\n", - " 'calculationFormula': '',\n", - " 'calculationRounding': '',\n", - " 'enableCalculation': '',\n", - " 'disableQuantity': False,\n", - " 'displayAllCategories': False,\n", - " 'useRichTextEditor': False,\n", - " 'pageNumber': 1,\n", - " 'displayOnly': '',\n", - " 'fields': '',\n", - " 'inputMaskIsCustom': '',\n", - " 'maxLength': ''},\n", - " {'type': 'email',\n", - " 'id': 3,\n", - " 'label': 'Email',\n", - " 'adminLabel': '',\n", - " 'isRequired': True,\n", - " 'size': 'medium',\n", - " 'errorMessage': '',\n", - " 'visibility': 'visible',\n", - " 'inputs': None,\n", - " 'formId': 3,\n", - " 'description': '',\n", - " 'allowsPrepopulate': False,\n", - " 'inputMask': False,\n", - " 'inputMaskValue': '',\n", - " 'inputType': '',\n", - " 'labelPlacement': '',\n", - " 'descriptionPlacement': '',\n", - " 'subLabelPlacement': '',\n", - " 'placeholder': '',\n", - " 'cssClass': '',\n", - " 'inputName': '',\n", - " 'noDuplicates': False,\n", - " 'defaultValue': '',\n", - " 'choices': '',\n", - " 'conditionalLogic': '',\n", - " 'productField': '',\n", - " 'emailConfirmEnabled': '',\n", - " 'multipleFiles': False,\n", - " 'maxFiles': '',\n", - " 'calculationFormula': '',\n", - " 'calculationRounding': '',\n", - " 'enableCalculation': '',\n", - " 'disableQuantity': False,\n", - " 'displayAllCategories': False,\n", - " 'useRichTextEditor': False,\n", - " 'pageNumber': 1,\n", - " 'displayOnly': '',\n", - " 'fields': '',\n", - " 'inputMaskIsCustom': '',\n", - " 'maxLength': ''},\n", - " {'type': 'text',\n", - " 'id': 5,\n", - " 'label': 'Campus ID (if available)',\n", - " 'adminLabel': '',\n", - " 'isRequired': False,\n", - " 'size': 'medium',\n", - " 'errorMessage': '',\n", - " 'visibility': 'visible',\n", - " 'inputs': None,\n", - " 'formId': 3,\n", - " 'description': 'If the card holder already has an assigned 9-digit Campus ID number, please enter it here.',\n", - " 'allowsPrepopulate': False,\n", - " 'inputMask': True,\n", - " 'inputMaskValue': '999999999',\n", - " 'inputMaskIsCustom': True,\n", - " 'maxLength': '',\n", - " 'inputType': '',\n", - " 'labelPlacement': '',\n", - " 'descriptionPlacement': '',\n", - " 'subLabelPlacement': '',\n", - " 'placeholder': '',\n", - " 'cssClass': '',\n", - " 'inputName': '',\n", - " 'noDuplicates': False,\n", - " 'defaultValue': '',\n", - " 'choices': '',\n", - " 'conditionalLogic': '',\n", - " 'productField': '',\n", - " 'enablePasswordInput': '',\n", - " 'multipleFiles': False,\n", - " 'maxFiles': '',\n", - " 'calculationFormula': '',\n", - " 'calculationRounding': '',\n", - " 'enableCalculation': '',\n", - " 'disableQuantity': False,\n", - " 'displayAllCategories': False,\n", - " 'useRichTextEditor': False,\n", - " 'gp-unique-id_starting_number': '',\n", - " 'checkboxLabel': '',\n", - " 'pageNumber': 1,\n", - " 'fields': ''},\n", - " {'type': 'uid',\n", - " 'id': 4,\n", - " 'label': 'Unique ID',\n", - " 'adminLabel': '',\n", - " 'isRequired': False,\n", - " 'size': 'medium',\n", - " 'errorMessage': '',\n", - " 'visibility': 'hidden',\n", - " 'inputs': None,\n", - " 'gp-unique-id_type': 'sequential',\n", - " 'formId': 3,\n", - " 'description': '',\n", - " 'allowsPrepopulate': False,\n", - " 'inputMask': False,\n", - " 'inputMaskValue': '',\n", - " 'inputType': '',\n", - " 'labelPlacement': '',\n", - " 'descriptionPlacement': '',\n", - " 'subLabelPlacement': '',\n", - " 'placeholder': '',\n", - " 'cssClass': '',\n", - " 'inputName': '',\n", - " 'noDuplicates': False,\n", - " 'defaultValue': '',\n", - " 'choices': '',\n", - " 'conditionalLogic': {'actionType': 'hide',\n", - " 'logicType': 'all',\n", - " 'rules': [{'fieldId': '5', 'operator': '>', 'value': '0'}]},\n", - " 'productField': '',\n", - " 'multipleFiles': False,\n", - " 'maxFiles': '',\n", - " 'calculationFormula': '',\n", - " 'calculationRounding': '',\n", - " 'enableCalculation': '',\n", - " 'disableQuantity': False,\n", - " 'displayAllCategories': False,\n", - " 'useRichTextEditor': False,\n", - " 'gp-unique-id_starting_number': '100028400',\n", - " 'pageNumber': 1,\n", - " 'displayOnly': '',\n", - " 'fields': '',\n", - " 'inputMaskIsCustom': False,\n", - " 'maxLength': ''}],\n", - " 'useCurrentUserAsAuthor': True,\n", - " 'postContentTemplateEnabled': False,\n", - " 'postTitleTemplateEnabled': False,\n", - " 'postTitleTemplate': '',\n", - " 'postContentTemplate': '',\n", - " 'lastPageButton': None,\n", - " 'pagination': None,\n", - " 'firstPageCssClass': None,\n", - " 'nextFieldId': 6,\n", - " 'notifications': [],\n", - " 'confirmations': {'5acfbb44d680c': {'id': '5acfbb44d680c',\n", - " 'name': 'Default Confirmation',\n", - " 'isDefault': True,\n", - " 'type': 'message',\n", - " 'message': 'Thanks for contacting us! We will get in touch with you shortly.',\n", - " 'url': '',\n", - " 'pageId': '',\n", - " 'queryString': ''}}}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "form.details" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ff5e1405-3a4b-42c8-ba9a-7db99b7943b4", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.4" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/test_gravity_forms.ipynb b/notebooks/test_gravity_forms.ipynb new file mode 100644 index 0000000..7d7e78f --- /dev/null +++ b/notebooks/test_gravity_forms.ipynb @@ -0,0 +1,354 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "b1db26d3-9f3f-48b5-9880-1bf64c61bdac", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import os, sys\n", + "from pathlib import Path\n", + "PROJECTPATH = '/home/jmgibso3/ncstate/projects/sat-utils/'\n", + "sys.path.insert(0, PROJECTPATH)\n", + "os.chdir(PROJECTPATH)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "81212050-3259-4c17-9844-5d2230cfcce0", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from urllib.parse import urlencode\n", + "from sat import gravity_forms" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1f4728d2-26b1-4cbb-b856-2e9b458b619d", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "gravity = gravity_forms.GravityForms()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "fce9b5d2-d3ad-4f9e-b5ef-8ebc2743692f", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "form = gravity.get_form(3)\n", + "form" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0b3e9de6-4170-4538-9e3b-d99d3ae2ceec", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gravity.get_forms()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "250b3874-8dcd-47d9-b321-41d767778bd9", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "sponsors = gravity.get_entries(form_id=2)\n", + "cards = gravity.get_entries(form_id=3)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "d6edf62e-0f57-4404-ba59-da841194bec1", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '20454',\n", + " 'form_id': '2',\n", + " 'created_by': '5757',\n", + " 'date_created': '2024-02-28 13:14:08',\n", + " 'date_updated': '2024-02-28 13:14:08',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'post_id': None,\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", + " 'status': 'active',\n", + " 'is_fulfilled': None,\n", + " 'details': {'date_updated': '2024-02-28 13:14:08',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'transaction_type': None,\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20447,20448,20449,20450,20451,20452,20453',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False}}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sponsors[0].__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "a184a4f1-c213-4f66-92a5-0a05b158fbf4", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '20453',\n", + " 'form_id': '3',\n", + " 'created_by': '5757',\n", + " 'date_created': '2024-02-28 13:13:19',\n", + " 'date_updated': '2024-02-28 13:13:19',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'post_id': None,\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", + " 'status': 'active',\n", + " 'is_fulfilled': None,\n", + " 'details': {'date_updated': '2024-02-28 13:13:19',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'transaction_type': None,\n", + " '2.3': 'Christina',\n", + " '2.6': 'Harvey',\n", + " '3': 'cnharvey48@gmail.com',\n", + " '4': '100038329',\n", + " 'gpnf_entry_parent': '20454',\n", + " 'gpnf_entry_parent_form': '2',\n", + " 'gpnf_entry_nested_form_field': '32',\n", + " '2.2': '',\n", + " '2.4': '',\n", + " '2.8': '',\n", + " '5': ''}}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cards[0].__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "58ab3076-2274-4fa8-9517-3baa3bc0053b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "sponsor = gravity.get_entry('20454')" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "198abbfe-6d57-414c-b1cd-e1004a14f4d6", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Got page: 1 of 200 results.\n", + "Got page: 2 of 200 results.\n", + "Got page: 3 of 200 results.\n", + "Got page: 4 of 200 results.\n", + "Got page: 5 of 200 results.\n", + "Got page: 6 of 200 results.\n", + "Got page: 7 of 200 results.\n", + "Got page: 8 of 200 results.\n", + "Got page: 9 of 200 results.\n", + "Got page: 10 of 200 results.\n", + "Got page: 11 of 200 results.\n", + "Got page: 12 of 200 results.\n", + "Got page: 13 of 200 results.\n", + "Got page: 14 of 200 results.\n", + "Got page: 15 of 200 results.\n", + "Got page: 16 of 200 results.\n", + "Got page: 17 of 200 results.\n", + "Got page: 18 of 200 results.\n", + "Got page: 19 of 200 results.\n", + "Got page: 20 of 200 results.\n", + "Got page: 21 of 200 results.\n", + "Got page: 22 of 200 results.\n", + "Got page: 23 of 200 results.\n", + "Got page: 24 of 200 results.\n", + "Got page: 25 of 200 results.\n", + "Got page: 26 of 200 results.\n", + "Got page: 27 of 200 results.\n", + "Got page: 28 of 200 results.\n", + "Got page: 29 of 200 results.\n", + "Got page: 30 of 200 results.\n", + "Got page: 31 of 200 results.\n", + "Got page: 32 of 200 results.\n", + "Got page: 33 of 200 results.\n", + "Got page: 34 of 200 results.\n", + "Got page: 35 of 200 results.\n", + "Got page: 36 of 200 results.\n", + "Got page: 37 of 200 results.\n", + "Got page: 38 of 200 results.\n", + "Got page: 39 of 200 results.\n", + "Got page: 40 of 200 results.\n", + "Got page: 41 of 200 results.\n", + "Got page: 42 of 200 results.\n", + "Got page: 43 of 200 results.\n", + "Got page: 44 of 200 results.\n", + "Got page: 45 of 200 results.\n", + "Got page: 46 of 200 results.\n", + "Got page: 47 of 200 results.\n", + "Got page: 48 of 200 results.\n", + "Got page: 49 of 200 results.\n", + "Got page: 50 of 200 results.\n", + "Got page: 51 of 200 results.\n", + "Got page: 52 of 150 results.\n", + "Got page: 53 of 0 results.\n", + "No more pages\n" + ] + } + ], + "source": [ + "count = 1\n", + "while True:\n", + " ents = gravity.get_entries(page=count, page_size=200, form_id=3)\n", + " print(f\"Got page: {count} of {len(ents)} results.\")\n", + " if not ents:\n", + " print(\"No more pages\")\n", + " break\n", + " count += 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff5e1405-3a4b-42c8-ba9a-7db99b7943b4", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 69038129229e8ad8d45b35ea879282b9d16e8a54 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 08:30:54 -0500 Subject: [PATCH 07/14] JMG Adds working search. Bumps pyodbc to new version --- notebooks/test_gravity_forms.ipynb | 612 ++++++++++++++++++++++++++++- pyproject.toml | 4 +- sat/gravity_forms.py | 23 +- 3 files changed, 626 insertions(+), 13 deletions(-) diff --git a/notebooks/test_gravity_forms.ipynb b/notebooks/test_gravity_forms.ipynb index 7d7e78f..7aa6c5b 100644 --- a/notebooks/test_gravity_forms.ipynb +++ b/notebooks/test_gravity_forms.ipynb @@ -26,7 +26,8 @@ "outputs": [], "source": [ "from urllib.parse import urlencode\n", - "from sat import gravity_forms" + "from sat import gravity_forms\n", + "import json" ] }, { @@ -50,14 +51,16 @@ }, "outputs": [ { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "ename": "TypeError", + "evalue": "sat.gravity_forms.Form() argument after ** must be a mapping, not str", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m form \u001b[38;5;241m=\u001b[39m \u001b[43mgravity\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_form\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m form\n", + "File \u001b[0;32m~/ncstate/projects/sat-utils/sat/gravity_forms.py:205\u001b[0m, in \u001b[0;36mGravityForms.get_form\u001b[0;34m(self, form_id)\u001b[0m\n\u001b[1;32m 198\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;124;03mGets and returns a form.\u001b[39;00m\n\u001b[1;32m 200\u001b[0m \n\u001b[1;32m 201\u001b[0m \u001b[38;5;124;03mParameters:\u001b[39;00m\n\u001b[1;32m 202\u001b[0m \u001b[38;5;124;03m- form_id: The ID of the form.\u001b[39;00m\n\u001b[1;32m 203\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 204\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/forms/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mform_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 205\u001b[0m entry \u001b[38;5;241m=\u001b[39m Form(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mresponse)\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m entry\n", + "\u001b[0;31mTypeError\u001b[0m: sat.gravity_forms.Form() argument after ** must be a mapping, not str" + ] } ], "source": [ @@ -321,10 +324,599 @@ " count += 1" ] }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f693a3cf-1b5d-46b3-bd1c-46af24722d4f", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "keys = [('23', 'kkmahl', '=')]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "a49d9930-2427-483b-8206-e1d84f683bcf", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '20454',\n", + " 'form_id': '2',\n", + " 'created_by': '5757',\n", + " 'date_created': '2024-02-28 13:14:08',\n", + " 'date_updated': '2024-02-28 13:14:08',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'post_id': None,\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", + " 'status': 'active',\n", + " 'is_fulfilled': None,\n", + " 'details': {'date_updated': '2024-02-28 13:14:08',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'transaction_type': None,\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20447,20448,20449,20450,20451,20452,20453',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False}}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "res = gravity.search_entry(keys=keys, form_id='2')\n", + "res[0].__dict__" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "4bc3461d-0f23-4a8a-a8ea-09add3c9c6c5", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "#res = 'https://onecard.ncsu.edu/wp-json/gf/v2/forms/2/entries?search={\"field_filters\": [{\"key\": \"23\", \"value\": \"kkmahl\", \"operator\": \"=\"}]}&'" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "b2c95d99-ffbb-4a61-9ab5-572f85f00683", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "resp = gravity.session.get(res)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "2cb60d9a-ed13-46af-8496-212bae49b18d", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'total_count': 121,\n", + " 'entries': [{'id': '20454',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-02-28 13:14:08',\n", + " 'date_updated': '2024-02-28 13:14:08',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20447,20448,20449,20450,20451,20452,20453',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '20341',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-02-21 14:28:04',\n", + " 'date_updated': '2024-02-21 14:28:04',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20338,20339,20340',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '20240',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-02-14 13:21:07',\n", + " 'date_updated': '2024-02-14 13:21:07',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20236,20237,20238,20239',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '20150',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-02-09 13:18:20',\n", + " 'date_updated': '2024-02-09 13:18:20',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20149',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '20099',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-02-07 13:50:28',\n", + " 'date_updated': '2024-02-07 13:50:28',\n", + " 'is_starred': '0',\n", + " 'is_read': '1',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20098',\n", + " '7': 'Corporate Partner',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'kkmahl@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '20033',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-01-31 13:27:21',\n", + " 'date_updated': '2024-01-31 13:27:21',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '20029,20030,20031,20032',\n", + " '7': 'Affiliate',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '19937',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-01-24 13:41:02',\n", + " 'date_updated': '2024-01-24 13:41:02',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '19927,19928,19929,19930,19931,19932,19933,19934,19935,19936',\n", + " '7': 'Affiliate',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '19813',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-01-17 16:22:49',\n", + " 'date_updated': '2024-01-17 16:22:49',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '19802,19803,19804,19805,19806,19807,19808,19809,19810,19811,19812',\n", + " '7': 'Affiliate',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '19746',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-01-10 13:05:46',\n", + " 'date_updated': '2024-01-10 13:05:46',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '19734,19735,19736,19737,19738,19739,19740,19741,19742,19743,19744,19745',\n", + " '7': 'Affiliate',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'olli_info@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False},\n", + " {'id': '19661',\n", + " 'form_id': '2',\n", + " 'post_id': None,\n", + " 'date_created': '2024-01-03 13:12:24',\n", + " 'date_updated': '2024-01-03 13:12:24',\n", + " 'is_starred': '0',\n", + " 'is_read': '0',\n", + " 'ip': '152.1.166.139',\n", + " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", + " 'currency': 'USD',\n", + " 'payment_status': None,\n", + " 'payment_date': None,\n", + " 'payment_amount': None,\n", + " 'payment_method': None,\n", + " 'transaction_id': None,\n", + " 'is_fulfilled': None,\n", + " 'created_by': '5757',\n", + " 'transaction_type': None,\n", + " 'status': 'active',\n", + " '22': 'Kimberly Mahl',\n", + " '23': 'kkmahl',\n", + " '21': 'kkmahl@ncsu.edu',\n", + " '32': '19654,19655,19656,19657,19658,19659,19660',\n", + " '7': 'Affiliate',\n", + " '16': 'Osher Lifelong Learning Institute',\n", + " '17': '(919) 515-5782',\n", + " '18': 'kkmahl@ncsu.edu',\n", + " '19': '',\n", + " '29': '',\n", + " '8': '',\n", + " '13': '',\n", + " '27': '',\n", + " '24': '',\n", + " '25': '',\n", + " '12': '',\n", + " '14': '',\n", + " '15': '',\n", + " '20': '',\n", + " '26': '',\n", + " '33': '',\n", + " '34': '',\n", + " '36': '',\n", + " 'gpnf_entry_parent': False,\n", + " 'gpnf_entry_parent_form': False,\n", + " 'gpnf_entry_nested_form_field': False}]}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "resp.json()" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "ff5e1405-3a4b-42c8-ba9a-7db99b7943b4", + "id": "732f2ba0-556e-4933-b9b2-23d15b07ab13", "metadata": {}, "outputs": [], "source": [] diff --git a/pyproject.toml b/pyproject.toml index d9671db..176c5f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "sat-utils" -version = "1.3.0" +version = "1.3.1" authors = [ { name="Ryan Semmler", email="rsemmle@ncsu.edu" }, { name="Shawn Taylor", email="staylor8@ncsu.edu" }, @@ -21,7 +21,7 @@ dependencies = [ "ldap3>=2.9.1, <3.0.0", "cx_Oracle==8.3.0", "oracledb==2.0.1", - "pyodbc>=5.0.1, <6.0.0", + "pyodbc==5.1.0", "requests_oauthlib==1.3.1" ] diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index a6bfa22..7d39abb 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -6,6 +6,7 @@ - CONSUMER_SECRET """ +import json import os from typing import Optional @@ -174,7 +175,6 @@ def get(self, endpoint: str, params: Optional[dict] = None): if params: for key, value in params.items(): param_string += f"{key}={value}&" - try: response = self.session.get(self.base_url + endpoint + param_string) return response.json() @@ -230,3 +230,24 @@ def get_entry(self, entry_id: int): response = self.get(f"/entries/{entry_id}") entry = Entry(**response) return entry + + def search_entry(self, keys: [tuple], form_id: int): + """ + keys: list of tuples (key, value, operator) + 'search={"field_filters": + [ + {"key":2,"value":"squiffy","operator":"contains"}, + {"key":1.3,"value":"squiffy","operator":"contains"} + ] + }' + """ + field_filters = {"field_filters": []} + for key, value, operator in keys: + inner_dict = {"key": key, "value": value, "operator": operator} + field_filters["field_filters"].append(inner_dict) + field_filters = json.dumps(field_filters) + response = self.get(f"/forms/{form_id}/entries", params={"search": field_filters}) + entries = [] + for entry in response["entries"]: + entries.append(Entry(**entry)) + return entries From 8cef312392c0944a5633134cd5d8f6f10a281fd9 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 09:53:45 -0500 Subject: [PATCH 08/14] JMG Add some tests --- sat/gravity_forms.py | 24 +++++++++++++++++------ tests/test_gravity_forms.py | 39 ++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index 7d39abb..de2632c 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -163,6 +163,22 @@ def __init__(self, **settings) -> None: signature_type=oauthlib.oauth1.SIGNATURE_TYPE_QUERY, ) + @staticmethod + def _field_filters(keys: [tuple]) -> str: + """ + keys: list of tuples (key, value, operator) + 'search={"field_filters": + [ + {"key":2,"value":"squiffy","operator":"contains"}, + {"key":1.3,"value":"squiffy","operator":"contains"} + ] + }' + """ + field_filters = [] + for key, value, operator in keys: + field_filters.append({"key": key, "value": value, "operator": operator}) + return json.dumps({"field_filters": field_filters}) + def get(self, endpoint: str, params: Optional[dict] = None): """ Submits a GET request to a specified endpoint. @@ -241,13 +257,9 @@ def search_entry(self, keys: [tuple], form_id: int): ] }' """ - field_filters = {"field_filters": []} - for key, value, operator in keys: - inner_dict = {"key": key, "value": value, "operator": operator} - field_filters["field_filters"].append(inner_dict) - field_filters = json.dumps(field_filters) + field_filters = self._field_filters(keys) response = self.get(f"/forms/{form_id}/entries", params={"search": field_filters}) entries = [] - for entry in response["entries"]: + for entry in response.get("entries"): entries.append(Entry(**entry)) return entries diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index 891131b..9ebc08e 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -1,18 +1,28 @@ +import os +from unittest import mock from unittest.mock import patch +import pytest from requests.exceptions import RequestException from sat.gravity_forms import Entry, Form, GravityForms -def test_environment_variable_error(): - try: - gravity_forms = GravityForms() - gravity_forms.get( - "/forms/2/entries", params={"paging[current_page]": 1, "paging[page_size]": 5} - ) - assert False - except ValueError: - assert True +@mock.patch.dict(os.environ, {"GRAVITY_FORMS_CONSUMER_KEY": ""}) +def test_environment_variable_error_key(): + with pytest.raises(ValueError): + GravityForms() + + +@mock.patch.dict(os.environ, {"GRAVITY_FORMS_CONSUMER_SECRET": ""}) +def test_environment_variable_error_secret(): + with pytest.raises(ValueError): + GravityForms() + + +@mock.patch.dict(os.environ, {"GRAVITY_FORMS_BASE_URL": ""}) +def test_environment_variable_error_base_url(): + with pytest.raises(ValueError): + GravityForms() def test_request_exception_get(): @@ -82,6 +92,17 @@ def test_get_entry_exception(): assert str(e) == "Simulated request exception." +def test_field_filter_construct(caplog): + expected_filter = ( + '{"field_filters": [{"key": "search_string", "value": "search_field", "operator": "="}]}' + ) + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + result = gravity_forms._field_filters([("search_string", "search_field", "=")]) + assert expected_filter in result + + def test_create_form_model(): form_data = { "id": "1", From a082fe59d157e17b4bf02251070f9ca767f619fd Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 10:00:41 -0500 Subject: [PATCH 09/14] JMG small refactor --- notebooks/test_gravity_forms.ipynb | 500 +---------------------------- sat/gravity_forms.py | 16 +- tests/test_gravity_forms.py | 2 +- 3 files changed, 19 insertions(+), 499 deletions(-) diff --git a/notebooks/test_gravity_forms.ipynb b/notebooks/test_gravity_forms.ipynb index 7aa6c5b..0109807 100644 --- a/notebooks/test_gravity_forms.ipynb +++ b/notebooks/test_gravity_forms.ipynb @@ -338,7 +338,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "a49d9930-2427-483b-8206-e1d84f683bcf", "metadata": { "tags": [] @@ -347,20 +347,20 @@ { "data": { "text/plain": [ - "{'id': '20454',\n", + "{'id': '20150',\n", " 'form_id': '2',\n", " 'created_by': '5757',\n", - " 'date_created': '2024-02-28 13:14:08',\n", - " 'date_updated': '2024-02-28 13:14:08',\n", + " 'date_created': '2024-02-09 13:18:20',\n", + " 'date_updated': '2024-02-09 13:18:20',\n", " 'is_starred': '0',\n", " 'is_read': '0',\n", " 'ip': '152.1.166.139',\n", " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", " 'post_id': None,\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", + " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", " 'status': 'active',\n", " 'is_fulfilled': None,\n", - " 'details': {'date_updated': '2024-02-28 13:14:08',\n", + " 'details': {'date_updated': '2024-02-09 13:18:20',\n", " 'currency': 'USD',\n", " 'payment_status': None,\n", " 'payment_date': None,\n", @@ -371,7 +371,7 @@ " '22': 'Kimberly Mahl',\n", " '23': 'kkmahl',\n", " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20447,20448,20449,20450,20451,20452,20453',\n", + " '32': '20149',\n", " '7': 'Corporate Partner',\n", " '16': 'Osher Lifelong Learning Institute',\n", " '17': '(919) 515-5782',\n", @@ -396,14 +396,15 @@ " 'gpnf_entry_nested_form_field': False}}" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "res = gravity.search_entry(keys=keys, form_id='2')\n", - "res[0].__dict__" + "filters = gravity.field_filters(keys)\n", + "res = gravity.search_entry(field_filters=filters, form_id='2')\n", + "res[3].__dict__" ] }, { @@ -432,486 +433,13 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "2cb60d9a-ed13-46af-8496-212bae49b18d", "metadata": { "tags": [] }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'total_count': 121,\n", - " 'entries': [{'id': '20454',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-02-28 13:14:08',\n", - " 'date_updated': '2024-02-28 13:14:08',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20447,20448,20449,20450,20451,20452,20453',\n", - " '7': 'Corporate Partner',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '20341',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-02-21 14:28:04',\n", - " 'date_updated': '2024-02-21 14:28:04',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20338,20339,20340',\n", - " '7': 'Corporate Partner',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '20240',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-02-14 13:21:07',\n", - " 'date_updated': '2024-02-14 13:21:07',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20236,20237,20238,20239',\n", - " '7': 'Corporate Partner',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '20150',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-02-09 13:18:20',\n", - " 'date_updated': '2024-02-09 13:18:20',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20149',\n", - " '7': 'Corporate Partner',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '20099',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-02-07 13:50:28',\n", - " 'date_updated': '2024-02-07 13:50:28',\n", - " 'is_starred': '0',\n", - " 'is_read': '1',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20098',\n", - " '7': 'Corporate Partner',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'kkmahl@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '20033',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-01-31 13:27:21',\n", - " 'date_updated': '2024-01-31 13:27:21',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '20029,20030,20031,20032',\n", - " '7': 'Affiliate',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '19937',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-01-24 13:41:02',\n", - " 'date_updated': '2024-01-24 13:41:02',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '19927,19928,19929,19930,19931,19932,19933,19934,19935,19936',\n", - " '7': 'Affiliate',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '19813',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-01-17 16:22:49',\n", - " 'date_updated': '2024-01-17 16:22:49',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '19802,19803,19804,19805,19806,19807,19808,19809,19810,19811,19812',\n", - " '7': 'Affiliate',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '19746',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-01-10 13:05:46',\n", - " 'date_updated': '2024-01-10 13:05:46',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '19734,19735,19736,19737,19738,19739,19740,19741,19742,19743,19744,19745',\n", - " '7': 'Affiliate',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'olli_info@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False},\n", - " {'id': '19661',\n", - " 'form_id': '2',\n", - " 'post_id': None,\n", - " 'date_created': '2024-01-03 13:12:24',\n", - " 'date_updated': '2024-01-03 13:12:24',\n", - " 'is_starred': '0',\n", - " 'is_read': '0',\n", - " 'ip': '152.1.166.139',\n", - " 'source_url': 'https://onecard.ncsu.edu/get-card/card-request-form/',\n", - " 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',\n", - " 'currency': 'USD',\n", - " 'payment_status': None,\n", - " 'payment_date': None,\n", - " 'payment_amount': None,\n", - " 'payment_method': None,\n", - " 'transaction_id': None,\n", - " 'is_fulfilled': None,\n", - " 'created_by': '5757',\n", - " 'transaction_type': None,\n", - " 'status': 'active',\n", - " '22': 'Kimberly Mahl',\n", - " '23': 'kkmahl',\n", - " '21': 'kkmahl@ncsu.edu',\n", - " '32': '19654,19655,19656,19657,19658,19659,19660',\n", - " '7': 'Affiliate',\n", - " '16': 'Osher Lifelong Learning Institute',\n", - " '17': '(919) 515-5782',\n", - " '18': 'kkmahl@ncsu.edu',\n", - " '19': '',\n", - " '29': '',\n", - " '8': '',\n", - " '13': '',\n", - " '27': '',\n", - " '24': '',\n", - " '25': '',\n", - " '12': '',\n", - " '14': '',\n", - " '15': '',\n", - " '20': '',\n", - " '26': '',\n", - " '33': '',\n", - " '34': '',\n", - " '36': '',\n", - " 'gpnf_entry_parent': False,\n", - " 'gpnf_entry_parent_form': False,\n", - " 'gpnf_entry_nested_form_field': False}]}" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "resp.json()" - ] + "outputs": [], + "source": [] }, { "cell_type": "code", diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index de2632c..16c4bf4 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -164,8 +164,10 @@ def __init__(self, **settings) -> None: ) @staticmethod - def _field_filters(keys: [tuple]) -> str: + def field_filters(keys: [tuple]) -> str: """ + Generates the appropriate JSON string for the field_filters parameter. + keys: list of tuples (key, value, operator) 'search={"field_filters": [ @@ -247,17 +249,7 @@ def get_entry(self, entry_id: int): entry = Entry(**response) return entry - def search_entry(self, keys: [tuple], form_id: int): - """ - keys: list of tuples (key, value, operator) - 'search={"field_filters": - [ - {"key":2,"value":"squiffy","operator":"contains"}, - {"key":1.3,"value":"squiffy","operator":"contains"} - ] - }' - """ - field_filters = self._field_filters(keys) + def search_entry(self, field_filters: str, form_id: int): response = self.get(f"/forms/{form_id}/entries", params={"search": field_filters}) entries = [] for entry in response.get("entries"): diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index 9ebc08e..5e3e03e 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -99,7 +99,7 @@ def test_field_filter_construct(caplog): gravity_forms = GravityForms( consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" ) - result = gravity_forms._field_filters([("search_string", "search_field", "=")]) + result = gravity_forms.field_filters([("search_string", "search_field", "=")]) assert expected_filter in result From 6193be66b0a0302c881d36d50dc66e3b0eaa4d73 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 10:07:02 -0500 Subject: [PATCH 10/14] JMG Adds one more test --- tests/test_gravity_forms.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index 5e3e03e..c3f20a4 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -92,7 +92,7 @@ def test_get_entry_exception(): assert str(e) == "Simulated request exception." -def test_field_filter_construct(caplog): +def test_field_filter_construct(): expected_filter = ( '{"field_filters": [{"key": "search_string", "value": "search_field", "operator": "="}]}' ) @@ -103,6 +103,20 @@ def test_field_filter_construct(caplog): assert expected_filter in result +def test_more_than_one_field_filter_construct(): + expected_filter = ( + '{"field_filters": [{"key": "search_string", "value": "search_field", "operator": "="},' + ' {"key": "search_string1", "value": "search_field1", "operator": "contains"}]}' + ) + gravity_forms = GravityForms( + consumer_key="your_key", consumer_secret="your_secret", base_url="https://baseurl.edu" + ) + result = gravity_forms.field_filters( + [("search_string", "search_field", "="), ("search_string1", "search_field1", "contains")] + ) + assert expected_filter in result + + def test_create_form_model(): form_data = { "id": "1", From d5bd6833be97d4130fe64e6e2a34063a96d94798 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 11:10:49 -0500 Subject: [PATCH 11/14] JMG Fix tests --- sat/gravity_forms.py | 1 - tests/test_gravity_forms.py | 27 ++++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index 16c4bf4..31b9857 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -141,7 +141,6 @@ def __init__(self, **settings) -> None: ) self.base_url = settings.get("base_url", os.getenv("GRAVITY_FORMS_BASE_URL")) self.page_size = settings.get("page_size", self.page_size) - if not consumer_key: raise ValueError( "A consumer_key is required as either an environment variable or parameter." diff --git a/tests/test_gravity_forms.py b/tests/test_gravity_forms.py index c3f20a4..b597858 100644 --- a/tests/test_gravity_forms.py +++ b/tests/test_gravity_forms.py @@ -7,19 +7,40 @@ from sat.gravity_forms import Entry, Form, GravityForms -@mock.patch.dict(os.environ, {"GRAVITY_FORMS_CONSUMER_KEY": ""}) +@mock.patch.dict( + os.environ, + { + "GRAVITY_FORMS_CONSUMER_KEY": "", + "GRAVITY_FORMS_CONSUMER_SECRET": "secret", + "GRAVITY_FORMS_BASE_URL": "https://baseurl.edu", + }, +) def test_environment_variable_error_key(): with pytest.raises(ValueError): GravityForms() -@mock.patch.dict(os.environ, {"GRAVITY_FORMS_CONSUMER_SECRET": ""}) +@mock.patch.dict( + os.environ, + { + "GRAVITY_FORMS_CONSUMER_KEY": "your_key", + "GRAVITY_FORMS_CONSUMER_SECRET": "", + "GRAVITY_FORMS_BASE_URL": "https://baseurl.edu", + }, +) def test_environment_variable_error_secret(): with pytest.raises(ValueError): GravityForms() -@mock.patch.dict(os.environ, {"GRAVITY_FORMS_BASE_URL": ""}) +@mock.patch.dict( + os.environ, + { + "GRAVITY_FORMS_CONSUMER_KEY": "your_key", + "GRAVITY_FORMS_CONSUMER_SECRET": "your_secret", + "GRAVITY_FORMS_BASE_URL": "", + }, +) def test_environment_variable_error_base_url(): with pytest.raises(ValueError): GravityForms() From 48366d66c0c0a93593ee826373cc2350dfd9ea52 Mon Sep 17 00:00:00 2001 From: Jeremy Gibson Date: Thu, 29 Feb 2024 11:13:25 -0500 Subject: [PATCH 12/14] JMG Update the error handling code. --- sat/gravity_forms.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index 31b9857..3ceedf8 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -141,19 +141,11 @@ def __init__(self, **settings) -> None: ) self.base_url = settings.get("base_url", os.getenv("GRAVITY_FORMS_BASE_URL")) self.page_size = settings.get("page_size", self.page_size) - if not consumer_key: - raise ValueError( - "A consumer_key is required as either an environment variable or parameter." - ) - - if not consumer_secret: - raise ValueError( - "A consumer_secret is required as either an environment variable or parameter." - ) - if not self.base_url: + if not all([consumer_key, consumer_secret, self.base_url]): raise ValueError( - "A base_url is required as either an environment variable or parameter." + "A consumer_key, consumer_secret, and base_url are required as either environment " + "variables or parameters." ) self.session = OAuth1Session( From 3b01f50667083bc356f3e222ae09a43121ebd327 Mon Sep 17 00:00:00 2001 From: John Champion Date: Fri, 1 Mar 2024 10:11:24 -0500 Subject: [PATCH 13/14] expand data type for id --- sat/gravity_forms.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index 3ceedf8..f111ef7 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -8,7 +8,7 @@ import json import os -from typing import Optional +from typing import Optional, Union import oauthlib from requests.exceptions import RequestException @@ -24,7 +24,7 @@ class Form: A form object from GravityForms. """ - id: str + id: Union[int, str] title: str description: str date_created: str @@ -65,7 +65,7 @@ class Entry: An entry object from GravityForms. """ - id: str + id: Union[int, str] form_id: str created_by: str date_created: str From 665bb2cb38e2dbb0b375ad6f66835966537479b4 Mon Sep 17 00:00:00 2001 From: John Champion Date: Fri, 1 Mar 2024 10:15:51 -0500 Subject: [PATCH 14/14] change parameter data type --- sat/gravity_forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sat/gravity_forms.py b/sat/gravity_forms.py index f111ef7..5f8eee2 100644 --- a/sat/gravity_forms.py +++ b/sat/gravity_forms.py @@ -213,7 +213,7 @@ def get_form(self, form_id: int): entry = Form(**response) return entry - def get_entries(self, page: int = 1, page_size: int = 20, form_id: Optional[str] = None): + def get_entries(self, page: int = 1, page_size: int = 20, form_id: Optional[int] = None): """ Gets and returns a list of entries. """