Esempio n. 1
0
def make_test_objects(doctype, test_records=None, verbose=None, reset=False):
	'''Make test objects from given list of `test_records` or from `test_records.json`'''
	records = []

	def revert_naming(d):
		if getattr(d, 'naming_series', None):
			revert_series_if_last(d.naming_series, d.name)


	if test_records is None:
		test_records = frappe.get_test_records(doctype)

	for doc in test_records:
		if not doc.get("doctype"):
			doc["doctype"] = doctype

		d = frappe.copy_doc(doc)

		if d.meta.get_field("naming_series"):
			if not d.naming_series:
				d.naming_series = "_T-" + d.doctype + "-"

		if doc.get('name'):
			d.name = doc.get('name')
		else:
			d.set_new_name()

		if frappe.db.exists(d.doctype, d.name) and not reset:
			frappe.db.rollback()
			# do not create test records, if already exists
			continue

		# submit if docstatus is set to 1 for test record
		docstatus = d.docstatus

		d.docstatus = 0

		try:
			d.run_method("before_test_insert")
			d.insert()

			if docstatus == 1:
				d.submit()

		except frappe.NameError:
			revert_naming(d)

		except Exception as e:
			if d.flags.ignore_these_exceptions_in_test and e.__class__ in d.flags.ignore_these_exceptions_in_test:
				revert_naming(d)
			else:
				raise

		records.append(d.name)

		frappe.db.commit()

	return records
Esempio n. 2
0
def make_test_records_for_doctype(doctype, verbose=0, force=False):
	module, test_module = get_modules(doctype)

	if verbose:
		print "Making for " + doctype

	if hasattr(test_module, "_make_test_records"):
		frappe.local.test_objects[doctype] += test_module._make_test_records(verbose)

	elif hasattr(test_module, "test_records"):
		frappe.local.test_objects[doctype] += make_test_objects(doctype, test_module.test_records, verbose)

	else:
		test_records = frappe.get_test_records(doctype)
		if test_records:
			frappe.local.test_objects[doctype] += make_test_objects(doctype, test_records, verbose)

		elif verbose:
			print_mandatory_fields(doctype)
Esempio n. 3
0
def make_test_records_for_doctype(doctype, verbose=0, force=False):
	if not force and doctype in get_test_record_log():
		return

	module, test_module = get_modules(doctype)

	if verbose:
		print("Making for " + doctype)

	if hasattr(test_module, "_make_test_records"):
		frappe.local.test_objects[doctype] += test_module._make_test_records(verbose)

	elif hasattr(test_module, "test_records"):
		frappe.local.test_objects[doctype] += make_test_objects(doctype, test_module.test_records, verbose, force)

	else:
		test_records = frappe.get_test_records(doctype)
		if test_records:
			frappe.local.test_objects[doctype] += make_test_objects(doctype, test_records, verbose, force)

		elif verbose:
			print_mandatory_fields(doctype)

	add_to_test_record_log(doctype)
	lcv.company = "_Test Company"
	lcv.distribute_charges_based_on = 'Amount'
	
	lcv.set("purchase_receipts", [{
		"receipt_document_type": receipt_document_type,
		"receipt_document": receipt_document,
		"supplier": ref_doc.supplier,
		"posting_date": ref_doc.posting_date,
		"grand_total": ref_doc.base_grand_total
	}])
	
	lcv.set("taxes", [{
		"description": "Insurance Charges",
		"account": "_Test Account Insurance Charges - _TC",
		"amount": 50
	}])

	lcv.insert()
	
	distribute_landed_cost_on_items(lcv)
	
	lcv.submit()
		
def distribute_landed_cost_on_items(lcv):
	based_on = lcv.distribute_charges_based_on.lower()
	total = sum([flt(d.get(based_on)) for d in lcv.get("items")])
	for item in lcv.get("items"):
		item.applicable_charges = flt(item.get(based_on)) * flt(lcv.total_taxes_and_charges) / flt(total)

test_records = frappe.get_test_records('Landed Cost Voucher')
Esempio n. 5
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
from frappe.utils import today, random_string
from erpbee.crm.doctype.lead.lead import make_customer
from erpbee.crm.doctype.opportunity.opportunity import make_quotation
import unittest

test_records = frappe.get_test_records('Opportunity')

class TestOpportunity(unittest.TestCase):
	def test_opportunity_status(self):
		doc = make_opportunity(with_items=0)
		quotation = make_quotation(doc.name)
		quotation.append('items', {
			"item_code": "_Test Item",
			"qty": 1
		})

		quotation.run_method("set_missing_values")
		quotation.run_method("calculate_taxes_and_totals")
		quotation.submit()

		doc = frappe.get_doc('Opportunity', doc.name)
		self.assertEqual(doc.status, "Quotation")

	def test_make_new_lead_if_required(self):
		new_lead_email_id = "new{}@example.com".format(random_string(5))
		args = {
Esempio n. 6
0
		qo_item2 = [
			{
				"item_code": second_item.item_code,
				"warehouse": "_Test Warehouse - _TC",
				"qty": 2,
				"rate": 300,
				"conversion_factor": 1.0
			}
		]

		first_qo = make_quotation(item_list=qo_item1, do_not_submit=True)
		first_qo.submit()
		sec_qo = make_quotation(item_list=qo_item2, do_not_submit=True)
		sec_qo.submit()

test_records = frappe.get_test_records('Quotation')

def get_quotation_dict(customer=None, item_code=None):
	if not customer:
		customer = '_Test Customer'
	if not item_code:
		item_code = '_Test Item'

	return {
		'doctype': 'Quotation',
		'customer': customer,
		'items': [
			{
				'item_code': item_code,
				'qty': 1,
				'rate': 100
		prod_order = make_prod_order_test_record(item="_Test FG Item 2",
			planned_start_date="2014-11-25 00:00:00", qty=1, do_not_save=True)
		prod_order.set_production_order_operations()
		cost = prod_order.planned_operating_cost
		prod_order.qty = 2
		prod_order.set_production_order_operations()
		self.assertEqual(prod_order.planned_operating_cost, cost*2)
		
def make_prod_order_test_record(**args):
	args = frappe._dict(args)

	pro_order = frappe.new_doc("Production Order")
	pro_order.production_item = args.production_item or args.item or args.item_code or "_Test FG Item"
	pro_order.bom_no = frappe.db.get_value("BOM", {"item": pro_order.production_item,
		"is_active": 1, "is_default": 1})
	pro_order.qty = args.qty or 10
	pro_order.wip_warehouse = args.wip_warehouse or "_Test Warehouse - _TC"
	pro_order.fg_warehouse = args.fg_warehouse or "_Test Warehouse 1 - _TC"
	pro_order.company = args.company or "_Test Company"
	pro_order.stock_uom = "_Test UOM"
	if args.planned_start_date:
		pro_order.planned_start_date = args.planned_start_date

	if not args.do_not_save:
		pro_order.insert()
		if not args.do_not_submit:
			pro_order.submit()
	return pro_order

test_records = frappe.get_test_records('Production Order')
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest

test_records = frappe.get_test_records('Salary Structure')

class TestSalaryStructure(unittest.TestCase):
	pass
Esempio n. 9
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals


import frappe
test_records = frappe.get_test_records('Territory')
# Copyright (c) 2013, Frappe Technologies and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('AM Department')


class TestAMDepartment(unittest.TestCase):
    pass
Esempio n. 11
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals


import frappe
test_records = frappe.get_test_records('Earning Type')
Esempio n. 12
0
# Copyright (c) 2013, indictrans and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Feedback')


class TestFeedback(unittest.TestCase):
    pass
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

import frappe, os
import unittest, email

test_records = frappe.get_test_records('Email Account')

from frappe.core.doctype.communication.email import make
from frappe.desk.form.load import get_attachments
from frappe.utils.file_manager import delete_file_from_filesystem
from frappe.email.doctype.email_account.email_account import notify_unreplied
from datetime import datetime, timedelta


class TestEmailAccount(unittest.TestCase):
    def setUp(self):
        email_account = frappe.get_doc("Email Account",
                                       "_Test Email Account 1")
        email_account.db_set("enable_incoming", 1)
        frappe.db.sql('delete from `tabEmail Queue`')

    def tearDown(self):
        email_account = frappe.get_doc("Email Account",
                                       "_Test Email Account 1")
        email_account.db_set("enable_incoming", 0)

    def test_incoming(self):
        frappe.db.sql(
            "delete from tabCommunication where sender='*****@*****.**'"
        )
Esempio n. 14
0
from __future__ import unicode_literals

import unittest

import frappe
from frappe.test_runner import make_test_records
from frappe.utils import flt

from erpnext.accounts.party import get_due_date
from erpnext.exceptions import PartyDisabled, PartyFrozen
from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding
from erpnext.tests.utils import create_test_contact_and_address

test_ignore = ["Price List"]
test_dependencies = ['Payment Term', 'Payment Terms Template']
test_records = frappe.get_test_records('Customer')

from six import iteritems


class TestCustomer(unittest.TestCase):
    def setUp(self):
        if not frappe.get_value('Item', '_Test Item'):
            make_test_records('Item')

    def tearDown(self):
        set_credit_limit('_Test Customer', '_Test Company', 0)

    def test_get_customer_group_details(self):
        doc = frappe.new_doc("Customer Group")
        doc.customer_group_name = "_Testing Customer Group"
Esempio n. 15
0
		self.assertTrue(
			getdate("2013-01-02")
			in [d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")]
		)

	def test_get_applicable_block_dates_for_allowed_user(self):
		frappe.set_user("*****@*****.**")
		frappe.db.set_value(
			"Department", "_Test Department 1 - _TC", "leave_block_list", "_Test Leave Block List"
		)
		self.assertEqual(
			[], [d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03")]
		)

	def test_get_applicable_block_dates_all_lists(self):
		frappe.set_user("*****@*****.**")
		frappe.db.set_value(
			"Department", "_Test Department 1 - _TC", "leave_block_list", "_Test Leave Block List"
		)
		self.assertTrue(
			getdate("2013-01-02")
			in [
				d.block_date for d in get_applicable_block_dates("2013-01-01", "2013-01-03", all_lists=True)
			]
		)


test_dependencies = ["Employee"]

test_records = frappe.get_test_records("Leave Block List")
Esempio n. 16
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from erpnext.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError

test_records = frappe.get_test_records('Shipping Rule')


class TestShippingRule(unittest.TestCase):
    def test_from_greater_than_to(self):
        shipping_rule = frappe.copy_doc(test_records[0])
        shipping_rule.name = test_records[0].get('name')
        shipping_rule.get("conditions")[0].from_value = 101
        self.assertRaises(FromGreaterThanToError, shipping_rule.insert)

    def test_many_zero_to_values(self):
        shipping_rule = frappe.copy_doc(test_records[0])
        shipping_rule.name = test_records[0].get('name')
        shipping_rule.get("conditions")[0].to_value = 0
        self.assertRaises(ManyBlankToValuesError, shipping_rule.insert)

    def test_overlapping_conditions(self):
        for range_a, range_b in [
            ((50, 150), (0, 100)),
            ((50, 150), (100, 200)),
            ((50, 150), (75, 125)),
            ((50, 150), (25, 175)),
            ((50, 150), (50, 150)),
Esempio n. 17
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

"""Use blog post test to test user permissions logic"""

import frappe
import frappe.defaults
import unittest
import json

from frappe.core.doctype.event.event import get_events

test_records = frappe.get_test_records('Event')

class TestEvent(unittest.TestCase):
	# def setUp(self):
	# 	user = frappe.get_doc("User", "*****@*****.**")
	# 	user.add_roles("Website Manager")

	def tearDown(self):
		frappe.set_user("Administrator")

	def test_allowed_public(self):
		frappe.set_user("*****@*****.**")
		doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 1"}))
		self.assertTrue(frappe.has_permission("Event", doc=doc))

	def test_not_allowed_private(self):
		frappe.set_user("*****@*****.**")
		doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 2"}))
		self.assertFalse(frappe.has_permission("Event", doc=doc))
Esempio n. 18
0
# -*- coding: utf-8 -*-
# Copyright (c) 2015, TeamA Technologies and Contributors
# See license.txt
from __future__ import unicode_literals
from frappe.test_runner import make_test_records
from erpnext.education.doctype.program.test_program import make_program_and_linked_courses
from erpnext.education.doctype.course.test_course import make_course

import frappe
import unittest

test_records = frappe.get_test_records('Student')


class TestStudent(unittest.TestCase):
    def setUp(self):
        create_student({"first_name": "_Test Name",
                        "last_name": "_Test Last Name", "email": "*****@*****.**"})
        make_program_and_linked_courses(
            "_Test Program 1", ["_Test Course 1", "_Test Course 2"])

    def test_create_student_user(self):
        self.assertTrue(bool(frappe.db.exists(
            "User", "*****@*****.**")))
        frappe.db.rollback()

    def test_enroll_in_program(self):
        student = get_student("*****@*****.**")
        enrollment = student.enroll_in_program("_Test Program 1")
        test_enrollment = frappe.get_all("Program Enrollment", filters={
                                         "student": student.name, "Program": "_Test Program 1"})
Esempio n. 19
0
		"item_code": args.item or args.item_code or "_Test Item",
		"s_warehouse": args.from_warehouse or args.source,
		"t_warehouse": args.to_warehouse or args.target,
		"qty": args.qty,
		"basic_rate": args.basic_rate,
		"expense_account": args.expense_account or "Stock Adjustment - _TC",
		"conversion_factor": 1.0,
		"cost_center": "_Test Cost Center - _TC",
		"serial_no": args.serial_no
	})

	if not args.do_not_save:
		s.insert()
		if not args.do_not_submit:
			s.submit()
	return s

def get_qty_after_transaction(**args):
	args = frappe._dict(args)

	last_sle = get_previous_sle({
		"item_code": args.item_code or "_Test Item",
		"warehouse": args.warehouse or "_Test Warehouse - _TC",
		"posting_date": args.posting_date or nowdate(),
		"posting_time": args.posting_time or nowtime()
	})

	return flt(last_sle.get("qty_after_transaction"))

test_records = frappe.get_test_records('Stock Entry')
Esempio n. 20
0
# Copyright (c) 2013, Systematrix and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Web Contact Form')

class TestWebContactForm(unittest.TestCase):
	pass
Esempio n. 21
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals

"""Use blog post test to test user permissions logic"""

import frappe
import frappe.defaults
import unittest
import json
import frappe.model.meta
from frappe.core.page.user_permissions.user_permissions import add, remove, get_permissions
from frappe.permissions import clear_user_permissions_for_doctype, get_doc_permissions

test_records = frappe.get_test_records('Blog Post')

test_dependencies = ["User"]

class TestPermissions(unittest.TestCase):
	def setUp(self):
		frappe.clear_cache(doctype="Blog Post")

		user = frappe.get_doc("User", "*****@*****.**")
		user.add_roles("Website Manager")

		user = frappe.get_doc("User", "*****@*****.**")
		user.add_roles("Blogger")

		frappe.db.sql("""update `tabDocPerm` set if_owner=0
			where parent='Blog Post' and permlevel=0 and permlevel=0 and role='Blogger'""")
Esempio n. 22
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: See license.txt

from __future__ import unicode_literals

import frappe
test_records = frappe.get_test_records('Address Template')

import unittest
import frappe


class TestAddressTemplate(unittest.TestCase):
    def test_default_is_unset(self):
        a = frappe.get_doc("Address Template", "India")
        a.is_default = 1
        a.save()

        b = frappe.get_doc("Address Template", "Brazil")
        b.is_default = 1
        b.save()

        self.assertEqual(
            frappe.db.get_value("Address Template", "India", "is_default"), 0)

    def tearDown(self):
        a = frappe.get_doc("Address Template", "India")
        a.is_default = 1
        a.save()
Esempio n. 23
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt


from __future__ import unicode_literals
import unittest
import frappe
from frappe.utils import cstr

test_records = frappe.get_test_records('BOM')

class TestBOM(unittest.TestCase):
	def test_get_items(self):
		from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict
		items_dict = get_bom_items_as_dict(bom=get_default_bom(), qty=1, fetch_exploded=0)
		self.assertTrue(test_records[2]["items"][0]["item_code"] in items_dict)
		self.assertTrue(test_records[2]["items"][1]["item_code"] in items_dict)
		self.assertEquals(len(items_dict.values()), 2)

	def test_get_items_exploded(self):
		from erpnext.manufacturing.doctype.bom.bom import get_bom_items_as_dict
		items_dict = get_bom_items_as_dict(bom=get_default_bom(), qty=1, fetch_exploded=1)
		self.assertTrue(test_records[2]["items"][0]["item_code"] in items_dict)
		self.assertFalse(test_records[2]["items"][1]["item_code"] in items_dict)
		self.assertTrue(test_records[0]["items"][0]["item_code"] in items_dict)
		self.assertTrue(test_records[0]["items"][1]["item_code"] in items_dict)
		self.assertEquals(len(items_dict.values()), 3)

	def test_get_items_list(self):
		from erpnext.manufacturing.doctype.bom.bom import get_bom_items
		self.assertEquals(len(get_bom_items(bom=get_default_bom())), 3)
Esempio n. 24
0
        for serial_no in accepted_serial_nos:
            self.assertEquals(
                frappe.db.get_value("Serial No", serial_no, "warehouse"),
                pr.get("purchase_receipt_details")[0].warehouse)

        rejected_serial_nos = pr.get(
            "purchase_receipt_details")[0].rejected_serial_no.split("\n")
        self.assertEquals(len(rejected_serial_nos), 2)
        for serial_no in rejected_serial_nos:
            self.assertEquals(
                frappe.db.get_value("Serial No", serial_no, "warehouse"),
                pr.get("purchase_receipt_details")[0].rejected_warehouse)


def get_gl_entries(voucher_type, voucher_no):
    return frappe.db.sql("""select account, debit, credit
		from `tabGL Entry` where voucher_type=%s and voucher_no=%s
		order by account desc""", (voucher_type, voucher_no),
                         as_dict=1)


def set_perpetual_inventory(enable=1):
    accounts_settings = frappe.get_doc("Accounts Settings")
    accounts_settings.auto_accounting_for_stock = enable
    accounts_settings.save()


test_dependencies = ["BOM", "Item Price"]

test_records = frappe.get_test_records('Purchase Receipt')
# Copyright (c) 2013, Nathan (Hoovix Consulting Pte. Ltd.) and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Opencart Site')

class TestOpencartSite(unittest.TestCase):
	pass
Esempio n. 26
0
def get_multiple_items():
    return [{
        "conversion_factor": 1.0,
        "cost_center": "Main - TCP1",
        "doctype": "Stock Entry Detail",
        "expense_account": "Stock Adjustment - TCP1",
        "basic_rate": 100,
        "item_code": "_Test Item",
        "qty": 50.0,
        "s_warehouse": "Stores - TCP1",
        "stock_uom": "_Test UOM",
        "transfer_qty": 50.0,
        "uom": "_Test UOM"
    }, {
        "conversion_factor": 1.0,
        "cost_center": "Main - TCP1",
        "doctype": "Stock Entry Detail",
        "expense_account": "Stock Adjustment - TCP1",
        "basic_rate": 5000,
        "item_code": "_Test Item Home Desktop 100",
        "qty": 1,
        "stock_uom": "_Test UOM",
        "t_warehouse": "Stores - TCP1",
        "transfer_qty": 1,
        "uom": "_Test UOM"
    }]


test_records = frappe.get_test_records('Stock Entry')
Esempio n. 27
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from frappe.utils import random_string, nowdate
from erpnext.hr.doctype.expense_claim.expense_claim import make_bank_entry

test_records = frappe.get_test_records('Expense Claim')

class TestExpenseClaim(unittest.TestCase):
	def test_total_expense_claim_for_project(self):
		frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """)
		frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """)

		frappe.get_doc({
			"project_name": "_Test Project 1",
			"doctype": "Project",
			"tasks" :
				[{ "title": "_Test Project Task 1", "status": "Open" }]
		}).save()

		task_name = frappe.db.get_value("Task", {"project": "_Test Project 1"})
		payable_account = get_payable_account("Wind Power LLC")

		expense_claim = frappe.get_doc({
			 "doctype": "Expense Claim",
			 "employee": "_T-Employee-0001",
			 "payable_account": payable_account,
			 "approval_status": "Approved",
Esempio n. 28
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: See license.txt

import frappe
test_records = frappe.get_test_records('Country')
Esempio n. 29
0
# Copyright (c) 2013, Wayzon Technologies and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Contact')

class TestContact(unittest.TestCase):
	pass
Esempio n. 30
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
test_records = frappe.get_test_records('Communication')


class TestCommunication(unittest.TestCase):

	def test_email(self):
		valid_email_list = ["Full Name <*****@*****.**>",
		'"Full Name with quotes and <*****@*****.**>" <*****@*****.**>',
		"Surname, Name <*****@*****.**>",
		"Purchase@ABC <*****@*****.**>", "[email protected] <*****@*****.**>",
		"Name [something else] <*****@*****.**>"]

		invalid_email_list = ["[invalid!email]", "invalid-email",
		"tes2", "e", "rrrrrrrr", "manas","[[[sample]]]",
		"[invalid!email].com"]

		for x in valid_email_list:
			self.assertTrue(frappe.utils.parse_addr(x)[1])

		for x in invalid_email_list:
			self.assertFalse(frappe.utils.parse_addr(x)[0])

	def test_name(self):
		valid_email_list = ["Full Name <*****@*****.**>",
		'"Full Name with quotes and <*****@*****.**>" <*****@*****.**>',
    pi.is_return = args.is_return
    pi.is_return = args.is_return
    pi.credit_to = args.return_against or "Creditors - _TC"
    pi.is_subcontracted = args.is_subcontracted or "No"
    pi.supplier_warehouse = "_Test Warehouse 1 - _TC"

    pi.append(
        "items", {
            "item_code": args.item or args.item_code or "_Test Item",
            "warehouse": args.warehouse or "_Test Warehouse - _TC",
            "qty": args.qty or 5,
            "received_qty": args.received_qty or 0,
            "rejected_qty": args.rejected_qty or 0,
            "rate": args.rate or 50,
            "conversion_factor": 1.0,
            "serial_no": args.serial_no,
            "stock_uom": "_Test UOM",
            "cost_center": args.cost_center or "_Test Cost Center - _TC",
            "project": args.project,
            "rejected_warehouse": args.rejected_warehouse or "",
            "rejected_serial_no": args.rejected_serial_no or ""
        })
    if not args.do_not_save:
        pi.insert()
        if not args.do_not_submit:
            pi.submit()
    return pi


test_records = frappe.get_test_records('Purchase Invoice')
Esempio n. 32
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import frappe

test_records = frappe.get_test_records('Activity Type')
Esempio n. 33
0
		pr.get("purchase_receipt_details")[0].rejected_warehouse = "_Test Rejected Warehouse - _TC"
		pr.insert()
		pr.submit()

		accepted_serial_nos = pr.get("purchase_receipt_details")[0].serial_no.split("\n")
		self.assertEquals(len(accepted_serial_nos), 3)
		for serial_no in accepted_serial_nos:
			self.assertEquals(frappe.db.get_value("Serial No", serial_no, "warehouse"),
				pr.get("purchase_receipt_details")[0].warehouse)

		rejected_serial_nos = pr.get("purchase_receipt_details")[0].rejected_serial_no.split("\n")
		self.assertEquals(len(rejected_serial_nos), 2)
		for serial_no in rejected_serial_nos:
			self.assertEquals(frappe.db.get_value("Serial No", serial_no, "warehouse"),
				pr.get("purchase_receipt_details")[0].rejected_warehouse)

def get_gl_entries(voucher_type, voucher_no):
	return frappe.db.sql("""select account, debit, credit
		from `tabGL Entry` where voucher_type=%s and voucher_no=%s
		order by account desc""", (voucher_type, voucher_no), as_dict=1)

def set_perpetual_inventory(enable=1):
	accounts_settings = frappe.get_doc("Accounts Settings")
	accounts_settings.auto_accounting_for_stock = enable
	accounts_settings.save()


test_dependencies = ["BOM"]

test_records = frappe.get_test_records('Purchase Receipt')
Esempio n. 34
0
                                                 do_not_save=True)
        self.assertRaises(ItemHasVariantError, prod_order.save)


def make_prod_order_test_record(**args):
    args = frappe._dict(args)

    pro_order = frappe.new_doc("Production Order")
    pro_order.production_item = args.production_item or args.item or args.item_code or "_Test FG Item"
    pro_order.bom_no = frappe.db.get_value("BOM", {
        "item": pro_order.production_item,
        "is_active": 1,
        "is_default": 1
    })
    pro_order.qty = args.qty or 10
    pro_order.wip_warehouse = args.wip_warehouse or "_Test Warehouse - _TC"
    pro_order.fg_warehouse = args.fg_warehouse or "_Test Warehouse 1 - _TC"
    pro_order.company = args.company or "_Test Company"
    pro_order.stock_uom = "_Test UOM"
    if args.planned_start_date:
        pro_order.planned_start_date = args.planned_start_date

    if not args.do_not_save:
        pro_order.insert()
        if not args.do_not_submit:
            pro_order.submit()
    return pro_order


test_records = frappe.get_test_records('Production Order')
Esempio n. 35
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

test_ignore = ["Account", "Cost Center"]

import frappe
import unittest
from frappe.utils import random_string
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import get_charts_for_country

test_records = frappe.get_test_records('Company')

class TestCompany(unittest.TestCase):
	def test_coa_based_on_existing_company(self):
		company = frappe.new_doc("Company")
		company.company_name = "COA from Existing Company"
		company.abbr = "CFEC"
		company.default_currency = "INR"
		company.create_chart_of_accounts_based_on = "Existing Company"
		company.existing_company = "_Test Company"
		company.save()
		
		expected_results = {
			"Debtors - CFEC": {
				"account_type": "Receivable",
				"is_group": 0,
				"root_type": "Asset",
				"parent_account": "Accounts Receivable - CFEC",
			},
			"_Test Cash - CFEC": {
Esempio n. 36
0
# Copyright (c) 2013, New Indictrans Technologies Pvt. Ltd. and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Member')


class TestMember(unittest.TestCase):
    pass
# Copyright (c) 2013, Wayzon Technology Services Pvt Ltd and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Bank Withdrawal')

class TestBankWithdrawal(unittest.TestCase):
	pass
Esempio n. 38
0
            "t_warehouse": "_Test Warehouse 1 - _TC",
            "incoming_rate": 1.0
        })
        se_doc.get("mtn_details")[1].update({
            "qty": 3.0,
            "transfer_qty": 3.0,
            "s_warehouse": "_Test Warehouse 1 - _TC",
            "incoming_rate": 1.0
        })

        # check for stopped status of Material Request
        se = frappe.copy_doc(se_doc)
        self.assertRaises(frappe.MappingMismatchError, se.insert)

    def test_warehouse_company_validation(self):
        from erpnext.stock.utils import InvalidWarehouseCompany
        mr = frappe.copy_doc(test_records[0])
        mr.company = "_Test Company 1"
        self.assertRaises(InvalidWarehouseCompany, mr.insert)

    def _get_requested_qty(self, item_code, warehouse):
        return flt(
            frappe.db.get_value("Bin", {
                "item_code": item_code,
                "warehouse": warehouse
            }, "indented_qty"))


test_dependencies = ["Currency Exchange"]
test_records = frappe.get_test_records('Material Request')
Esempio n. 39
0
# Copyright (c) 2013, xyz and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Doc_master')

class TestDoc_master(unittest.TestCase):
	pass
	si.company = args.company or "_Test Company"
	si.customer = args.customer or "_Test Customer"
	si.debit_to = args.debit_to or "Debtors - _TC"
	si.update_stock = args.update_stock
	si.is_pos = args.is_pos
	si.is_return = args.is_return
	si.return_against = args.return_against
	si.currency=args.currency or "INR"
	si.conversion_rate = args.conversion_rate or 1

	si.append("items", {
		"item_code": args.item or args.item_code or "_Test Item",
		"warehouse": args.warehouse or "_Test Warehouse - _TC",
		"qty": args.qty or 1,
		"rate": args.rate or 100,
		"income_account": "Sales - _TC",
		"expense_account": "Cost of Goods Sold - _TC",
		"cost_center": "_Test Cost Center - _TC",
		"serial_no": args.serial_no
	})

	if not args.do_not_save:
		si.insert()
		if not args.do_not_submit:
			si.submit()
	return si

test_dependencies = ["Journal Entry", "Contact", "Address"]
test_records = frappe.get_test_records('Sales Invoice')
Esempio n. 41
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

"""Use blog post test to test permission restriction logic"""

import frappe
import frappe.defaults
import unittest

test_records = frappe.get_test_records("Event")


class TestEvent(unittest.TestCase):
    # def setUp(self):
    # 	user = frappe.get_doc("User", "*****@*****.**")
    # 	user.add_roles("Website Manager")

    def tearDown(self):
        frappe.set_user("Administrator")

    def test_allowed_public(self):
        frappe.set_user("*****@*****.**")
        doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject": "_Test Event 1"}))
        self.assertTrue(frappe.has_permission("Event", doc=doc))

    def test_not_allowed_private(self):
        frappe.set_user("*****@*****.**")
        doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject": "_Test Event 2"}))
        self.assertFalse(frappe.has_permission("Event", doc=doc))

    def test_allowed_private_if_in_event_user(self):
Esempio n. 42
0
# Copyright (c) 2013, Arun Logistics and Contributors
# See license.txt

import unittest

import frappe

test_records = frappe.get_test_records('Gatepass')


class TestGatepass(unittest.TestCase):
    pass
Esempio n. 43
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals

import frappe
import unittest

from frappe.test_runner import make_test_records
from erpnext.controllers.accounts_controller import CustomerFrozen

test_ignore = ["Price List"]

test_records = frappe.get_test_records('Customer')

class TestCustomer(unittest.TestCase):
	def test_party_details(self):
		from erpnext.accounts.party import get_party_details

		to_check = {
			'selling_price_list': None,
			'customer_group': '_Test Customer Group',
			'contact_designation': None,
			'customer_address': '_Test Address-Office',
			'contact_department': None,
			'contact_email': '*****@*****.**',
			'contact_mobile': None,
			'sales_team': [],
			'contact_display': '_Test Contact For _Test Customer',
			'contact_person': '_Test Contact For _Test Customer-_Test Customer',
			'territory': u'_Test Territory',
Esempio n. 44
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Item Attribute')


class TestItemAttribute(unittest.TestCase):
    pass
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

import frappe
import unittest
from erpnext.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError

test_records = frappe.get_test_records('Shipping Rule')

class TestShippingRule(unittest.TestCase):
	def test_from_greater_than_to(self):
		shipping_rule = frappe.copy_doc(test_records[0])
		shipping_rule.name = test_records[0].get('name')
		shipping_rule.get("shipping_rule_conditions")[0].from_value = 101
		self.assertRaises(FromGreaterThanToError, shipping_rule.insert)
		
	def test_many_zero_to_values(self):
		shipping_rule = frappe.copy_doc(test_records[0])
		shipping_rule.name = test_records[0].get('name')
		shipping_rule.get("shipping_rule_conditions")[0].to_value = 0
		self.assertRaises(ManyBlankToValuesError, shipping_rule.insert)
		
	def test_overlapping_conditions(self):
		for range_a, range_b in [
			((50, 150), (0, 100)),
			((50, 150), (100, 200)),
			((50, 150), (75, 125)),
			((50, 150), (25, 175)),
			((50, 150), (50, 150)),
		]:
			shipping_rule = frappe.copy_doc(test_records[0])
Esempio n. 46
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import frappe
test_records = frappe.get_test_records('Brand')
Esempio n. 47
0
		new_barcode.barcode_type = 'EAN'
		self.assertRaises(InvalidBarcode, item_doc.save)

def set_item_variant_settings(fields):
	doc = frappe.get_doc('Item Variant Settings')
	doc.set('fields', fields)
	doc.save()

def make_item_variant():
	if not frappe.db.exists("Item", "_Test Variant Item-S"):
		variant = create_variant("_Test Variant Item", """{"Test Size": "Small"}""")
		variant.item_code = "_Test Variant Item-S"
		variant.item_name = "_Test Variant Item-S"
		variant.save()

test_records = frappe.get_test_records('Item')

def create_item(item_code, is_stock_item=None, valuation_rate=0, warehouse=None, opening_stock=None):
	if not frappe.db.exists("Item", item_code):
		item = frappe.new_doc("Item")
		item.item_code = item_code
		item.item_name = item_code
		item.description = item_code
		item.item_group = "All Item Groups"
		item.is_stock_item = is_stock_item or 1
		item.opening_stock = opening_stock or 0
		item.valuation_rate = valuation_rate or 0.0
		item.append("item_defaults", {
			"default_warehouse": warehouse or '_Test Warehouse - _TC',
			"company": "_Test Company"
		})
Esempio n. 48
0
        "BOM", {
            "item": wo_order.production_item,
            "is_active": 1,
            "is_default": 1
        })
    wo_order.qty = args.qty or 10
    wo_order.wip_warehouse = args.wip_warehouse or "_Test Warehouse - _TC"
    wo_order.fg_warehouse = args.fg_warehouse or "_Test Warehouse 1 - _TC"
    wo_order.scrap_warehouse = args.fg_warehouse or "_Test Scrap Warehouse - _TC"
    wo_order.company = args.company or "_Test Company"
    wo_order.stock_uom = args.stock_uom or "_Test UOM"
    wo_order.use_multi_level_bom = 0
    wo_order.skip_transfer = args.skip_transfer or 0
    wo_order.get_items_and_operations_from_bom()
    wo_order.sales_order = args.sales_order or None
    wo_order.planned_start_date = args.planned_start_date or now()

    if args.source_warehouse:
        for item in wo_order.get("required_items"):
            item.source_warehouse = args.source_warehouse

    if not args.do_not_save:
        wo_order.insert()

        if not args.do_not_submit:
            wo_order.submit()
    return wo_order


test_records = frappe.get_test_records('Work Order')
# Copyright (c) 2013, Wayzon Technology Services Pvt Ltd and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Creditor Client')

class TestCreditorClient(unittest.TestCase):
	pass
Esempio n. 50
0
# License: MIT. See LICENSE
import json
import unittest
from unittest.mock import patch

import frappe
import frappe.exceptions
from frappe.core.doctype.user.user import (extract_mentions, reset_password,
                                           sign_up, test_password_strength,
                                           update_password, verify_password)
from frappe.frappeclient import FrappeClient
from frappe.model.delete_doc import delete_doc
from frappe.utils import get_url

user_module = frappe.core.doctype.user.user
test_records = frappe.get_test_records('User')


class TestUser(unittest.TestCase):
    def tearDown(self):
        # disable password strength test
        frappe.db.set_value("System Settings", "System Settings",
                            "enable_password_policy", 0)
        frappe.db.set_value("System Settings", "System Settings",
                            "minimum_password_score", "")
        frappe.db.set_value("System Settings", "System Settings",
                            "password_reset_limit", 3)
        frappe.set_user('Administrator')

    def test_user_type(self):
        new_user = frappe.get_doc(
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals


import frappe, unittest
test_records = frappe.get_test_records('Currency Exchange')

class TestCurrencyExchange(unittest.TestCase):
	def test_exchnage_rate(self):
		from erpnext.setup.utils import get_exchange_rate
		
		# Exchange rate as on 15th Jan, 2016, should be fetched from Currency Exchange record
		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
		self.assertEqual(exchange_rate, 60.0)
		
		# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
		exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15")
		self.assertFalse(exchange_rate==60)
		
Esempio n. 52
0

def create_pr_against_po(po, received_qty=4):
    pr = make_purchase_receipt(po)
    pr.get("items")[0].qty = received_qty
    pr.insert()
    pr.submit()
    return pr


def get_ordered_qty(item_code="_Test Item", warehouse="_Test Warehouse - _TC"):
    return flt(
        frappe.db.get_value("Bin", {
            "item_code": item_code,
            "warehouse": warehouse
        }, "ordered_qty"))


def get_requested_qty(item_code="_Test Item",
                      warehouse="_Test Warehouse - _TC"):
    return flt(
        frappe.db.get_value("Bin", {
            "item_code": item_code,
            "warehouse": warehouse
        }, "indented_qty"))


test_dependencies = ["BOM", "Item Price"]

test_records = frappe.get_test_records('Purchase Order')
Esempio n. 53
0
# Copyright (c) 2013, wayzon and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Add Color')

class TestAddColor(unittest.TestCase):
	pass
Esempio n. 54
0
# Copyright (c) 2013, wayzon and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Add Clothtype')


class TestAddClothtype(unittest.TestCase):
    pass
Esempio n. 55
0
		pi = make_purchase_invoice(po.name)

		self.assertEquals(pi.doctype, "Purchase Invoice")
		self.assertEquals(len(pi.get("entries", [])), len(test_records[0]["po_details"]))
		pi.posting_date = "2013-05-12"
		pi.bill_no = "NA"
		frappe.get_doc(pi).insert()

	def test_subcontracting(self):
		po = frappe.copy_doc(test_records[0])
		po.insert()
		self.assertEquals(len(po.get("po_raw_material_details")), 2)

	def test_warehouse_company_validation(self):
		from erpnext.stock.utils import InvalidWarehouseCompany
		po = frappe.copy_doc(test_records[0])
		po.company = "_Test Company 1"
		po.conversion_rate = 0.0167
		self.assertRaises(InvalidWarehouseCompany, po.insert)

	def test_uom_integer_validation(self):
		from erpnext.utilities.transaction_base import UOMMustBeIntegerError
		po = frappe.copy_doc(test_records[0])
		po.get("po_details")[0].qty = 3.4
		self.assertRaises(UOMMustBeIntegerError, po.insert)


test_dependencies = ["BOM"]

test_records = frappe.get_test_records('Purchase Order')
Esempio n. 56
0
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import frappe

test_records = frappe.get_test_records('Currency Exchange')
Esempio n. 57
0
# Copyright (c) 2013, GAM LTD and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Works')

class TestWorks(unittest.TestCase):
	pass
Esempio n. 58
0
# Copyright (c) 2013, New Indictrans Technologies Pvt. Ltd. and Contributors
# See license.txt

import frappe
import unittest

test_records = frappe.get_test_records('Zones')


class TestZones(unittest.TestCase):
    pass
Esempio n. 59
0
			 item_doc.save(ignore_permissions=True)

		item.uom = 'Kg'
		for item in mr.items:
			item.schedule_date = mr.schedule_date

		mr.insert()
		self.assertRaises(frappe.ValidationError, make_purchase_order,
			mr.name)

		mr = frappe.get_doc("Material Request", mr.name)
		mr.submit()
		item = mr.items[0]

		self.assertEquals(item.uom, "Kg")
		self.assertEquals(item.conversion_factor, 5.0)
		self.assertEquals(item.stock_qty, flt(item.qty * 5))

		po = make_purchase_order(mr.name)
		self.assertEquals(po.doctype, "Purchase Order")
		self.assertEquals(len(po.get("items")), len(mr.get("items")))

		po.supplier = '_Test Supplier'
		po.insert()
		po.submit()
		mr = frappe.get_doc("Material Request", mr.name)
		self.assertEquals(mr.per_ordered, 100)

test_dependencies = ["Currency Exchange", "BOM"]
test_records = frappe.get_test_records('Material Request')
Esempio n. 60
0
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import frappe

test_records = frappe.get_test_records('UOM')