Kaynağa Gözat

[minor] don't rollback when running all tests, fixed test cases

version-14
Anand Doshi 11 yıl önce
ebeveyn
işleme
b6d932a13f
10 değiştirilmiş dosya ile 49 ekleme ve 25 silme
  1. +1
    -1
      core/doctype/profile/profile.py
  2. +19
    -4
      core/doctype/profile/test_profile.py
  3. +1
    -1
      core/doctype/role/test_role.py
  4. +2
    -0
      webnotes/db.py
  5. +1
    -1
      webnotes/model/utils.py
  6. +14
    -10
      webnotes/test_runner.py
  7. +1
    -1
      webnotes/tests/test_db.py
  8. +5
    -2
      webnotes/tests/test_email.py
  9. +3
    -3
      webnotes/utils/__init__.py
  10. +2
    -2
      webnotes/utils/email_lib/bulk.py

+ 1
- 1
core/doctype/profile/profile.py Dosyayı Görüntüle

@@ -216,7 +216,7 @@ Thank you,<br>
# disable the user and log him/her out # disable the user and log him/her out
self.doc.enabled = 0 self.doc.enabled = 0
if webnotes.local.login_manager:
if getattr(webnotes.local, "login_manager", None):
webnotes.local.login_manager.logout(user=self.doc.name) webnotes.local.login_manager.logout(user=self.doc.name)
# delete their password # delete their password


+ 19
- 4
core/doctype/profile/test_profile.py Dosyayı Görüntüle

@@ -7,9 +7,9 @@ from webnotes.model.utils import delete_doc, LinkExistsError


class TestProfile(unittest.TestCase): class TestProfile(unittest.TestCase):
def test_delete(self): def test_delete(self):
self.assertRaises(LinkExistsError, delete_doc, "Role", "_Test Role")
webnotes.conn.sql("""delete from tabUserRole where role='_Test Role'""")
delete_doc("Role","_Test Role")
self.assertRaises(LinkExistsError, delete_doc, "Role", "_Test Role 2")
webnotes.conn.sql("""delete from tabUserRole where role='_Test Role 2'""")
delete_doc("Role","_Test Role 2")
profile = webnotes.bean(copy=test_records[1]) profile = webnotes.bean(copy=test_records[1])
profile.doc.email = "_test@example.com" profile.doc.email = "_test@example.com"
@@ -80,5 +80,20 @@ test_records = [[{
"email": "test2@example.com", "email": "test2@example.com",
"first_name": "_Test2", "first_name": "_Test2",
"new_password": "testpassword" "new_password": "testpassword"
}]
}],
[{
"doctype":"Profile",
"email": "testdelete@example.com",
"first_name": "_Test",
"new_password": "testpassword",
"enabled": 1
}, {
"doctype":"UserRole",
"parentfield":"user_roles",
"role": "_Test Role 2"
}, {
"doctype":"UserRole",
"parentfield":"user_roles",
"role": "System Manager"
}],
] ]

+ 1
- 1
core/doctype/role/test_role.py Dosyayı Görüntüle

@@ -1,4 +1,4 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# MIT License. See license.txt # MIT License. See license.txt


test_records = [[{"role_name":"_Test Role"}]]
test_records = [[{"role_name":"_Test Role"}], [{"role_name":"_Test Role 2"}]]

+ 2
- 0
webnotes/db.py Dosyayı Görüntüle

@@ -6,6 +6,7 @@


from __future__ import unicode_literals from __future__ import unicode_literals
import MySQLdb import MySQLdb
import warnings
import webnotes import webnotes
from webnotes import conf from webnotes import conf
import datetime import datetime
@@ -42,6 +43,7 @@ class Database:
""" """
Connect to a database Connect to a database
""" """
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password, self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password,
use_unicode=True, charset='utf8') use_unicode=True, charset='utf8')
self._conn.converter[246]=float self._conn.converter[246]=float


+ 1
- 1
webnotes/model/utils.py Dosyayı Görüntüle

@@ -200,7 +200,7 @@ def check_if_doc_is_linked(dt, dn, method="Delete"):
if not issingle: if not issingle:
item = webnotes.conn.get_value(link_dt, {link_field:dn}, item = webnotes.conn.get_value(link_dt, {link_field:dn},
["name", "parent", "parenttype", "docstatus"], as_dict=True) ["name", "parent", "parenttype", "docstatus"], as_dict=True)
if item and item.parent != dn and (method=="Delete" or if item and item.parent != dn and (method=="Delete" or
(method=="Cancel" and item.docstatus==1)): (method=="Cancel" and item.docstatus==1)):
webnotes.msgprint(method + " " + _("Error") + ":"+\ webnotes.msgprint(method + " " + _("Error") + ":"+\


+ 14
- 10
webnotes/test_runner.py Dosyayı Görüntüle

@@ -146,26 +146,28 @@ def run_unittest(doctype, verbose=False):
def run_all_tests(verbose): def run_all_tests(verbose):
import os import os


test_suite = unittest.TestSuite()
for path, folders, files in os.walk("."): for path, folders, files in os.walk("."):
# print path # print path
for filename in files: for filename in files:
filename = cstr(filename) filename = cstr(filename)
if filename.startswith("test_") and filename.endswith(".py"): if filename.startswith("test_") and filename.endswith(".py"):
print filename[:-3]
webnotes.session.user = "Administrator"
_run_test(path, filename, verbose)
# print filename[:-3]
webnotes.conn.rollback()
webnotes.test_objects = {}
_run_test(path, filename, verbose, test_suite=test_suite, run=False)
print
# webnotes.conn.rollback()
# webnotes.test_objects = {}


def _run_test(path, filename, verbose):
unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)

def _run_test(path, filename, verbose, test_suite=None, run=True):
import os, imp import os, imp
from webnotes.modules.utils import peval_doclist from webnotes.modules.utils import peval_doclist
test_suite = unittest.TestSuite()
if not test_suite:
test_suite = unittest.TestSuite()
if os.path.basename(os.path.dirname(path))=="doctype": if os.path.basename(os.path.dirname(path))=="doctype":
txt_file = os.path.join(path, filename[5:].replace(".py", ".txt")) txt_file = os.path.join(path, filename[5:].replace(".py", ".txt"))
with open(txt_file, 'r') as f: with open(txt_file, 'r') as f:
@@ -175,7 +177,9 @@ def _run_test(path, filename, verbose):
module = imp.load_source(filename[:-3], os.path.join(path, filename)) module = imp.load_source(filename[:-3], os.path.join(path, filename))
test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module)) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(module))
unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)
if run:
unittest.TextTestRunner(verbosity=1+(verbose and 1 or 0)).run(test_suite)


def main(): def main():
import argparse import argparse


+ 1
- 1
webnotes/tests/test_db.py Dosyayı Görüntüle

@@ -9,7 +9,7 @@ from webnotes.test_runner import make_test_records
class TestDB(unittest.TestCase): class TestDB(unittest.TestCase):
def test_get_value(self): def test_get_value(self):
webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""") webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""")
del webnotes.test_objects["Profile"]
make_test_records("Profile") make_test_records("Profile")
self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator") self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator")


+ 5
- 2
webnotes/tests/test_email.py Dosyayı Görüntüle

@@ -25,6 +25,7 @@ class TestEmail(unittest.TestCase):
def test_bulk(self): def test_bulk(self):
from webnotes.utils.email_lib.bulk import send from webnotes.utils.email_lib.bulk import send
send(recipients = ['test@example.com', 'test1@example.com'], send(recipients = ['test@example.com', 'test1@example.com'],
sender="admin@example.com",
doctype='Profile', email_field='email', doctype='Profile', email_field='email',
subject='Testing Bulk', message='This is a bulk mail!') subject='Testing Bulk', message='This is a bulk mail!')
@@ -45,7 +46,7 @@ class TestEmail(unittest.TestCase):
def test_unsubscribe(self): def test_unsubscribe(self):
from webnotes.utils.email_lib.bulk import unsubscribe, send from webnotes.utils.email_lib.bulk import unsubscribe, send
webnotes.form_dict = {
webnotes.local.form_dict = {
'email':'test@example.com', 'email':'test@example.com',
'type':'Profile', 'type':'Profile',
'email_field':'email', 'email_field':'email',
@@ -54,6 +55,7 @@ class TestEmail(unittest.TestCase):
unsubscribe() unsubscribe()


send(recipients = ['test@example.com', 'test1@example.com'], send(recipients = ['test@example.com', 'test1@example.com'],
sender="admin@example.com",
doctype='Profile', email_field='email', doctype='Profile', email_field='email',
subject='Testing Bulk', message='This is a bulk mail!') subject='Testing Bulk', message='This is a bulk mail!')
@@ -67,7 +69,8 @@ class TestEmail(unittest.TestCase):
def test_bulk_limit(self): def test_bulk_limit(self):
from webnotes.utils.email_lib.bulk import unsubscribe, send, BulkLimitCrossedError from webnotes.utils.email_lib.bulk import unsubscribe, send, BulkLimitCrossedError
self.assertRaises(BulkLimitCrossedError, send, self.assertRaises(BulkLimitCrossedError, send,
recipients=['test@example.com']*1000,
recipients=['test@example.com']*1000,
sender="admin@example.com",
doctype='Profile', email_field='email', doctype='Profile', email_field='email',
subject='Testing Bulk', message='This is a bulk mail!') subject='Testing Bulk', message='This is a bulk mail!')


+ 3
- 3
webnotes/utils/__init__.py Dosyayı Görüntüle

@@ -820,14 +820,14 @@ def get_base_path():
return os.path.dirname(os.path.abspath(conf.__file__)) return os.path.dirname(os.path.abspath(conf.__file__))
def get_site_base_path(sites_dir=None, hostname=None): def get_site_base_path(sites_dir=None, hostname=None):
if conf and not conf.sites_dir:
return get_base_path()
if not sites_dir: if not sites_dir:
sites_dir = conf.sites_dir sites_dir = conf.sites_dir
if not hostname: if not hostname:
hostname = conf.site hostname = conf.site
if not (sites_dir and hostname):
return get_base_path()


import os import os
return os.path.join(sites_dir, hostname) return os.path.join(sites_dir, hostname)


+ 2
- 2
webnotes/utils/email_lib/bulk.py Dosyayı Görüntüle

@@ -45,7 +45,7 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
})) }))
return updated return updated
if not recipients: recipients = [] if not recipients: recipients = []
if not sender or sender == "Administrator": if not sender or sender == "Administrator":
sender = webnotes.conn.get_value('Email Settings', None, 'auto_email_id') sender = webnotes.conn.get_value('Email Settings', None, 'auto_email_id')
@@ -79,7 +79,7 @@ def add(email, sender, subject, message, text_content=None, ref_doctype=None, re
try: try:
e.message = get_email(email, sender=e.sender, msg=message, subject=subject, e.message = get_email(email, sender=e.sender, msg=message, subject=subject,
text_content = text_content).as_string() text_content = text_content).as_string()
except webnotes.ValidationError, e:
except webnotes.ValidationError:
# bad email id - don't add to queue # bad email id - don't add to queue
return return


Yükleniyor…
İptal
Kaydet