def test_get_value(self): webnotes.conn.sql( """delete from `tabProfile` where name not in ('Administrator', 'Guest')""" ) make_test_records("Profile") self.assertEquals( webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator") self.assertEquals( webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator") self.assertEquals( webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator") from webnotes.utils import nowdate self.assertEquals( webnotes.conn.get_value("Profile", {"modified": ["<", nowdate()]}), "Administrator") self.assertEquals( webnotes.conn.get_value("Profile", {"modified": ["<=", nowdate()]}), "Administrator") self.assertEquals( webnotes.conn.get_value("Profile", {"modified": [">", nowdate()]}), "*****@*****.**") self.assertEquals( webnotes.conn.get_value("Profile", {"modified": [">=", nowdate()]}), "*****@*****.**")
def test_get_value(self): webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""") make_test_records("Profile") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator") from webnotes.utils import nowdate self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<", nowdate()]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<=", nowdate()]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": [">", nowdate()]}), "*****@*****.**") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": [">=", nowdate()]}), "*****@*****.**")
def test_merge(self): from webnotes.test_runner import make_test_records make_test_records("Sales Invoice") # clear transactions for new name webnotes.conn.sql("""delete from `tabSales Invoice` where customer='_Test Customer 1'""") # check if they exist self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), (("_Test Customer",),)) self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"), (("_Test Customer 1",),)) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), (("_Test Customer - _TC",),)) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer 1 - _TC"), (("_Test Customer 1 - _TC",),)) # check if transactions exists self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer'""", )[0][0], 0) self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer - _TC'""", )[0][0], 0) webnotes.rename_doc("Customer", "_Test Customer", "_Test Customer 1", merge=True) # check that no transaction exists for old name self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer 1'""", )[0][0], 0) self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer 1 - _TC'""", )[0][0], 0) # check that transactions exist for new name self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer'""", )[0][0], 0) self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer - _TC'""", )[0][0], 0) # check that old name doesn't exist self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), ()) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), ()) # create back _Test Customer webnotes.bean(copy=test_records[0]).insert()
def test_get_value(self): from webnotes.utils import now_datetime import time webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""") now = now_datetime() self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<", now]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<=", now]}), "Administrator") time.sleep(2) if "Profile" in webnotes.local.test_objects: del webnotes.local.test_objects["Profile"] make_test_records("Profile") self.assertEquals("*****@*****.**", webnotes.conn.get_value("Profile", {"modified": [">", now]})) self.assertEquals("*****@*****.**", webnotes.conn.get_value("Profile", {"modified": [">=", now]}))
def test_merge(self): from webnotes.test_runner import make_test_records make_test_records("Sales Invoice") # clear transactions for new name webnotes.conn.sql("""delete from `tabSales Invoice` where customer='_Test Customer 1'""") # check if they exist self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), (("_Test Customer",),)) self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer 1"), (("_Test Customer 1",),)) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), (("_Test Customer - _TC",),)) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer 1 - _TC"), (("_Test Customer 1 - _TC",),)) # check if transactions exists self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer'""", )[0][0], 0) self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer - _TC'""", )[0][0], 0) webnotes.rename_doc("Customer", "_Test Customer", "_Test Customer 1", merge=True) # check that no transaction exists for old name self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer 1'""", )[0][0], 0) self.assertNotEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer 1 - _TC'""", )[0][0], 0) # check that transactions exist for new name self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where customer='_Test Customer'""", )[0][0], 0) self.assertEquals(webnotes.conn.sql("""select count(*) from `tabSales Invoice` where debit_to='_Test Customer - _TC'""", )[0][0], 0) # check that old name doesn't exist self.assertEqual(webnotes.conn.exists("Customer", "_Test Customer"), ()) self.assertEqual(webnotes.conn.exists("Account", "_Test Customer - _TC"), ())
def test_get_value(self): from webnotes.utils import now_datetime import time webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""") now = now_datetime() self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<", now]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<=", now]}), "Administrator") time.sleep(2) if "Profile" in webnotes.test_objects: del webnotes.test_objects["Profile"] make_test_records("Profile") self.assertEquals("*****@*****.**", webnotes.conn.get_value("Profile", {"modified": [">", now]})) self.assertEquals("*****@*****.**", webnotes.conn.get_value("Profile", {"modified": [">=", now]}))
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # MIT License. See license.txt from __future__ import unicode_literals import os, sys import unittest, webnotes from webnotes.test_runner import make_test_records make_test_records("Profile") class TestEmail(unittest.TestCase): def setUp(self): webnotes.conn.sql("""update tabProfile set unsubscribed=0""") webnotes.conn.sql("""delete from `tabBulk Email`""") def test_send(self): from webnotes.utils.email_lib import sendmail #sendmail('*****@*****.**', subject='Test Mail', msg="Test Content") def test_bulk(self): from webnotes.utils.email_lib.bulk import send send(recipients = ['*****@*****.**', '*****@*****.**'], sender="*****@*****.**", doctype='Profile', email_field='email', subject='Testing Bulk', message='This is a bulk mail!') bulk = webnotes.conn.sql("""select * from `tabBulk Email` where status='Not Sent'""", as_dict=1) self.assertEquals(len(bulk), 2) self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk]) self.assertTrue('*****@*****.**' in [d['recipient'] for d in bulk])
def load_test_data(self): make_test_records("Company")
from __future__ import unicode_literals import os, sys sys.path.append('.') sys.path.append('lib/py') sys.path.append('erpnext') import unittest, webnotes from webnotes.test_runner import make_test_records make_test_records("Profile") class TestEmail(unittest.TestCase): def setUp(self): webnotes.conn.sql("""update tabProfile set unsubscribed=0""") webnotes.conn.sql("""delete from `tabBulk Email`""") def test_send(self): from webnotes.utils.email_lib import sendmail #sendmail('*****@*****.**', subject='Test Mail', msg="Test Content") def test_bulk(self): from webnotes.utils.email_lib.bulk import send send(recipients=['*****@*****.**', '*****@*****.**'], doctype='Profile', email_field='email', subject='Testing Bulk', message='This is a bulk mail!') bulk = webnotes.conn.sql(
test_records = [ [{ "doctype": "Leave Allocation", "leave_type": "_Test Leave Type", "fiscal_year": "_Test Fiscal Year", "employee":"_T-Employee-0001", "new_leaves_allocated": 15, "docstatus": 1 }], [{ "doctype": "Leave Application", "leave_type": "_Test Leave Type", "from_date": "2013-05-01", "to_date": "2013-05-05", "posting_date": "2013-01-02", "fiscal_year": "_Test Fiscal Year", "employee": "_T-Employee-0001" }]] if __name__=="__main__": sys.path.extend(["app", "lib"]) import webnotes webnotes.connect() from webnotes.test_runner import make_test_records make_test_records("Leave Application") unittest.main()