diff --git a/.travis.yml b/.travis.yml index a8a0d826145..40afeee8d46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,51 +1,80 @@ -language: python dist: trusty -python: - - "2.7" - - "3.6" +language: python -env: - - TEST_TYPE="Server Side Test" - - TEST_TYPE="Patch Test" +git: + depth: 1 -services: - - mysql +cache: + - pip + +addons: + hosts: test_site + mariadb: 10.3 + +jobs: + include: + - name: "Python 2.7 Server Side Test" + python: 2.7 + script: bench --site test_site run-tests --app erpnext --coverage + + - name: "Python 3.6 Server Side Test" + python: 3.6 + script: bench --site test_site run-tests --app erpnext --coverage + + - name: "Python 2.7 Patch Test" + python: 2.7 + before_script: + - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz + - bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz + script: bench --site test_site migrate + + - name: "Python 3.6 Patch Test" + python: 3.6 + before_script: + - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz + - bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz + script: bench --site test_site migrate install: - # fix mongodb travis error - - sudo rm /etc/apt/sources.list.d/mongodb*.list - - pip install flake8==3.3.0 - - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics - - sudo rm /etc/apt/sources.list.d/docker.list - - sudo apt-get install hhvm && rm -rf /home/travis/.kiex/ - - sudo apt-get purge -y mysql-common mysql-server mysql-client + - cd ~ - nvm install 10 - - pip install python-coveralls - - wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py - - sudo python install.py --develop --user travis --without-bench-setup - - sudo pip install -e ~/bench - - rm $TRAVIS_BUILD_DIR/.git/shallow - - bash $TRAVIS_BUILD_DIR/travis/bench_init.sh - - cp -r $TRAVIS_BUILD_DIR/test_sites/test_site ~/frappe-bench/sites/ + - git clone https://github.com/frappe/bench --depth 1 + - pip install -e ./bench -before_script: - - mysql -u root -ptravis -e 'create database test_frappe' - - echo "USE mysql;\nCREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe';\nFLUSH PRIVILEGES;\n" | mysql -u root -ptravis - - echo "USE mysql;\nGRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost';\n" | mysql -u root -ptravis + - git clone https://github.com/frappe/frappe --branch $TRAVIS_BRANCH --depth 1 + - bench init --skip-assets --frappe-path ~/frappe --python $(which python) frappe-bench + + - mkdir ~/frappe-bench/sites/test_site + - cp -r $TRAVIS_BUILD_DIR/.travis/site_config.json ~/frappe-bench/sites/test_site/ + + - mysql -u root -e "SET GLOBAL character_set_server = 'utf8mb4'" + - mysql -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'" + + - mysql -u root -e "CREATE DATABASE test_frappe" + - mysql -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'" + - mysql -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'" + + - mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'" + - mysql -u root -e "FLUSH PRIVILEGES" + + - 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 - cd ~/frappe-bench - - bench get-app erpnext $TRAVIS_BUILD_DIR - - bench use test_site - - bench reinstall --mariadb-root-username root --mariadb-root-password travis --yes - - bench scheduler disable - - sed -i 's/9000/9001/g' sites/common_site_config.json - - bench start & - - sleep 10 -script: - - bash $TRAVIS_BUILD_DIR/travis/run-tests.sh + - 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 $TRAVIS_BUILD_DIR + - bench start & + - bench --site test_site reinstall --yes after_script: + - pip install python-coveralls - coveralls -b apps/erpnext -d ../../sites/.coverage diff --git a/test_sites/test_site/site_config.json b/.travis/site_config.json similarity index 73% rename from test_sites/test_site/site_config.json rename to .travis/site_config.json index 48b330bc724..dae80095d45 100644 --- a/test_sites/test_site/site_config.json +++ b/.travis/site_config.json @@ -6,7 +6,8 @@ "mail_login": "test@example.com", "mail_password": "test", "admin_password": "admin", - "run_selenium_tests": 1, - "host_name": "http://localhost:8000", + "root_login": "root", + "root_password": "travis", + "host_name": "http://test_site:8000", "install_apps": ["erpnext"] } \ No newline at end of file diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 70ceeff4613..ae6fc49cea2 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '11.1.49' +__version__ = '11.1.50' def get_default_company(user=None): '''Get default company for user''' diff --git a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py index 2b68624f59f..b535ac6916c 100644 --- a/erpnext/accounts/doctype/loyalty_program/loyalty_program.py +++ b/erpnext/accounts/doctype/loyalty_program/loyalty_program.py @@ -38,7 +38,10 @@ def get_loyalty_details(customer, loyalty_program, expiry_date=None, company=Non @frappe.whitelist() def get_loyalty_program_details_with_points(customer, loyalty_program=None, expiry_date=None, company=None, silent=False, include_expired_entry=False, current_transaction_amount=0): lp_details = get_loyalty_program_details(customer, loyalty_program, company=company, silent=silent) - loyalty_program = frappe.get_doc("Loyalty Program", loyalty_program or lp_details.loyalty_program) + loyalty_program_name = loyalty_program or lp_details.loyalty_program + if not loyalty_program_name: return + + loyalty_program = frappe.get_doc("Loyalty Program", loyalty_program_name) lp_details.update(get_loyalty_details(customer, loyalty_program.name, expiry_date, company, include_expired_entry)) tier_spent_level = sorted([d.as_dict() for d in loyalty_program.collection_rules], diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index b4d584fbdef..6deee381481 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -20,11 +20,13 @@ test_dependencies = ["Item", "Cost Center", "Payment Term", "Payment Terms Templ test_ignore = ["Serial No"] class TestPurchaseInvoice(unittest.TestCase): - def setUp(self): + @classmethod + def setUpClass(self): unlink_payment_on_cancel_of_invoice() frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) - def tearDown(self): + @classmethod + def tearDownClass(self): unlink_payment_on_cancel_of_invoice(0) def test_gl_entries_without_perpetual_inventory(self): @@ -91,6 +93,7 @@ class TestPurchaseInvoice(unittest.TestCase): pi_doc = frappe.get_doc('Purchase Invoice', pi_doc.name) self.assertRaises(frappe.LinkExistsError, pi_doc.cancel) + unlink_payment_on_cancel_of_invoice() def test_purchase_invoice_for_blocked_supplier(self): supplier = frappe.get_doc('Supplier', '_Test Supplier') diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index bfcbe5a98eb..24358abffaf 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -28,10 +28,12 @@ class TestSalesInvoice(unittest.TestCase): w.submit() return w - def setUp(self): + @classmethod + def setUpClass(self): unlink_payment_on_cancel_of_invoice() - def tearDown(self): + @classmethod + def tearDownClass(self): unlink_payment_on_cancel_of_invoice(0) def test_timestamp_change(self): @@ -134,6 +136,7 @@ class TestSalesInvoice(unittest.TestCase): unlink_payment_on_cancel_of_invoice(0) si = frappe.get_doc('Sales Invoice', si.name) self.assertRaises(frappe.LinkExistsError, si.cancel) + unlink_payment_on_cancel_of_invoice() def test_sales_invoice_calculation_export_currency(self): si = frappe.copy_doc(test_records[2]) diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py index 1923f78cf89..63317c52d80 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py @@ -58,8 +58,7 @@ def get_columns(): { "fieldname": "payment_document", "label": _("Payment Document Type"), - "fieldtype": "Link", - "options": "DocType", + "fieldtype": "Data", "width": 220 }, { diff --git a/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py b/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py index 22dba99af00..e0f91cad652 100644 --- a/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py +++ b/erpnext/hr/doctype/staffing_plan/test_staffing_plan.py @@ -92,5 +92,5 @@ def make_company(): company.abbr = "_TC10" company.parent_company = "_Test Company" company.default_currency = "INR" - company.country = "India" + company.country = "Pakistan" company.insert() diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py index 696dc73ef32..d1bba923fd2 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.py +++ b/erpnext/regional/report/gstr_1/gstr_1.py @@ -152,7 +152,7 @@ class Gstr1Report(object): customers = frappe.get_all("Customer", filters={"disabled": 0}) - if self.filters.get("type_of_business") == "B2B": + if self.filters.get("type_of_business") == "B2B" and customers: conditions += """ and ifnull(invoice_type, '') != 'Export' and is_return != 1 and customer in ('{0}') and (customer_gstin IS NOT NULL AND customer_gstin NOT IN ('', 'NA'))""".\ format("', '".join([frappe.db.escape(c.name) for c in customers])) @@ -162,14 +162,14 @@ class Gstr1Report(object): if not b2c_limit: frappe.throw(_("Please set B2C Limit in GST Settings.")) - if self.filters.get("type_of_business") == "B2C Large": + if self.filters.get("type_of_business") == "B2C Large" and customers: conditions += """ and SUBSTR(place_of_supply, 1, 2) != SUBSTR(company_gstin, 1, 2) - and grand_total > {0} and is_return != 1 and customer in ('{1}')""".\ + and grand_total > {0} and is_return != 1 and customer in ('{1}') and (customer_gstin IS NULL OR customer_gstin IN ('', 'NA'))""".\ format(flt(b2c_limit), "', '".join([frappe.db.escape(c.name) for c in customers])) - elif self.filters.get("type_of_business") == "B2C Small": + elif self.filters.get("type_of_business") == "B2C Small" and customers: conditions += """ and ( SUBSTR(place_of_supply, 1, 2) = SUBSTR(company_gstin, 1, 2) - or grand_total <= {0}) and is_return != 1 and customer in ('{1}')""".\ + or grand_total <= {0}) and is_return != 1 and customer in ('{1}') and (customer_gstin IS NULL OR customer_gstin IN ('', 'NA'))""".\ format(flt(b2c_limit), "', '".join([frappe.db.escape(c.name) for c in customers])) elif self.filters.get("type_of_business") == "CDNR": diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 2dc585b8d63..eea23481c20 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -15,9 +15,10 @@ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.doctype.item.test_item import create_item class TestStockReconciliation(unittest.TestCase): - def setUp(self): + @classmethod + def setUpClass(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) - self.insert_existing_sle() + insert_existing_sle() def test_reco_for_fifo(self): self._test_reco_sle_gle("FIFO") @@ -94,17 +95,17 @@ class TestStockReconciliation(unittest.TestCase): self.assertEqual(["_Test Stock Reco Item", "_Test Warehouse Ledger 1 - _TC", 100], [items[0]["item_code"], items[0]["warehouse"], items[0]["qty"]]) - def insert_existing_sle(self): - from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry +def insert_existing_sle(): + from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - make_stock_entry(posting_date="2012-12-15", posting_time="02:00", item_code="_Test Item", - target="_Test Warehouse - _TC", qty=10, basic_rate=700) + make_stock_entry(posting_date="2012-12-15", posting_time="02:00", item_code="_Test Item", + target="_Test Warehouse - _TC", qty=10, basic_rate=700) - make_stock_entry(posting_date="2012-12-25", posting_time="03:00", item_code="_Test Item", - source="_Test Warehouse - _TC", qty=15) + make_stock_entry(posting_date="2012-12-25", posting_time="03:00", item_code="_Test Item", + source="_Test Warehouse - _TC", qty=15) - make_stock_entry(posting_date="2013-01-05", posting_time="07:00", item_code="_Test Item", - target="_Test Warehouse - _TC", qty=15, basic_rate=1200) + make_stock_entry(posting_date="2013-01-05", posting_time="07:00", item_code="_Test Item", + target="_Test Warehouse - _TC", qty=15, basic_rate=1200) def create_stock_reconciliation(**args): args = frappe._dict(args) diff --git a/erpnext/stock/doctype/stock_settings/test_stock_settings.py b/erpnext/stock/doctype/stock_settings/test_stock_settings.py index 1e83ec2f499..42a78f723d3 100644 --- a/erpnext/stock/doctype/stock_settings/test_stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/test_stock_settings.py @@ -8,16 +8,7 @@ import unittest class TestStockSettings(unittest.TestCase): def setUp(self): - settings = frappe.get_single('Stock Settings') - settings.clean_description_html = 0 - settings.save() - - frappe.delete_doc('Item', 'Item for description test') - - def tearDown(self): - settings = frappe.get_single('Stock Settings') - settings.clean_description_html = 1 - settings.save() + frappe.db.set_value("Stock Settings", None, "clean_description_html", 0) def test_settings(self): item = frappe.get_doc(dict( diff --git a/erpnext/tests/test_notifications.py b/erpnext/tests/test_notifications.py index 596bc80deea..1fd90beef0f 100644 --- a/erpnext/tests/test_notifications.py +++ b/erpnext/tests/test_notifications.py @@ -2,45 +2,31 @@ # MIT License. See license.txt from __future__ import unicode_literals +import frappe import unittest from frappe.desk import notifications from frappe.test_runner import make_test_objects class TestNotifications(unittest.TestCase): - def setUp(self): - test_records_company = [ - { - "abbr": "_TC6", - "company_name": "_Test Company 6", - "country": "India", - "default_currency": "INR", - "doctype": "Company", - "domain": "Manufacturing", - "monthly_sales_target": 2000, - "chart_of_accounts": "Standard" - }, - { - "abbr": "_TC7", - "company_name": "_Test Company 7", - "country": "United States", - "default_currency": "USD", - "doctype": "Company", - "domain": "Retail", - "monthly_sales_target": 10000, - "total_monthly_sales": 1000, - "chart_of_accounts": "Standard" - }, - ] - - make_test_objects('Company', test_records=test_records_company, reset=True) - def test_get_notifications_for_targets(self): ''' Test notification config entries for targets as percentages ''' + company = frappe.get_all("Company")[0] + frappe.db.set_value("Company", company.name, "monthly_sales_target", 10000) + frappe.db.set_value("Company", company.name, "total_monthly_sales", 1000) + config = notifications.get_notification_config() doc_target_percents = notifications.get_notifications_for_targets(config, {}) - self.assertEqual(doc_target_percents['Company']['_Test Company 7'], 10) - self.assertEqual(doc_target_percents['Company']['_Test Company 6'], 0) + + self.assertEqual(doc_target_percents['Company'][company.name], 10) + + frappe.db.set_value("Company", company.name, "monthly_sales_target", 2000) + frappe.db.set_value("Company", company.name, "total_monthly_sales", 0) + + config = notifications.get_notification_config() + doc_target_percents = notifications.get_notifications_for_targets(config, {}) + + self.assertEqual(doc_target_percents['Company'][company.name], 0) diff --git a/test_sites/apps.txt b/test_sites/apps.txt deleted file mode 100644 index ee6454915ca..00000000000 --- a/test_sites/apps.txt +++ /dev/null @@ -1 +0,0 @@ -erpnext \ No newline at end of file diff --git a/travis/bench_init.sh b/travis/bench_init.sh deleted file mode 100755 index f96269b919c..00000000000 --- a/travis/bench_init.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cd ~/ -curl -I https://github.com/frappe/frappe/tree/$TRAVIS_BRANCH | head -n 1 | cut -d $' ' -f2 | ( - read response; - [ $response == '200' ] && branch=$TRAVIS_BRANCH || branch='develop'; - bench init frappe-bench --frappe-path https://github.com/frappe/frappe.git --frappe-branch $branch --python $(which python) -) diff --git a/travis/run-tests.sh b/travis/run-tests.sh deleted file mode 100755 index 7cfd64833b7..00000000000 --- a/travis/run-tests.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -if [[ $TEST_TYPE == 'Server Side Test' ]]; then - bench run-tests --app erpnext --coverage - -elif [[ $TEST_TYPE == 'Patch Test' ]]; then - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz - bench --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz --mariadb-root-password travis - bench migrate -fi