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 = dataent.get_test_records(doctype)

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

		d = dataent.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 dataent.db.exists(d.doctype, d.name) and not reset:
			dataent.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 dataent.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)

		dataent.db.commit()
	return records
Esempio n. 2
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"):
		dataent.local.test_objects[doctype] += test_module._make_test_records(verbose)

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

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

		elif verbose:
			print_mandatory_fields(doctype)

	add_to_test_record_log(doctype)
Esempio n. 3
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals, print_function

import dataent
import unittest
import re

test_records = dataent.get_test_records('Print Format')

class TestPrintFormat(unittest.TestCase):
	def test_print_user(self, style=None):
		print_html = dataent.get_print("User", "Administrator", style=style)
		self.assertTrue("<label>First Name</label>" in print_html)
		self.assertTrue(re.findall('<div class="col-xs-7[^"]*">[\s]*administrator[\s]*</div>', print_html))
		return print_html

	def test_print_user_standard(self):
		print_html = self.test_print_user("Standard")
		self.assertTrue(re.findall('\.print-format {[\s]*font-size: 9pt;', print_html))
		self.assertFalse(re.findall('th {[\s]*background-color: #eee;[\s]*}', print_html))
		self.assertFalse("font-family: serif;" in print_html)

	def test_print_user_modern(self):
		print_html = self.test_print_user("Modern")
		self.assertTrue("/* modern format: for-test */" in print_html)

	def test_print_user_classic(self):
		print_html = self.test_print_user("Classic")
		self.assertTrue("/* classic format: for-test */" in print_html)
Esempio n. 4
0
# Copyright (c) 2015, Dataent 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 dataent
import dataent.defaults
import unittest
import json

from dataent.desk.doctype.event.event import get_events
from dataent.test_runner import make_test_objects

test_records = dataent.get_test_records('Event')


class TestEvent(unittest.TestCase):
    def setUp(self):
        dataent.db.sql('delete from tabEvent')
        make_test_objects('Event', reset=True)

        self.test_records = dataent.get_test_records('Event')
        self.test_user = "******"

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

    def test_allowed_public(self):
        dataent.set_user(self.test_user)
        doc = dataent.get_doc(
            "Event", dataent.db.get_value("Event",
Esempio n. 5
0
        self.assertEqual(po.doctype, "Purchase Order")
        self.assertEqual(len(po.get("items")), len(mr.get("items")))

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


def make_material_request(**args):
    args = dataent._dict(args)
    mr = dataent.new_doc("Material Request")
    mr.material_request_type = args.material_request_type or "Purchase"
    mr.company = args.company or "_Test Company"
    mr.append(
        "items", {
            "item_code": args.item_code or "_Test Item",
            "qty": args.qty or 10,
            "schedule_date": args.schedule_date or today(),
            "warehouse": args.warehouse or "_Test Warehouse - _TC"
        })
    mr.insert()
    if not args.do_not_submit:
        mr.submit()
    return mr


test_dependencies = ["Currency Exchange", "BOM"]
test_records = dataent.get_test_records('Material Request')
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 = dataent.get_test_records('Quotation')


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

    return {
        'doctype': 'Quotation',
        'party_name': party_name,
        'items': [{
            'item_code': item_code,
            'qty': 1,
            'rate': 100
Esempio n. 7
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
from dataent.model.rename_doc import rename_doc
from epaas.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from dataent.utils import cint
from epaas import set_perpetual_inventory
from dataent.test_runner import make_test_records
from epaas.accounts.doctype.account.test_account import get_inventory_account, create_account

import epaas
import dataent
import unittest
test_records = dataent.get_test_records('Warehouse')


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

    def test_parent_warehouse(self):
        parent_warehouse = dataent.get_doc("Warehouse",
                                           "_Test Warehouse Group - _TC")
        self.assertEqual(parent_warehouse.is_group, 1)

    def test_warehouse_hierarchy(self):
        p_warehouse = dataent.get_doc("Warehouse",
                                      "_Test Warehouse Group - _TC")

        child_warehouses = dataent.db.sql(
Esempio n. 8
0
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import dataent
import unittest
from epaas.accounts.doctype.tax_rule.tax_rule import IncorrectCustomerGroup, IncorrectSupplierType, ConflictingTaxRule, get_tax_template

test_records = dataent.get_test_records('Tax Rule')

from six import iteritems


class TestTaxRule(unittest.TestCase):
    def setUp(self):
        dataent.db.sql("delete from `tabTax Rule`")

    def tearDown(self):
        dataent.db.sql("delete from `tabTax Rule`")

    def test_conflict(self):
        tax_rule1 = make_tax_rule(
            customer="_Test Customer",
            sales_tax_template="_Test Sales Taxes and Charges Template - _TC",
            priority=1)
        tax_rule1.save()

        tax_rule2 = make_tax_rule(
            customer="_Test Customer",
            sales_tax_template="_Test Sales Taxes and Charges Template - _TC",
Esempio n. 9
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(
        dataent.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(
        dataent.db.get_value("Bin", {
            "item_code": item_code,
            "warehouse": warehouse
        }, "indented_qty"))


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

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


import dataent
test_records = dataent.get_test_records('Employment Type')
Esempio n. 11
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

test_ignore = ["Price List"]

import dataent
test_records = dataent.get_test_records('Customer Group')
Esempio n. 12
0
            rejected_qty,
            "rejected_warehouse":
            args.rejected_warehouse or "_Test Rejected Warehouse - _TC"
            if rejected_qty != 0 else "",
            "rate":
            args.rate or 50,
            "conversion_factor":
            args.conversion_factor or 1.0,
            "serial_no":
            args.serial_no,
            "stock_uom":
            args.stock_uom or "_Test UOM",
            "uom":
            args.uom or "_Test UOM",
            "cost_center":
            args.cost_center
            or dataent.get_cached_value('Company', pr.company, 'cost_center'),
            "asset_location":
            args.location or "Test Location"
        })

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


test_dependencies = ["BOM", "Item Price", "Location"]
test_records = dataent.get_test_records('Purchase Receipt')
Esempio n. 13
0
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Dataent Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import dataent, dataent.utils, dataent.utils.scheduler
import unittest

test_records = dataent.get_test_records('Notification')

test_dependencies = ["User"]


class TestNotification(unittest.TestCase):
    def setUp(self):
        dataent.db.sql("""delete from `tabEmail Queue`""")
        dataent.set_user("*****@*****.**")

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

    def test_new_and_save(self):
        communication = dataent.new_doc("Communication")
        communication.communication_type = 'Comment'
        communication.subject = "test"
        communication.content = "test"
        communication.insert(ignore_permissions=True)

        self.assertTrue(
            dataent.db.get_value(
                "Email Queue", {
Esempio n. 14
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import dataent
import unittest

test_records = dataent.get_test_records('Page')


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

from __future__ import unicode_literals
import dataent

# test_ignore = ["Item"]

test_records = dataent.get_test_records('Price List')
Esempio n. 16
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals
import dataent, json, os
import unittest

test_records = dataent.get_test_records('Report')


class TestReport(unittest.TestCase):
    def test_report_builder(self):
        if dataent.db.exists('Report', 'User Activity Report'):
            dataent.delete_doc('Report', 'User Activity Report')

        with open(
                os.path.join(os.path.dirname(__file__),
                             'user_activity_report.json'), 'r') as f:
            dataent.get_doc(json.loads(f.read())).insert()

        report = dataent.get_doc('Report', 'User Activity Report')
        columns, data = report.get_data()
        self.assertEqual(columns[0].get('label'), 'ID')
        self.assertEqual(columns[1].get('label'), 'User Type')
        self.assertTrue('Administrator' in [d[0] for d in data])

    def test_query_report(self):
        report = dataent.get_doc('Report', 'Permitted Documents For User')
        columns, data = report.get_data(filters={
            'user': '******',
            'doctype': 'DocType'
Esempio n. 17
0
    jv.posting_date = posting_date or nowdate()
    jv.company = "_Test Company"
    jv.user_remark = "test"
    jv.multi_currency = 1
    jv.set("accounts",
           [{
               "account": account1,
               "cost_center": cost_center,
               "project": project,
               "debit_in_account_currency": amount if amount > 0 else 0,
               "credit_in_account_currency": abs(amount) if amount < 0 else 0,
               "exchange_rate": exchange_rate
           }, {
               "account": account2,
               "cost_center": cost_center,
               "project": project,
               "credit_in_account_currency": amount if amount > 0 else 0,
               "debit_in_account_currency": abs(amount) if amount < 0 else 0,
               "exchange_rate": exchange_rate
           }])
    if save or submit:
        jv.insert()

        if submit:
            jv.submit()

    return jv


test_records = dataent.get_test_records('Journal Entry')
Esempio n. 18
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
import unittest
import json
from dataent import _
from dataent.utils import random_string
from epaas.accounts.doctype.account.chart_of_accounts.chart_of_accounts import get_charts_for_country

test_ignore = ["Account", "Cost Center", "Payment Terms Template", "Salary Component"]
test_dependencies = ["Fiscal Year"]
test_records = dataent.get_test_records('Company')

class TestCompany(unittest.TestCase):
	def test_coa_based_on_existing_company(self):
		company = dataent.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",
Esempio n. 19
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
test_records = dataent.get_test_records('Project')
test_ignore = ["Sales Order"]
Esempio n. 20
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
import unittest
from epaas.accounts.doctype.shipping_rule.shipping_rule import FromGreaterThanToError, ManyBlankToValuesError, OverlappingConditionError

test_records = dataent.get_test_records('Shipping Rule')


class TestShippingRule(unittest.TestCase):
    def test_from_greater_than_to(self):
        shipping_rule = dataent.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 = dataent.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. 21
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals
import dataent
import unittest

test_records = dataent.get_test_records('Website Theme')


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

import dataent
import unittest, json

from dataent.website.render import build_page
from dataent.website.doctype.web_form.web_form import accept

test_records = dataent.get_test_records('Web Form')

class TestWebForm(unittest.TestCase):
	def setUp(self):
		dataent.conf.disable_website_cache = True
		dataent.local.path = None

	def tearDown(self):
		dataent.conf.disable_website_cache = False
		dataent.local.path = None

	def test_basic(self):
		dataent.set_user("Guest")
		html = build_page("manage-events")
		self.assertTrue('<div class="login-required">' in html)

	def test_logged_in(self):
		dataent.set_user("Administrator")
		html = build_page("manage-events")
		self.assertFalse('<div class="login-required">' in html)
		self.assertTrue('"/manage-events?new=1"' in html)
Esempio n. 23
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals


import dataent
test_records = dataent.get_test_records('Designation')
Esempio n. 24
0
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Dataent Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import json
import unittest

import dataent

test_records = dataent.get_test_records('Location')


class TestLocation(unittest.TestCase):
    def runTest(self):
        locations = ['Basil Farm', 'Division 1', 'Field 1', 'Block 1']
        area = 0
        formatted_locations = []

        for location in locations:
            doc = dataent.get_doc('Location', location)
            doc.save()
            area += doc.area
            temp = json.loads(doc.location)
            temp['features'][0]['properties']['child_feature'] = True
            temp['features'][0]['properties']['feature_of'] = location
            formatted_locations.extend(temp['features'])

        test_location = dataent.get_doc('Location', 'Test Location Area')
        test_location.save()
Esempio n. 25
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
from __future__ import unicode_literals

import dataent
import unittest
from epaas.manufacturing.doctype.workstation.workstation import check_if_within_operating_hours, NotInWorkingHoursError, WorkstationHolidayError

test_dependencies = ["Warehouse"]
test_records = dataent.get_test_records('Workstation')


class TestWorkstation(unittest.TestCase):
    def test_validate_timings(self):
        check_if_within_operating_hours("_Test Workstation 1", "Operation 1",
                                        "2013-02-02 11:00:00",
                                        "2013-02-02 19:00:00")
        check_if_within_operating_hours("_Test Workstation 1", "Operation 1",
                                        "2013-02-02 10:00:00",
                                        "2013-02-02 20:00:00")
        self.assertRaises(NotInWorkingHoursError,
                          check_if_within_operating_hours,
                          "_Test Workstation 1", "Operation 1",
                          "2013-02-02 05:00:00", "2013-02-02 20:00:00")
        self.assertRaises(NotInWorkingHoursError,
                          check_if_within_operating_hours,
                          "_Test Workstation 1", "Operation 1",
                          "2013-02-02 05:00:00", "2013-02-02 20:00:00")
        self.assertRaises(WorkstationHolidayError,
                          check_if_within_operating_hours,
                          "_Test Workstation 1", "Operation 1",
Esempio n. 26
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
test_records = dataent.get_test_records('Holiday List')
Esempio n. 27
0
    def setUp(self):
        dataent.db.sql('delete from tabEvent')
        make_test_objects('Event', reset=True)

        self.test_records = dataent.get_test_records('Event')
        self.test_user = "******"
Esempio n. 28
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
test_records = dataent.get_test_records('Sales Partner')

test_ignore = ["Item Group"]
Esempio n. 29
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals

import dataent
test_records = dataent.get_test_records('Quotation Lost Reason')
Esempio n. 30
0
# Copyright (c) 2015, Dataent Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import dataent, unittest
from dataent.utils import flt
from epaas.setup.utils import get_exchange_rate

test_records = dataent.get_test_records('Currency Exchange')


def save_new_records(test_records):
	for record in test_records:
		kwargs = dict(
			doctype=record.get("doctype"),
			docname=record.get("date") + '-' + record.get("from_currency") + '-' + record.get("to_currency"),
			fieldname="exchange_rate",
			value=record.get("exchange_rate"),
		)

		try:
			dataent.set_value(**kwargs)
		except dataent.DoesNotExistError:
			curr_exchange = dataent.new_doc(record.get("doctype"))
			curr_exchange.date = record["date"]
			curr_exchange.from_currency = record["from_currency"]
			curr_exchange.to_currency = record["to_currency"]
			curr_exchange.exchange_rate = record["exchange_rate"]
			curr_exchange.insert()


class TestCurrencyExchange(unittest.TestCase):