From 79fae904bffbe795a6ca6b86954813afb8495472 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 10:55:05 +0530 Subject: [PATCH 01/16] test: Add unit tests for start and end of day epoch functions --- .../payment_integration_utils/tests/test_utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 payment_integration_utils/payment_integration_utils/tests/test_utils.py diff --git a/payment_integration_utils/payment_integration_utils/tests/test_utils.py b/payment_integration_utils/payment_integration_utils/tests/test_utils.py new file mode 100644 index 0000000..b50f791 --- /dev/null +++ b/payment_integration_utils/payment_integration_utils/tests/test_utils.py @@ -0,0 +1,11 @@ +from frappe.tests.utils import FrappeTestCase + +from payment_integration_utils.payment_integration_utils.utils import * + + +class TestUtils(FrappeTestCase): + def test_start_of_day_epoch(self): + self.assertEqual(get_start_of_day_epoch("2024-05-30"), 1717007400) + + def test_end_of_day_epoch(self): + self.assertEqual(get_end_of_day_epoch("2024-05-30"), 1717093799) From ae145ee60b0263d75dbd16333edb6dcdfbf8d656 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 11:31:41 +0530 Subject: [PATCH 02/16] ci: Add test github workflow --- .github/helper/install.sh | 75 ++++++++++++++ .github/helper/site_config.json | 17 ++++ .github/workflows/server-tests.yml | 153 +++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 .github/helper/install.sh create mode 100644 .github/helper/site_config.json create mode 100644 .github/workflows/server-tests.yml diff --git a/.github/helper/install.sh b/.github/helper/install.sh new file mode 100644 index 0000000..d6aae0c --- /dev/null +++ b/.github/helper/install.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +set -e + +# Check for merge conflicts before proceeding +python -m compileall -f "${GITHUB_WORKSPACE}" +if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}" + then echo "Found merge conflicts" + exit 1 +fi + +cd ~ || exit + +echo "Setting Up System Dependencies..." + +sudo apt update + +sudo apt remove mysql-server mysql-client +sudo apt install libcups2-dev redis-server mariadb-client-10.6 + +install_whktml() { + if [ "$(lsb_release -rs)" = "22.04" ]; then + wget -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb + sudo apt install /tmp/wkhtmltox.deb + else + echo "Please update this script to support wkhtmltopdf for $(lsb_release -ds)" + exit 1 + fi +} +install_whktml & +wkpid=$! + +pip install frappe-bench + +git clone "https://github.com/frappe/frappe" --branch "${FRAPPE_BRANCH}" --depth 1 +bench init --skip-assets --frappe-path ~/frappe --python "$(which python)" frappe-bench + +mkdir ~/frappe-bench/sites/test_site + +cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config.json" ~/frappe-bench/sites/test_site/ + +# Update MySQL/MariaDB credentials +mariadb --host 127.0.0.1 --port 3306 -u root -ppassword -e " +SET GLOBAL character_set_server = 'utf8mb4'; +SET GLOBAL collation_server = 'utf8mb4_unicode_ci'; + +CREATE USER 'test_resilient'@'localhost' IDENTIFIED BY 'test_resilient'; +CREATE DATABASE test_resilient; +GRANT ALL PRIVILEGES ON \`test_resilient\`.* TO 'test_resilient'@'localhost'; + +FLUSH PRIVILEGES; +" + +cd ~/frappe-bench || exit + +sed -i 's/watch:/# watch:/g' Procfile +sed -i 's/schedule:/# schedule:/g' Procfile +sed -i 's/socketio:/# socketio:/g' Procfile +sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile + +bench get-app erpnext --branch "${ERPNEXT_BRANCH}" --resolve-deps + +# Install the app using SSH +bench get-app "git@github.com:${GITHUB_REPOSITORY}.git" --branch "${PR_BRANCH}" + +bench setup requirements --dev + +wait $wkpid + +bench use test_site +bench start & +bench reinstall --yes + +bench install-app "${APP_NAME}" +bench --site test_site add-to-hosts diff --git a/.github/helper/site_config.json b/.github/helper/site_config.json new file mode 100644 index 0000000..7c17d59 --- /dev/null +++ b/.github/helper/site_config.json @@ -0,0 +1,17 @@ +{ + "db_host": "127.0.0.1", + "db_port": 3306, + "db_name": "test_frappe", + "db_password": "test_frappe", + "db_type": "mariadb", + "auto_email_id": "test@example.com", + "mail_server": "smtp.example.com", + "mail_login": "test@example.com", + "mail_password": "test", + "admin_password": "admin", + "root_login": "root", + "root_password": "password", + "host_name": "http://test_site:8000", + "install_apps": ["erpnext"], + "throttle_user_limit": 100 +} diff --git a/.github/workflows/server-tests.yml b/.github/workflows/server-tests.yml new file mode 100644 index 0000000..983fd60 --- /dev/null +++ b/.github/workflows/server-tests.yml @@ -0,0 +1,153 @@ +name: Server Tests + +on: + workflow_call: + inputs: + base_ref: + type: string + + app_name: + type: string + + pull_request: + paths-ignore: + - "**.css" + - "**.js" + - "**.md" + - "**.html" + - "**.csv" + + push: + branches: [develop, "version-15"] + paths-ignore: + - "**.css" + - "**.js" + - "**.md" + - "**.html" + - "**.csv" + +env: + FRAPPE_BRANCH: "version-15" + ERPNEXT_BRANCH: "version-15" + APP_NAME: ${{ inputs.app_name || 'payment_integration_utils' }} + +# TODO: Update installation process when the app get published and remove SSH configuration +jobs: + tests: + runs-on: ubuntu-latest + timeout-minutes: 20 + + strategy: + fail-fast: false + matrix: + type: [server] + + name: Python Unit Tests + + services: + mariadb: + image: mariadb:10.6 + env: + MARIADB_ROOT_PASSWORD: "password" + ports: + - 3306:3306 + options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + + steps: + - name: Clone + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + check-latest: true + + - name: Add to Hosts + run: echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts + + - name: Cache pip + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + + - name: Cache node modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v4 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Setup SSH + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Installing Apps + run: | + bash ${GITHUB_WORKSPACE}/.github/helper/install.sh + env: + FRAPPE_BRANCH: ${{ env.FRAPPE_BRANCH }} + ERPNEXT_BRANCH: ${{ env.ERPNEXT_BRANCH }} + APP_NAME: ${{ env.APP_NAME }} + GITHUB_REPOSITORY: ${{ github.repository }} + PR_BRANCH: ${{ github.head_ref }} + + - name: Run Tests + run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app ${{ env.APP_NAME }} --with-coverage + env: + TYPE: server + + - name: Show bench output + if: ${{ always() }} + run: cat ~/frappe-bench/bench_start.log || true + + + # coverage: + # name: Coverage Wrap Up + # env: + # CODECOV_TOKEN: ${{ secrets.codecov_token || secrets.CODECOV_TOKEN }} + # needs: tests + # runs-on: ubuntu-latest + # steps: + # - name: Clone + # uses: actions/checkout@v4 + + # - name: Download artifacts + # uses: actions/download-artifact@v4 + + # - name: Upload coverage data + # if: github.event.repository.name == 'india-compliance' || env.CODECOV_TOKEN != '' + # uses: codecov/codecov-action@v4 + # env: + # CODECOV_TOKEN: ${{ env.CODECOV_TOKEN }} + # with: + # name: MariaDB + # fail_ci_if_error: true + # verbose: true From 2b636c572d131426faaaf218b46282ec1df205c1 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 11:57:48 +0530 Subject: [PATCH 03/16] fix: Simplify installation script for wkhtmltopdf and remove unnecessary checks --- .github/helper/install.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index d6aae0c..2bd468b 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -16,16 +16,11 @@ echo "Setting Up System Dependencies..." sudo apt update sudo apt remove mysql-server mysql-client -sudo apt install libcups2-dev redis-server mariadb-client-10.6 +sudo apt install libcups2-dev redis-server mariadb-client install_whktml() { - if [ "$(lsb_release -rs)" = "22.04" ]; then - wget -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb - sudo apt install /tmp/wkhtmltox.deb - else - echo "Please update this script to support wkhtmltopdf for $(lsb_release -ds)" - exit 1 - fi + wget -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb + sudo apt install /tmp/wkhtmltox.deb } install_whktml & wkpid=$! From 461df2a4ca408dc10240b8e4e00f2b5f753df027 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 12:05:56 +0530 Subject: [PATCH 04/16] test: Add initial test suite for payment integration utilities --- payment_integration_utils/tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 payment_integration_utils/tests/__init__.py diff --git a/payment_integration_utils/tests/__init__.py b/payment_integration_utils/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 829a710f357d26e95ab360948d8abc3a788716f3 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 13:27:06 +0530 Subject: [PATCH 05/16] fix: Improve currency conversion functions for precision and clarity --- .../payment_integration_utils/utils/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/payment_integration_utils/payment_integration_utils/utils/__init__.py b/payment_integration_utils/payment_integration_utils/utils/__init__.py index fcaf4c9..00748fc 100644 --- a/payment_integration_utils/payment_integration_utils/utils/__init__.py +++ b/payment_integration_utils/payment_integration_utils/utils/__init__.py @@ -3,12 +3,7 @@ import frappe from frappe import _ -from frappe.utils import ( - DateTimeLikeObject, - add_to_date, - get_timestamp, - getdate, -) +from frappe.utils import DateTimeLikeObject, add_to_date, flt, get_timestamp, getdate from payment_integration_utils.constants import SECONDS_IN_A_DAY @@ -89,13 +84,15 @@ def rupees_to_paisa(amount: float | int) -> int: Convert the given amount in Rupees to Paisa. :param amount: The amount in Rupees to be converted to Paisa. - Example: ``` rupees_to_paisa(100) ==> 10000 + rupees_to_paisa(79.899) ==> 7990 + rupees_to_paisa(79.9) ==> 7990 + ``` """ - return int(amount * 100) + return int(flt(amount, 2) * 100) def paisa_to_rupees(amount: int) -> int | float: @@ -107,9 +104,10 @@ def paisa_to_rupees(amount: int) -> int | float: Example: ``` paisa_to_rupees(10000) ==> 100 + paisa_to_rupees(7990) ==> 79.9 ``` """ - return amount / 100 + return flt(amount / 100, 2) ################# HTML RELATED ################# From f0f0409dcadbff173c59bd45b591eb57079eaf15 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 13:27:15 +0530 Subject: [PATCH 06/16] test: Add unit tests for currency conversion functions --- .../tests/test_utils.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/payment_integration_utils/payment_integration_utils/tests/test_utils.py b/payment_integration_utils/payment_integration_utils/tests/test_utils.py index b50f791..bd9005a 100644 --- a/payment_integration_utils/payment_integration_utils/tests/test_utils.py +++ b/payment_integration_utils/payment_integration_utils/tests/test_utils.py @@ -4,8 +4,16 @@ class TestUtils(FrappeTestCase): - def test_start_of_day_epoch(self): - self.assertEqual(get_start_of_day_epoch("2024-05-30"), 1717007400) - - def test_end_of_day_epoch(self): - self.assertEqual(get_end_of_day_epoch("2024-05-30"), 1717093799) + def test_conversion(self): + # (100, 10000) => 100 Rupees = 10000 Paisa + data = [ + (100, 10000), + (100.0, 10000), + (100.5, 10050), + (0.5, 50), + (79.9, 7990), + (0, 0), + ] + for rupees, paisa in data: + self.assertEqual(rupees_to_paisa(rupees), paisa) + self.assertEqual(paisa_to_rupees(paisa), rupees) From 8df109df9ded9126ef829c7dcbfb341a3daa3e2b Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 15:25:47 +0530 Subject: [PATCH 07/16] test: Add unit tests for to_hyphenated function --- .../payment_integration_utils/tests/test_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/payment_integration_utils/payment_integration_utils/tests/test_utils.py b/payment_integration_utils/payment_integration_utils/tests/test_utils.py index bd9005a..e64fb4a 100644 --- a/payment_integration_utils/payment_integration_utils/tests/test_utils.py +++ b/payment_integration_utils/payment_integration_utils/tests/test_utils.py @@ -17,3 +17,7 @@ def test_conversion(self): for rupees, paisa in data: self.assertEqual(rupees_to_paisa(rupees), paisa) self.assertEqual(paisa_to_rupees(paisa), rupees) + + def test_to_hyphenated(self): + self.assertEqual(to_hyphenated("Hello World"), "Hello-World") + self.assertEqual(to_hyphenated("Hello World!"), "Hello-World-") From 3a84ae3877e6f8d112b6c9ccdcb14d73a2840dcc Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 15:32:35 +0530 Subject: [PATCH 08/16] test: Add initial test files for authentication, payment entry, and validation utilities --- .../payment_integration_utils/tests/test_auth.py | 1 + .../payment_integration_utils/tests/test_payment_entry.py | 1 + .../payment_integration_utils/tests/test_validation.py | 1 + 3 files changed, 3 insertions(+) create mode 100644 payment_integration_utils/payment_integration_utils/tests/test_auth.py create mode 100644 payment_integration_utils/payment_integration_utils/tests/test_payment_entry.py create mode 100644 payment_integration_utils/payment_integration_utils/tests/test_validation.py diff --git a/payment_integration_utils/payment_integration_utils/tests/test_auth.py b/payment_integration_utils/payment_integration_utils/tests/test_auth.py new file mode 100644 index 0000000..444ac39 --- /dev/null +++ b/payment_integration_utils/payment_integration_utils/tests/test_auth.py @@ -0,0 +1 @@ +# TODO: test : payment_integration_utils/payment_integration_utils/utils/auth.py diff --git a/payment_integration_utils/payment_integration_utils/tests/test_payment_entry.py b/payment_integration_utils/payment_integration_utils/tests/test_payment_entry.py new file mode 100644 index 0000000..04baf5d --- /dev/null +++ b/payment_integration_utils/payment_integration_utils/tests/test_payment_entry.py @@ -0,0 +1 @@ +# TODO: test: payment_integration_utils/payment_integration_utils/server_overrides/doctype/payment_entry.py diff --git a/payment_integration_utils/payment_integration_utils/tests/test_validation.py b/payment_integration_utils/payment_integration_utils/tests/test_validation.py new file mode 100644 index 0000000..f3fa584 --- /dev/null +++ b/payment_integration_utils/payment_integration_utils/tests/test_validation.py @@ -0,0 +1 @@ +# TODO: test: payment_integration_utils/payment_integration_utils/utils/validation.py From cc7462fe7591fbb404c2e7d8a406800f74f4be37 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 15:43:29 +0530 Subject: [PATCH 09/16] test: Refactor imports in test_utils.py for clarity and organization --- .../payment_integration_utils/tests/test_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/payment_integration_utils/payment_integration_utils/tests/test_utils.py b/payment_integration_utils/payment_integration_utils/tests/test_utils.py index e64fb4a..c1f8af1 100644 --- a/payment_integration_utils/payment_integration_utils/tests/test_utils.py +++ b/payment_integration_utils/payment_integration_utils/tests/test_utils.py @@ -1,6 +1,10 @@ from frappe.tests.utils import FrappeTestCase -from payment_integration_utils.payment_integration_utils.utils import * +from payment_integration_utils.payment_integration_utils.utils import ( + paisa_to_rupees, + rupees_to_paisa, + to_hyphenated, +) class TestUtils(FrappeTestCase): From 2a477be58cc0199691ec3cfd50795391bbbd21af Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Tue, 25 Feb 2025 19:12:15 +0530 Subject: [PATCH 10/16] test: Add unit tests for validation functions including IFSC code and payment mode --- .../tests/test_validation.py | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/payment_integration_utils/payment_integration_utils/tests/test_validation.py b/payment_integration_utils/payment_integration_utils/tests/test_validation.py index f3fa584..b10be85 100644 --- a/payment_integration_utils/payment_integration_utils/tests/test_validation.py +++ b/payment_integration_utils/payment_integration_utils/tests/test_validation.py @@ -1 +1,52 @@ -# TODO: test: payment_integration_utils/payment_integration_utils/utils/validation.py +import re +from unittest.mock import patch + +import frappe +from frappe.tests.utils import FrappeTestCase + +from payment_integration_utils.payment_integration_utils.utils.validation import ( + validate_ifsc_code, + validate_payment_mode, +) + + +class TestUtils(FrappeTestCase): + @patch("requests.get") + def test_ifsc_code(self, mock_get): + IN_VALID_CODE = "SBK0000001" + + # Mock a failed response + mock_get.return_value.status_code = 404 + self.assertFalse(validate_ifsc_code(IN_VALID_CODE)) + + # Mock a successful response + mock_get.return_value.status_code = 200 + self.assertTrue(validate_ifsc_code("HDFC0000314")) + + # Test throwing an exception + mock_get.return_value.status_code = 404 + self.assertRaisesRegex( + frappe.exceptions.ValidationError, + re.compile(rf"Invalid IFSC Code:.*{IN_VALID_CODE}.*"), + validate_ifsc_code, + IN_VALID_CODE, + throw=True, + ) + + def test_payment_mode(self): + valid_modes = ["NEFT", "IMPS", "RTGS", "UPI", "Link"] + + for mode in valid_modes: + self.assertTrue(validate_payment_mode(mode)) + + IN_VALID_MODE = "Crypto" + self.assertFalse(validate_payment_mode(IN_VALID_MODE)) + + # Test throwing an exception + self.assertRaisesRegex( + frappe.exceptions.ValidationError, + re.compile(r"Invalid Payment Mode:.* Must be one of:.*"), + validate_payment_mode, + IN_VALID_MODE, + throw=True, + ) From b3682dbefd2e680d291422f0867c2ba94e55c94b Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 27 Feb 2025 10:21:41 +0530 Subject: [PATCH 11/16] fix: Improve condition check for custom fields in delete_custom_fields function --- .../payment_integration_utils/setup/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payment_integration_utils/payment_integration_utils/setup/__init__.py b/payment_integration_utils/payment_integration_utils/setup/__init__.py index 2f6cd87..7b0ece2 100644 --- a/payment_integration_utils/payment_integration_utils/setup/__init__.py +++ b/payment_integration_utils/payment_integration_utils/setup/__init__.py @@ -208,7 +208,7 @@ def delete_custom_fields(custom_fields: dict): for doctype, fields in custom_fields.items(): fieldnames = [] - if isinstance(fields, list) and fields: + if fields and isinstance(fields, list): if isinstance(fields[0], str): fieldnames = fields elif isinstance(fields[0], dict): From af4c25376e406fd7161aaec17072edf2f00f8153 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 27 Feb 2025 10:30:41 +0530 Subject: [PATCH 12/16] refactor: Remove unused custom field 'is_auto_generated' from CUSTOM_FIELDS --- .../constants/custom_fields.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/payment_integration_utils/payment_integration_utils/constants/custom_fields.py b/payment_integration_utils/payment_integration_utils/constants/custom_fields.py index b6ea667..16e54cf 100644 --- a/payment_integration_utils/payment_integration_utils/constants/custom_fields.py +++ b/payment_integration_utils/payment_integration_utils/constants/custom_fields.py @@ -136,21 +136,11 @@ "print_hide": 1, "permlevel": PERMISSION_LEVEL.SEVEN.value, }, - { - "fieldname": "is_auto_generated", - "label": "Is Auto Generated", - "fieldtype": "Check", - "insert_after": "online_payment_meta_data_section", - "hidden": 1, - "print_hide": 1, - "permlevel": PERMISSION_LEVEL.SEVEN.value, - "no_copy": 1, - }, { "fieldname": "payment_authorized_by", "label": "Payment Authorized By", "fieldtype": "Data", - "insert_after": "is_auto_generated", + "insert_after": "online_payment_meta_data_section", "options": "Email", "description": "User who made the payment", "hidden": 1, From a41790878e41aa0c0ab714cabf6d21d286e9f9b0 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 27 Feb 2025 10:50:39 +0530 Subject: [PATCH 13/16] refactor: deleting `is_auto_generated` custom fields --- payment_integration_utils/patches.txt | 3 ++- .../patches/delete_old_custom_fields.py | 9 +++++++++ .../patches/delete_old_property_setters.py | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 payment_integration_utils/patches/delete_old_custom_fields.py create mode 100644 payment_integration_utils/patches/delete_old_property_setters.py diff --git a/payment_integration_utils/patches.txt b/payment_integration_utils/patches.txt index f15c3a9..daafed8 100644 --- a/payment_integration_utils/patches.txt +++ b/payment_integration_utils/patches.txt @@ -3,4 +3,5 @@ # Read docs to understand patches: https://frappeframework.com/docs/v14/user/en/database-migrations [post_model_sync] -# Patches added in this section will be executed after doctypes are migrated \ No newline at end of file +# Patches added in this section will be executed after doctypes are migrated +payment_integration_utils.patches.delete_old_custom_fields \ No newline at end of file diff --git a/payment_integration_utils/patches/delete_old_custom_fields.py b/payment_integration_utils/patches/delete_old_custom_fields.py new file mode 100644 index 0000000..88e52fc --- /dev/null +++ b/payment_integration_utils/patches/delete_old_custom_fields.py @@ -0,0 +1,9 @@ +from payment_integration_utils.payment_integration_utils.setup import ( + delete_custom_fields, +) + +FIELDS_TO_DELETE = {"Payment Entry": ["is_auto_generated"]} + + +def execute(): + delete_custom_fields(FIELDS_TO_DELETE) diff --git a/payment_integration_utils/patches/delete_old_property_setters.py b/payment_integration_utils/patches/delete_old_property_setters.py new file mode 100644 index 0000000..8a1b448 --- /dev/null +++ b/payment_integration_utils/patches/delete_old_property_setters.py @@ -0,0 +1,9 @@ +from payment_integration_utils.payment_integration_utils.setup import ( + delete_property_setters, +) + +PROPERTY_SETTERS_TO_DELETE = [] + + +def execute(): + delete_property_setters(PROPERTY_SETTERS_TO_DELETE) From 5f7d6388ec617dba2613927d94934c674f42202f Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 27 Feb 2025 11:22:10 +0530 Subject: [PATCH 14/16] refactor: streamline setup functions for custom fields and workflows --- payment_integration_utils/setup.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/payment_integration_utils/setup.py b/payment_integration_utils/setup.py index b6cfa86..0115002 100644 --- a/payment_integration_utils/setup.py +++ b/payment_integration_utils/setup.py @@ -1,6 +1,8 @@ import click import frappe -from frappe.custom.doctype.custom_field.custom_field import create_custom_fields +from frappe.custom.doctype.custom_field.custom_field import ( + create_custom_fields as make_custom_fields, +) from payment_integration_utils.payment_integration_utils.constants.custom_fields import ( CUSTOM_FIELDS, @@ -30,17 +32,33 @@ ################### After Install ################### def setup_customizations(): click.secho("Creating Roles and Permissions...", fg="blue") - make_roles_and_permissions(ROLES) + create_roles_and_permissions() click.secho("Creating Custom Fields...", fg="blue") - create_custom_fields(CUSTOM_FIELDS) + create_custom_fields() click.secho("Creating Property Setters...", fg="blue") + create_property_setters() + + click.secho("Creating Workflows...", fg="blue") + create_workflows() + + +# Note: separate functions are required to use in patches +def create_roles_and_permissions(): + make_roles_and_permissions(ROLES) + + +def create_custom_fields(): + make_custom_fields(CUSTOM_FIELDS) + + +def create_property_setters(): for property_setter in PROPERTY_SETTERS: frappe.make_property_setter(property_setter) - click.secho("Creating Workflows...", fg="blue") +def create_workflows(): # create states make_workflow_states(WORKFLOW_STATES) From cbc5ab5a14fdd8cef8e3136473cafee42fe806f4 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Thu, 27 Feb 2025 11:24:23 +0530 Subject: [PATCH 15/16] fix: Update patch --- payment_integration_utils/patches.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/payment_integration_utils/patches.txt b/payment_integration_utils/patches.txt index daafed8..dc9d5e0 100644 --- a/payment_integration_utils/patches.txt +++ b/payment_integration_utils/patches.txt @@ -4,4 +4,5 @@ [post_model_sync] # Patches added in this section will be executed after doctypes are migrated +execute:from payment_integration_utils.setup import create_custom_fields; create_custom_fields() payment_integration_utils.patches.delete_old_custom_fields \ No newline at end of file From a002dfd424ddca2ed1cbdd31fe87f4448676aaff Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhoda Date: Fri, 28 Feb 2025 09:41:46 +0530 Subject: [PATCH 16/16] revert: remove server tests workflow file --- .github/workflows/server-tests.yml | 153 ----------------------------- 1 file changed, 153 deletions(-) delete mode 100644 .github/workflows/server-tests.yml diff --git a/.github/workflows/server-tests.yml b/.github/workflows/server-tests.yml deleted file mode 100644 index 983fd60..0000000 --- a/.github/workflows/server-tests.yml +++ /dev/null @@ -1,153 +0,0 @@ -name: Server Tests - -on: - workflow_call: - inputs: - base_ref: - type: string - - app_name: - type: string - - pull_request: - paths-ignore: - - "**.css" - - "**.js" - - "**.md" - - "**.html" - - "**.csv" - - push: - branches: [develop, "version-15"] - paths-ignore: - - "**.css" - - "**.js" - - "**.md" - - "**.html" - - "**.csv" - -env: - FRAPPE_BRANCH: "version-15" - ERPNEXT_BRANCH: "version-15" - APP_NAME: ${{ inputs.app_name || 'payment_integration_utils' }} - -# TODO: Update installation process when the app get published and remove SSH configuration -jobs: - tests: - runs-on: ubuntu-latest - timeout-minutes: 20 - - strategy: - fail-fast: false - matrix: - type: [server] - - name: Python Unit Tests - - services: - mariadb: - image: mariadb:10.6 - env: - MARIADB_ROOT_PASSWORD: "password" - ports: - - 3306:3306 - options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - - steps: - - name: Clone - uses: actions/checkout@v4 - - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 20 - check-latest: true - - - name: Add to Hosts - run: echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts - - - name: Cache pip - uses: actions/cache@v4 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - - - name: Cache node modules - uses: actions/cache@v4 - env: - cache-name: cache-node-modules - with: - path: ~/.npm - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}- - ${{ runner.os }}-build- - ${{ runner.os }}- - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Setup SSH - uses: webfactory/ssh-agent@v0.5.3 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - - name: Installing Apps - run: | - bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - env: - FRAPPE_BRANCH: ${{ env.FRAPPE_BRANCH }} - ERPNEXT_BRANCH: ${{ env.ERPNEXT_BRANCH }} - APP_NAME: ${{ env.APP_NAME }} - GITHUB_REPOSITORY: ${{ github.repository }} - PR_BRANCH: ${{ github.head_ref }} - - - name: Run Tests - run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app ${{ env.APP_NAME }} --with-coverage - env: - TYPE: server - - - name: Show bench output - if: ${{ always() }} - run: cat ~/frappe-bench/bench_start.log || true - - - # coverage: - # name: Coverage Wrap Up - # env: - # CODECOV_TOKEN: ${{ secrets.codecov_token || secrets.CODECOV_TOKEN }} - # needs: tests - # runs-on: ubuntu-latest - # steps: - # - name: Clone - # uses: actions/checkout@v4 - - # - name: Download artifacts - # uses: actions/download-artifact@v4 - - # - name: Upload coverage data - # if: github.event.repository.name == 'india-compliance' || env.CODECOV_TOKEN != '' - # uses: codecov/codecov-action@v4 - # env: - # CODECOV_TOKEN: ${{ env.CODECOV_TOKEN }} - # with: - # name: MariaDB - # fail_ci_if_error: true - # verbose: true