def tearDown(self): frappe.db.sql('delete from `tabProperty Setter` where doc_type="Event"') frappe.clear_cache(doctype='Event') frappe.db.sql('delete from `tabEvent`') frappe.db.sql('delete from __global_search') make_test_objects('Event') frappe.db.commit()
def setUp(self): # GIVEN # Make Sure db is clean frappe.db.sql( 'delete from `tabCustom Event` where title like "_Test Event%"') frappe.db.sql( 'delete from `tabCustom Event` where name like "welcome-party-for-test%"' ) frappe.db.sql('delete from `tabUser` where email like "test_%"') frappe.db.sql( 'delete from `tabEvent Invitee` where invitee like "test_%"') # Create User user = frappe.get_doc({ "doctype": "User", "email": "*****@*****.**", "first_name": "Test Manager", }).insert() # Deleting new user automatic welcome party event to not interfere with the test logic. frappe.db.sql( 'delete from `tabCustom Event` where name like "welcome-party-for-test-manager"' ) user.add_roles('Event Manager') frappe.set_user('*****@*****.**') # Create events make_test_objects('Custom Event', reset=True) self.test_records = frappe.get_test_records('Custom Event')
def tearDown(self): frappe.db.delete("Property Setter", {"doc_type": "Event"}) frappe.clear_cache(doctype='Event') frappe.db.delete("Event") frappe.db.delete("__global_search") make_test_objects('Event') frappe.db.commit()
def tearDown(self): frappe.db.sql("DELETE FROM `tabProperty Setter` WHERE `doc_type`='Event'") frappe.clear_cache(doctype="Event") frappe.db.sql("DELETE FROM `tabEvent`") frappe.db.sql("DELETE FROM `__global_search`") make_test_objects("Event") frappe.db.commit()
def setUp(self): test_records = [ { "abbr": "_TC6", "company_name": "_Test Company 6", "country": "India", "default_currency": "INR", "doctype": "Company", "domain": "Manufacturing", "sales_target": 2000, "chart_of_accounts": "Standard" }, { "abbr": "_TC7", "company_name": "_Test Company 7", "country": "United States", "default_currency": "USD", "doctype": "Company", "domain": "Retail", "sales_target": 10000, "total_monthly_sales": 1000, "chart_of_accounts": "Standard" }, ] make_test_objects('Company', test_records=test_records, reset=True)
def test_get_item_details(self): # delete modified item price record and make as per test_records frappe.db.sql("""delete from `tabItem Price`""") to_check = { "item_code": "_Test Item", "item_name": "_Test Item", "description": "_Test Item 1", "warehouse": "_Test Warehouse - _TC", "income_account": "Sales - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", "qty": 1.0, "price_list_rate": 100.0, "base_price_list_rate": 0.0, "discount_percentage": 0.0, "rate": 0.0, "base_rate": 0.0, "amount": 0.0, "base_amount": 0.0, "batch_no": None, "uom": "_Test UOM", "conversion_factor": 1.0, } make_test_objects("Item Price") company = "_Test Company" currency = frappe.get_cached_value("Company", company, "default_currency") details = get_item_details({ "item_code": "_Test Item", "company": company, "price_list": "_Test Price List", "currency": currency, "doctype": "Sales Order", "conversion_rate": 1, "price_list_currency": currency, "plc_conversion_rate": 1, "order_type": "Sales", "customer": "_Test Customer", "conversion_factor": 1, "price_list_uom_dependant": 1, "ignore_pricing_rule": 1, }) for key, value in to_check.items(): self.assertEqual(value, details.get(key))
def _make_test_records(verbose): from frappe.test_runner import make_test_objects accounts = [ # [account_name, parent_account, is_group] ["_Test Bank", "Bank Accounts", 0, "Bank", None], ["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"], ["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"], ["_Test Cash", "Cash In Hand", 0, "Cash", None], ["_Test Account Stock Expenses", "Direct Expenses", 1, None, None], ["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], ["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None], ["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], ["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None], ["_Test Employee Advance", "Current Liabilities", 0, None, None], ["_Test Account Tax Assets", "Current Assets", 1, None, None], ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None], ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None], ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None], ["_Test Account Cost for Goods Sold", "Expenses", 0, None, None], ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None], ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None], ["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax", None], ["_Test Account CST", "Direct Expenses", 0, "Tax", None], ["_Test Account Discount", "Direct Expenses", 0, None, None], ["_Test Write Off", "Indirect Expenses", 0, None, None], ["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None], # related to Account Inventory Integration ["_Test Account Stock In Hand", "Current Assets", 0, None, None], # fixed asset depreciation ["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None], ["_Test Accumulated Depreciations", "Current Assets", 0, None, None], ["_Test Depreciations", "Expenses", 0, None, None], ["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None], # Receivable / Payable Account ["_Test Receivable", "Current Assets", 0, "Receivable", None], ["_Test Payable", "Current Liabilities", 0, "Payable", None], ["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"], ["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"] ] for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]: test_objects = make_test_objects("Account", [{ "doctype": "Account", "account_name": account_name, "parent_account": parent_account + " - " + abbr, "company": company, "is_group": is_group, "account_type": account_type, "account_currency": currency } for account_name, parent_account, is_group, account_type, currency in accounts]) return test_objects
def test_get_item_details(self): # delete modified item price record and make as per test_records frappe.db.sql("""delete from `tabItem Price`""") to_check = { "item_code": "_Test Item", "item_name": "_Test Item", "description": "_Test Item 1", "warehouse": "_Test Warehouse - _TC", "income_account": "Sales - _TC", "expense_account": "_Test Account Cost for Goods Sold - _TC", "cost_center": "_Test Cost Center 2 - _TC", "qty": 1.0, "price_list_rate": 100.0, "base_price_list_rate": 0.0, "discount_percentage": 0.0, "rate": 0.0, "base_rate": 0.0, "amount": 0.0, "base_amount": 0.0, "batch_no": None, "item_tax_rate": '{}', "uom": "_Test UOM", "conversion_factor": 1.0, } make_test_objects("Item Price") print(frappe.get_all("Item Price")) details = get_item_details({ "item_code": "_Test Item", "company": "_Test Company", "price_list": "_Test Price List", "currency": "_Test Currency", "doctype": "Sales Order", "conversion_rate": 1, "price_list_currency": "_Test Currency", "plc_conversion_rate": 1, "order_type": "Sales", "customer": "_Test Customer", "conversion_factor": 1, "price_list_uom_dependant": 1, "ignore_pricing_rule": 1 }) for key, value in to_check.iteritems(): self.assertEquals(value, details.get(key))
def _make_test_records(verbose): from frappe.test_runner import make_test_objects accounts = [ # [account_name, parent_account, is_group] ["_Test Account Bank Account", "Bank Accounts", 0, "Bank"], ["_Test Account Stock Expenses", "Direct Expenses", 1, None], ["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable"], ["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax"], ["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable"], ["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment"], ["_Test Account Tax Assets", "Current Assets", 1, None], ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None], ["_Test Account Cost for Goods Sold", "Expenses", 0, None], ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account CST", "Direct Expenses", 0, "Tax"], ["_Test Account Discount", "Direct Expenses", 0, None], ["_Test Write Off", "Indirect Expenses", 0, None], # related to Account Inventory Integration ["_Test Account Stock In Hand", "Current Assets", 0, None], ["_Test Account Fixed Assets", "Current Assets", 0, None], # Receivable / Payable Account ["_Test Receivable", "Current Assets", 0, "Receivable"], ["_Test Payable", "Current Liabilities", 0, "Payable"], ] for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]: test_objects = make_test_objects("Account", [{ "doctype": "Account", "account_name": account_name, "parent_account": parent_account + " - " + abbr, "company": company, "is_group": is_group, "account_type": account_type } for account_name, parent_account, is_group, account_type in accounts]) return test_objects
def _make_test_records(verbose): from frappe.test_runner import make_test_objects accounts = [ # [account_name, parent_account, group_or_ledger] ["_Test Account Bank Account", "Bank Accounts", "Ledger", "Bank"], ["_Test Account Stock Expenses", "Direct Expenses", "Group", None], ["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger", "Chargeable"], ["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger", "Tax"], ["_Test Account Insurance Charges", "_Test Account Stock Expenses", "Ledger", "Chargeable"], ["_Test Account Tax Assets", "Current Assets", "Group", None], ["_Test Account VAT", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Reserves and Surplus", "Current Liabilities", "Ledger", None], ["_Test Account Cost for Goods Sold", "Expenses", "Ledger", None], ["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account CST", "Direct Expenses", "Ledger", "Tax"], ["_Test Account Discount", "Direct Expenses", "Ledger", None], # related to Account Inventory Integration ["_Test Account Stock In Hand", "Current Assets", "Ledger", None], ["_Test Account Fixed Assets", "Current Assets", "Ledger", None], ] for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]: test_objects = make_test_objects( "Account", [ { "doctype": "Account", "account_name": account_name, "parent_account": parent_account + " - " + abbr, "company": company, "group_or_ledger": group_or_ledger, "account_type": account_type, } for account_name, parent_account, group_or_ledger, account_type in accounts ], ) return test_objects
def test_get_diff(self): test_records = make_test_objects('Event', reset = True) old_doc = frappe.get_doc("Event", test_records[0]) new_doc = copy.deepcopy(old_doc) old_doc.color = None diff = get_diff(old_doc, new_doc)['changed'] self.assertEquals(get_fieldnames(diff)[0], 'color') self.assertTrue(get_old_values(diff)[0] is None) self.assertEquals(get_new_values(diff)[0], 'blue') new_doc.starts_on = "2017-07-20" diff = get_diff(old_doc, new_doc)['changed'] self.assertEquals(get_fieldnames(diff)[0], 'starts_on') self.assertEquals(get_old_values(diff)[0], '01-01-2014 00:00:00') self.assertEquals(get_new_values(diff)[0], '07-20-2017 00:00:00')
def _make_test_records(verbose): from frappe.test_runner import make_test_objects accounts = [ # [account_name, parent_account, group_or_ledger] ["_Test Account Bank Account", "Bank Accounts", "Ledger", "Bank"], ["_Test Account Stock Expenses", "Direct Expenses", "Group", None], ["_Test Account Shipping Charges", "_Test Account Stock Expenses", "Ledger", "Chargeable"], ["_Test Account Customs Duty", "_Test Account Stock Expenses", "Ledger", "Tax"], ["_Test Account Tax Assets", "Current Assets", "Group", None], ["_Test Account VAT", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Service Tax", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Reserves and Surplus", "Current Liabilities", "Ledger", None], ["_Test Account Cost for Goods Sold", "Expenses", "Ledger", None], ["_Test Account Excise Duty", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account S&H Education Cess", "_Test Account Tax Assets", "Ledger", "Tax"], ["_Test Account CST", "Direct Expenses", "Ledger", "Tax"], ["_Test Account Discount", "Direct Expenses", "Ledger", None], # related to Account Inventory Integration ["_Test Account Stock In Hand", "Current Assets", "Ledger", None], ["_Test Account Fixed Assets", "Current Assets", "Ledger", None], ] for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]: test_objects = make_test_objects("Account", [{ "doctype": "Account", "account_name": account_name, "parent_account": parent_account + " - " + abbr, "company": company, "group_or_ledger": group_or_ledger, "account_type": account_type } for account_name, parent_account, group_or_ledger, account_type in accounts]) return test_objects
def test_get_diff(self): test_records = make_test_objects('Event', reset = True) old_doc = frappe.get_doc("Event", test_records[0]) new_doc = copy.deepcopy(old_doc) old_doc.color = None new_doc.color = '#fafafa' diff = get_diff(old_doc, new_doc)['changed'] self.assertEquals(get_fieldnames(diff)[0], 'color') self.assertTrue(get_old_values(diff)[0] is None) self.assertEquals(get_new_values(diff)[0], '#fafafa') new_doc.starts_on = "2017-07-20" diff = get_diff(old_doc, new_doc)['changed'] self.assertEquals(get_fieldnames(diff)[0], 'starts_on') self.assertEquals(get_old_values(diff)[0], '01-01-2014 00:00:00') self.assertEquals(get_new_values(diff)[0], '07-20-2017 00:00:00')
def test_get_diff(self): frappe.set_user("Administrator") test_records = make_test_objects("Event", reset=True) old_doc = frappe.get_doc("Event", test_records[0]) new_doc = copy.deepcopy(old_doc) old_doc.color = None new_doc.color = "#fafafa" diff = get_diff(old_doc, new_doc)["changed"] self.assertEqual(get_fieldnames(diff)[0], "color") self.assertTrue(get_old_values(diff)[0] is None) self.assertEqual(get_new_values(diff)[0], "#fafafa") new_doc.starts_on = "2017-07-20" diff = get_diff(old_doc, new_doc)["changed"] self.assertEqual(get_fieldnames(diff)[1], "starts_on") self.assertEqual(get_old_values(diff)[1], "01-01-2014 00:00:00") self.assertEqual(get_new_values(diff)[1], "07-20-2017 00:00:00")
def setUp(self): frappe.db.sql('delete from tabEvent') make_test_objects('Event', reset=True) self.test_records = frappe.get_test_records('Event') self.test_user = "******"
def setUpClass(cls): super(TestUtils, cls).setUpClass() make_test_objects("Address", ADDRESS_RECORDS)
def setUpClass(cls): super(TestUtils, cls).setUpClass() make_test_objects('Address', ADDRESS_RECORDS)
def setUp(self): make_test_objects('Event', reset=True)
def _make_test_records(verbose): from frappe.test_runner import make_test_objects accounts = [ # [account_name, parent_account, is_group] ["_Test Account Bank Account", "Bank Accounts", 0, "Bank"], ["_Test Account Stock Expenses", "Direct Expenses", 1, None], [ "_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable" ], [ "_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax" ], [ "_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable" ], [ "_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment" ], ["_Test Account Tax Assets", "Current Assets", 1, None], ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None], ["_Test Account Cost for Goods Sold", "Expenses", 0, None], ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax"], ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax"], [ "_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax" ], ["_Test Account CST", "Direct Expenses", 0, "Tax"], ["_Test Account Discount", "Direct Expenses", 0, None], ["_Test Write Off", "Indirect Expenses", 0, None], # related to Account Inventory Integration ["_Test Account Stock In Hand", "Current Assets", 0, None], ["_Test Account Fixed Assets", "Current Assets", 0, None], # Receivable / Payable Account ["_Test Receivable", "Current Assets", 0, "Receivable"], ["_Test Payable", "Current Liabilities", 0, "Payable"], ] for company, abbr in [["_Test Company", "_TC"], ["_Test Company 1", "_TC1"]]: test_objects = make_test_objects("Account", [{ "doctype": "Account", "account_name": account_name, "parent_account": parent_account + " - " + abbr, "company": company, "is_group": is_group, "account_type": account_type } for account_name, parent_account, is_group, account_type in accounts ]) return test_objects
def setUp(self): make_test_objects('Email Domain', reset=True)
def setUp(self): make_test_objects("Event", reset=True)