From 3d5fd3b1d3acaa4e1ef010c46977993cc3092a8f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 16 Jan 2024 09:27:11 +0530 Subject: [PATCH] fix: create portal user for customer from shopping cart --- .github/helper/install.sh | 63 +++++++++++++------ ...e_config.json => site_config_mariadb.json} | 2 +- .github/workflows/ci.yml | 14 +++-- webshop/setup/install.py | 2 +- webshop/webshop/shopping_cart/cart.py | 2 + 5 files changed, 57 insertions(+), 26 deletions(-) rename .github/helper/{site_config.json => site_config_mariadb.json} (99%) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index 557cbac2ab..c679b5d0b5 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -10,28 +10,51 @@ sudo apt install libcups2-dev redis-server mariadb-client-10.6 pip install frappe-bench -git clone https://github.com/frappe/frappe --branch "$BRANCH_TO_CLONE" --depth 1 +githubbranch=${GITHUB_BASE_REF:-${GITHUB_REF##*/}} +frappeuser=${FRAPPE_USER:-"frappe"} +frappebranch=${FRAPPE_BRANCH:-$githubbranch} + +git clone "https://github.com/${frappeuser}/frappe" --branch "${frappebranch}" --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/ -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'" -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'" +if [ "$DB" == "mariadb" ];then + cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config_mariadb.json" ~/frappe-bench/sites/test_site/site_config.json +else + cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config_postgres.json" ~/frappe-bench/sites/test_site/site_config.json +fi + + +if [ "$DB" == "mariadb" ];then + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'" + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'" + + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'" + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_frappe" + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'" + + mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES" +fi -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'" -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_frappe" -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'" +if [ "$DB" == "postgres" ];then + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE DATABASE test_frappe" -U postgres; + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE USER test_frappe WITH PASSWORD 'test_frappe'" -U postgres; +fi -mariadb --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES" install_whktml() { - wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz - tar -xf /tmp/wkhtmltox.tar.xz -C /tmp - sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf - sudo chmod o+x /usr/local/bin/wkhtmltopdf + 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=$! + cd ~/frappe-bench || exit @@ -40,15 +63,17 @@ 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 payments --branch ${BRANCH_TO_CLONE%"-hotfix"} -bench get-app https://github.com/frappe/erpnext --branch "$BRANCH_TO_CLONE" --resolve-deps -bench setup requirements --dev +bench get-app payments --branch ${githubbranch%"-hotfix"} +bench get-app erpnext "${GITHUB_WORKSPACE}" +bench get-app webshop "${GITHUB_WORKSPACE}" + +if [ "$TYPE" == "server" ]; then bench setup requirements --dev; fi -bench start &> bench_run_logs.txt & +wait $wkpid + +bench start &>> ~/frappe-bench/bench_start.log & CI=Yes bench build --app frappe & bench --site test_site reinstall --yes -bench get-app webshop "${GITHUB_WORKSPACE}" bench --site test_site install-app webshop -bench --site test_site set-config allow_tests true -bench setup requirements --dev \ No newline at end of file +bench --site test_site set-config allow_tests true \ No newline at end of file diff --git a/.github/helper/site_config.json b/.github/helper/site_config_mariadb.json similarity index 99% rename from .github/helper/site_config.json rename to .github/helper/site_config_mariadb.json index 21fdbf31c8..ff763b82e1 100644 --- a/.github/helper/site_config.json +++ b/.github/helper/site_config_mariadb.json @@ -13,4 +13,4 @@ "host_name": "http://test_site:8000", "install_apps": ["payments", "erpnext"], "throttle_user_limit": 100 -} \ No newline at end of file + } \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88e3623897..5e2ce06709 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,17 +91,21 @@ jobs: run: | bash ${GITHUB_WORKSPACE}/.github/helper/install.sh env: - BRANCH_TO_CLONE: ${{ env._BRANCH }} + DB: mariadb + TYPE: server + FRAPPE_USER: ${{ github.event.inputs.user }} + FRAPPE_BRANCH: ${{ github.event.inputs.branch }} - name: Run Tests run: cd ~/frappe-bench/ && bench --site test_site run-tests --app webshop --coverage env: TYPE: server + CI_BUILD_ID: ${{ github.run_id }} + ORCHESTRATOR_URL: http://test-orchestrator.frappe.io - name: Upload coverage data - uses: codecov/codecov-action@v2 + uses: actions/upload-artifact@v3 with: - fail_ci_if_error: true - files: /home/runner/frappe-bench/sites/coverage.xml - verbose: true \ No newline at end of file + name: coverage-${{ matrix.container }} + path: /home/runner/frappe-bench/sites/coverage.xml \ No newline at end of file diff --git a/webshop/setup/install.py b/webshop/setup/install.py index 825ca40497..06b251291a 100644 --- a/webshop/setup/install.py +++ b/webshop/setup/install.py @@ -233,7 +233,7 @@ def run_patches(): try: for patch in patches: - frappe.get_attr(f"webshop.patches.after_install.{patch}.execute")() + frappe.get_attr(f"webshop.patches.{patch}.execute")() finally: frappe.flags.in_patch = False diff --git a/webshop/webshop/shopping_cart/cart.py b/webshop/webshop/shopping_cart/cart.py index 3196c9698a..109d1a40f3 100644 --- a/webshop/webshop/shopping_cart/cart.py +++ b/webshop/webshop/shopping_cart/cart.py @@ -573,6 +573,8 @@ def get_party(user=None): } ) + customer.append("portal_users", {"user": user}) + if debtors_account: customer.update( {