Skip to content

Commit

Permalink
Merge f7d07f5 into 7919b19
Browse files Browse the repository at this point in the history
  • Loading branch information
madmath03 committed Nov 14, 2019
2 parents 7919b19 + f7d07f5 commit 4758ce4
Show file tree
Hide file tree
Showing 34 changed files with 347 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ branches:

before_script:
- env | sort
- dir="test"
- dir=".travis"
- export IMAGE_NAME=docker-erpnext-ext:erpnext_ocr-travis
- export BUILD_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}
- export BUILD_URL=https://github.com/${TRAVIS_PULL_REQUEST_SLUG:-${TRAVIS_REPO_SLUG}}
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 6 additions & 12 deletions test/Dockerfile.alpine → .travis/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FROM monogramm/docker-erpnext:%%VERSION%%-alpine

RUN set -ex; \
sudo apk add --update \
chromium \
chromium-chromedriver \
;

# Build environment variables
ENV DOCKER_TAG=travis \
DOCKER_VCS_REF=${TRAVIS_COMMIT} \
Expand Down Expand Up @@ -29,15 +35,3 @@ RUN set -ex; \
"/home/$FRAPPE_USER"/frappe-bench/logs/* \
; \
bench get-app --branch ${BUILD_BRANCH} ${BUILD_URL}
#echo "Manually installing app for CI (not needed normally)"; \
#./env/bin/pip install -q -e "apps/erpnext_ocr" --no-cache-dir; \
#test ! "$FRAPPE_BRANCH" = "v10.x.x" \
# && ./env/bin/pip3 install -q -e "apps/erpnext_ocr" --no-cache-dir \
# && bench build --app erpnext_ocr \
#; \
#sudo mkdir -p "${FRAPPE_WD}/sites"; \
#sudo touch "${FRAPPE_WD}/sites/apps.txt"; \
#sudo chown $FRAPPE_USER:$FRAPPE_USER "${FRAPPE_WD}/sites/apps.txt"; \
#echo "frappe" > "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext" >> "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext_ocr" >> "${FRAPPE_WD}/sites/apps.txt"
28 changes: 16 additions & 12 deletions test/Dockerfile.debian → .travis/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
FROM monogramm/docker-erpnext:%%VERSION%%-debian

# Install Google Chrome & Chrome WebDriver for UI tests
RUN set -ex; \
sudo apt-get update -q; \
sudo apt-get install -y --no-install-recommends \
unzip \
; \
CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`; \
sudo mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION; \
sudo curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip; \
sudo unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION; \
sudo rm /tmp/chromedriver_linux64.zip; \
sudo chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver; \
sudo ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver; \
export PATH="$PATH;/usr/local/bin/chromedriver"

# Build environment variables
ENV DOCKER_TAG=travis \
DOCKER_VCS_REF=${TRAVIS_COMMIT} \
Expand All @@ -18,6 +33,7 @@ RUN set -ex; \
imagemagick \
tesseract-ocr \
; \
sudo rm -rf /var/lib/apt/lists/*; \
sudo sed -i \
-e 's/rights="none" pattern="PDF"/rights="read" pattern="PDF"/g' \
/etc/ImageMagick*/policy.xml \
Expand All @@ -29,15 +45,3 @@ RUN set -ex; \
"/home/$FRAPPE_USER"/frappe-bench/logs/* \
; \
bench get-app --branch ${BUILD_BRANCH} ${BUILD_URL}
#echo "Manually installing app for CI (not needed normally)"; \
#./env/bin/pip install -q -e "apps/erpnext_ocr" --no-cache-dir; \
#test ! "$FRAPPE_BRANCH" = "v10.x.x" \
# && ./env/bin/pip3 install -q -e "apps/erpnext_ocr" --no-cache-dir \
# && bench build --app erpnext_ocr \
#; \
#sudo mkdir -p "${FRAPPE_WD}/sites"; \
#sudo touch "${FRAPPE_WD}/sites/apps.txt"; \
#sudo chown $FRAPPE_USER:$FRAPPE_USER "${FRAPPE_WD}/sites/apps.txt"; \
#echo "frappe" > "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext" >> "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext_ocr" >> "${FRAPPE_WD}/sites/apps.txt"
30 changes: 17 additions & 13 deletions test/Dockerfile.debian-slim → .travis/Dockerfile.debian-slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
FROM monogramm/docker-erpnext:%%VERSION%%-debian-slim

# Install Google Chrome & Chrome WebDriver for UI tests
RUN set -ex; \
sudo apt-get update -q; \
sudo apt-get install -y --no-install-recommends \
iputils-ping \
unzip \
; \
CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`; \
sudo mkdir -p /opt/chromedriver-$CHROMEDRIVER_VERSION; \
sudo curl -sS -o /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip; \
sudo unzip -qq /tmp/chromedriver_linux64.zip -d /opt/chromedriver-$CHROMEDRIVER_VERSION; \
sudo rm /tmp/chromedriver_linux64.zip; \
sudo chmod +x /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver; \
sudo ln -fs /opt/chromedriver-$CHROMEDRIVER_VERSION/chromedriver /usr/local/bin/chromedriver; \
export PATH="$PATH;/usr/local/bin/chromedriver"

# Build environment variables
ENV DOCKER_TAG=travis \
DOCKER_VCS_REF=${TRAVIS_COMMIT} \
Expand All @@ -17,8 +33,8 @@ RUN set -ex; \
ghostscript \
imagemagick \
tesseract-ocr \
iputils-ping \
; \
sudo rm -rf /var/lib/apt/lists/*; \
sudo sed -i \
-e 's/rights="none" pattern="PDF"/rights="read" pattern="PDF"/g' \
/etc/ImageMagick*/policy.xml \
Expand All @@ -30,15 +46,3 @@ RUN set -ex; \
"/home/$FRAPPE_USER"/frappe-bench/logs/* \
; \
bench get-app --branch ${BUILD_BRANCH} ${BUILD_URL}
#echo "Manually installing app for CI (not needed normally)"; \
#./env/bin/pip install -q -e "apps/erpnext_ocr" --no-cache-dir; \
#test ! "$FRAPPE_BRANCH" = "v10.x.x" \
# && ./env/bin/pip3 install -q -e "apps/erpnext_ocr" --no-cache-dir \
# && bench build --app erpnext_ocr \
#; \
#sudo mkdir -p "${FRAPPE_WD}/sites"; \
#sudo touch "${FRAPPE_WD}/sites/apps.txt"; \
#sudo chown $FRAPPE_USER:$FRAPPE_USER "${FRAPPE_WD}/sites/apps.txt"; \
#echo "frappe" > "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext" >> "${FRAPPE_WD}/sites/apps.txt"; \
#echo "erpnext_ocr" >> "${FRAPPE_WD}/sites/apps.txt"
22 changes: 22 additions & 0 deletions .travis/Dockerfile_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM %%IMAGE_NAME%%

ADD docker_test.sh /docker_test.sh

# Test environment variables
ENV TEST_VERSION=${TEST_VERSION}

RUN set -ex; \
sudo chmod 755 /docker_test.sh; \
sudo pip install python-coveralls

EXPOSE 4444

# Default Chrome configuration
ENV DISPLAY=:20.0 \
SCREEN_GEOMETRY="1440x900x24" \
CHROMEDRIVER_PORT=4444 \
CHROMEDRIVER_WHITELISTED_IPS="127.0.0.1" \
CHROMEDRIVER_URL_BASE='' \
CHROMEDRIVER_EXTRA_ARGS=''

CMD ["/docker_test.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ services:
# Docker setup
- DOCKER_APPS_TIMEOUT=900
- DOCKER_DEBUG=1
# Test setup
- TEST_VERSION=${VERSION}
- TRAVIS_JOB_ID=${TRAVIS_JOB_ID}
- TRAVIS_BRANCH=${TRAVIS_BRANCH}
volumes_from:
- erpnext_app
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ services:
# Docker setup
- DOCKER_APPS_TIMEOUT=900
- DOCKER_DEBUG=1
# Test setup
- TEST_VERSION=${VERSION}
volumes_from:
- erpnext_app
volumes:
Expand Down
File renamed without changes.
95 changes: 95 additions & 0 deletions .travis/docker_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/sh

set -e

echo "Waiting to ensure everything is fully ready for the tests..."
sleep 60

echo "Checking content of sites directory..."
if [ ! -f "./sites/apps.txt" ] || [ ! -f "./sites/.docker-app-init" ] || [ ! -f "./sites/currentsite.txt" ] || [ ! -f "./sites/.docker-site-init" ] || [ ! -f "./sites/.docker-init" ]; then
echo 'Apps and site are not initalized?!'
ls -al "./sites"
exit 1
fi

echo "Checking main containers are reachable..."
if ! sudo ping -c 10 -q erpnext_db ; then
echo 'Database container is not responding!'
echo 'Check the following logs for details:'
tail -n 100 logs/*.log
exit 2
fi

if ! sudo ping -c 10 -q erpnext_app ; then
echo 'App container is not responding!'
echo 'Check the following logs for details:'
tail -n 100 logs/*.log
exit 4
fi

if ! sudo ping -c 10 -q erpnext_web ; then
echo 'Web container is not responding!'
echo 'Check the following logs for details:'
tail -n 100 logs/*.log
exit 8
fi


################################################################################
# Success
echo 'Docker tests successful'
#echo 'Check the following logs for details:'
#tail -n 100 logs/*.log


################################################################################
# Automated Unit tests
# https://docs.docker.com/docker-hub/builds/automated-testing/
# https://frappe.io/docs/user/en/testing
################################################################################

echo "Preparing Frappe application '${FRAPPE_APP_TO_TEST}' tests..."
FRAPPE_APP_TO_TEST=erpnext_ocr

################################################################################
# Frappe Unit tests
# https://frappe.io/docs/user/en/guides/automated-testing/unit-testing

#bench run-tests --help
echo "Executing Unit Tests of '${FRAPPE_APP_TO_TEST}' app..."
bench run-tests \
--app ${FRAPPE_APP_TO_TEST} --coverage
# FIXME https://github.com/frappe/frappe/issues/8809
# --junit-xml-output "$(pwd)/sites/.${FRAPPE_APP_TO_TEST}_unit_tests.xml"

## TODO Check result of tests
#if grep 'FAILED' "$(pwd)/sites/.${FRAPPE_APP_TO_TEST}_unit_tests.xml"; then
# echo "Unit Tests of '${FRAPPE_APP_TO_TEST}' app failed! See report for details:"
# cat "$(pwd)/sites/.${FRAPPE_APP_TO_TEST}_unit_tests.xml"
# exit 1
#fi

echo "Sending Unit Tests coverage of '${FRAPPE_APP_TO_TEST}' app to Coveralls..."
coveralls -b apps/${FRAPPE_APP_TO_TEST} -d ./sites/.coverage

################################################################################
# TODO QUnit (JS) Unit tests
# https://frappe.io/docs/user/en/guides/automated-testing/qunit-testing

#bench run-ui-tests --help
#echo "Executing UI Tests of '${FRAPPE_APP_TO_TEST}' app..."
#if [ "${TEST_VERSION}" = "10" ] || [ "${TEST_VERSION}" = "11" ]; then
# bench run-ui-tests --app ${FRAPPE_APP_TO_TEST}
#else
# bench run-ui-tests ${FRAPPE_APP_TO_TEST}
#fi

## TODO Check result of UI tests
#cat "${FRAPPE_APP_TO_TEST}_ui_tests.xml"


################################################################################
# Success
echo 'Frappe app '${FRAPPE_APP_TO_TEST}' tests finished'
echo 'Check the CI reports and logs for details.'
exit 0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ When installing Frappe app, the following python requirements will be installed:

**Sample Screenshot**:

![Sample Screenshot](./erpnext_ocr/erpnext_ocr/Selection_046.png)
![Sample Screenshot](./erpnext_ocr/tests/test_data/Picture_010.png)


**File Being Read**:

![Sample Screenshot 2](./erpnext_ocr/erpnext_ocr/Selection_047.png)
![Sample Screenshot 2](./erpnext_ocr/tests/test_data/Picture_010_screenshot.png)

### Tesseract trained data

Expand Down
Binary file removed erpnext_ocr/erpnext_ocr/Picture_010.tif
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

QUnit.test("test: OCR Language", function (assert) {
let done = assert.async();
let random_code = frappe.utils.get_random(3);
let random_lang = frappe.utils.get_random(2);

// number of asserts
assert.expect(1);
Expand All @@ -12,10 +14,11 @@ QUnit.test("test: OCR Language", function (assert) {
// insert a new OCR Language
() => frappe.tests.make('OCR Language', [
// values to be set
{key: 'value'}
{code: random_code, lang: random_lang}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
assert.equal(cur_frm.doc.code, random_code);
assert.equal(cur_frm.doc.lang, random_lang);
},
() => done()
]);
Expand Down
Loading

0 comments on commit 4758ce4

Please sign in to comment.