Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test suite and CI workflow to version-14 #34

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions .github/helper/install.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
#!/bin/bash

export PIP_ROOT_USER_ACTION=ignore

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

pip install --upgrade pip
pip install frappe-bench
git clone https://github.com/frappe/frappe --branch version-14 --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

mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"
mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"

mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe"
mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE OR REPLACE DATABASE test_site"
mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE OR REPLACE USER 'test_site'@'localhost' IDENTIFIED BY 'test_site'"
mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_site\`.* TO 'test_site'@'localhost'"

mysql --host 127.0.0.1 --port 3306 -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"
mysql --host 127.0.0.1 --port 3306 -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'" # match site_cofig
mysql --host 127.0.0.1 --port 3306 -u root -e "FLUSH PRIVILEGES"

cd ./frappe-bench || exit
echo BRANCH_NAME: "${BRANCH_NAME}"
git clone https://github.com/frappe/frappe --branch ${BRANCH_NAME}
bench init frappe-bench --frappe-path ~/frappe --python "$(which python)" --skip-assets --ignore-exist

sed -i 's/^watch:/# watch:/g' Procfile
sed -i 's/^schedule:/# schedule:/g' Procfile
mkdir ~/frappe-bench/sites/test_site
cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config.json" ~/frappe-bench/sites/test_site/

sed -i 's/^socketio:/# socketio:/g' Procfile;
sed -i 's/^redis_socketio:/# redis_socketio:/g' Procfile;
cd ~/frappe-bench || exit

bench setup requirements --node
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

cd ./apps/frappe || exit
yarn add node-sass@4.13.1
cd ../..
bench get-app erpnext https://github.com/frappe/erpnext --branch ${BRANCH_NAME} --resolve-deps --skip-assets
bench get-app payments https://github.com/frappe/payments --branch ${BRANCH_NAME} --skip-assets
bench get-app electronic_payments "${GITHUB_WORKSPACE}" --skip-assets

bench get-app https://github.com/frappe/payments
bench get-app https://github.com/frappe/erpnext --branch version-14
bench get-app https://github.com/frappe/hrms
bench setup requirements --dev
printf '%s\n' 'frappe' 'erpnext' 'payments' 'electronic_payments' > ~/frappe-bench/sites/apps.txt
bench setup requirements --python
bench use test_site

bench start &> bench_run_logs.txt &
CI=Yes bench build --app frappe &
bench --site test_site reinstall --yes
CI=Yes &
bench --site test_site reinstall --yes --admin-password admin

bench get-app check_run "${{GITHUB_WORKSPACE}}"
bench --site test_site install-app check_run
bench setup requirements --dev

echo "BENCH VERSION NUMBERS:"
bench version
echo "SITE LIST-APPS:"
bench list-apps

bench start &> bench_run_logs.txt &
CI=Yes &
bench execute 'electronic_payments.tests.setup.before_test'
8 changes: 1 addition & 7 deletions .github/helper/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@ if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${{GITHUB_WORKSPACE}}"
exit 1
fi

sudo apt update && sudo apt install redis-server libcups2-dev

# install wkhtmltopdf
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
sudo apt update -y && sudo apt install redis-server libcups2-dev mariadb-client-10.6 -y
35 changes: 20 additions & 15 deletions .github/helper/site_config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{
"db_host": "127.0.0.1",
"db_port": 3306,
"db_name": "test_frappe",
"db_password": "test_frappe",
"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": "travis",
"host_name": "http://test_site:8000",
"install_apps": ["erpnext", "electronic_payments"],
"throttle_user_limit": 100,
"developer_mode": 1
"allow_tests": true,
"db_host": "127.0.0.1",
"db_port": 3306,
"db_name": "test_site",
"db_password": "admin",
"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": "admin",
"host_name": "http://test_site:8000",
"install_apps": [
"erpnext",
"payments",
"electronic_payments"
],
"throttle_user_limit": 100,
"developer_mode": 1
}
84 changes: 84 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Pytest CI

on:
push:
branches:
- version-14
- version-15
pull_request:
branches:
- version-14
- version-15
env:
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}

# concurrency:
# group: develop-autoreader-${{ github.event.number }}
# cancel-in-progress: true

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
fail-fast: false
name: Server

services:
mariadb:
image: mariadb:10.6
env:
MYSQL_ALLOW_EMPTY_PASSWORD: YES
MYSQL_ROOT_PASSWORD: 'admin'
ports:
- 3306:3306
options: --health-cmd="mysqladmin 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.10'

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
check-latest: true
cache: 'yarn'

- 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', '**/pyproject.toml', '**/setup.py', '**/setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-

- name: Install JS Dependencies
run: yarn --prefer-offline

- name: Install App Dependencies
run: bash ${{ github.workspace }}/.github/helper/install_dependencies.sh

- name: Install Bench Site and Apps
env:
MYSQL_HOST: 'localhost'
MYSQL_PWD: 'admin'
BRANCH_NAME: ${{ env.BRANCH_NAME}}
run: |
bash ${{ github.workspace }}/.github/helper/install.sh

- name: Run Tests
working-directory: /home/runner/frappe-bench
run: |
source env/bin/activate
pytest ./apps/electronic_payments/electronic_payments/tests/ --disable-warnings -s
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def process_credit_card(self, doc, data):

createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = self.merchant_auth(doc.company)
createtransactionrequest.refId = doc.name
createtransactionrequest.refId = doc.name[:20] # Authorize.net length constraint
createtransactionrequest.transactionRequest = transactionrequest

createtransactioncontroller = createTransactionController(createtransactionrequest)
Expand Down Expand Up @@ -401,7 +401,7 @@ def charge_party_profile(self, doc, data):

createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = merchantAuth
createtransactionrequest.refId = doc.name
createtransactionrequest.refId = doc.name[:20] # Authorize.net length constraint

createtransactionrequest.transactionRequest = transactionrequest
createtransactioncontroller = createTransactionController(createtransactionrequest)
Expand Down Expand Up @@ -505,7 +505,7 @@ def credit_bank_account(self, doc, data):

createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = merchantAuth
createtransactionrequest.refId = doc.name
createtransactionrequest.refId = doc.name[:20] # Authorize.net length constraint
createtransactionrequest.transactionRequest = transactionrequest

createtransactioncontroller = createTransactionController(createtransactionrequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,11 @@ def queue_method_as_admin(method, **kwargs):


def get_party_details(doc):
if getattr(doc, "customer"):
if hasattr(doc, "customer"):
return frappe._dict(
{"doctype": "Customer", "name": doc.customer, "description": doc.customer_name}
)
else:
if getattr(doc, "supplier"):
return frappe._dict(
{"doctype": "Supplier", "name": doc.supplier, "description": doc.supplier_name}
)
elif hasattr(doc, "supplier"):
return frappe._dict(
{"doctype": "Supplier", "name": doc.supplier, "description": doc.supplier_name}
)
Loading
Loading