Skip to content

Commit

Permalink
started client side testing using selenium and other related and unre…
Browse files Browse the repository at this point in the history
…lated fixes
  • Loading branch information
rmehta committed Apr 30, 2014
1 parent e16c823 commit 487a4fe
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 125 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ install:

script:
cd ./test_sites/ &&
frappe --reinstall test_site &&
frappe -b test_site &&
frappe --verbose --run_tests test_site
frappe --use test_site &&
frappe --reinstall &&
frappe -b &&
frappe --verbose --run_tests

before_script:
- mysql -e 'create database travis' &&
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('travis') WHERE user='travis';\nFLUSH PRIVILEGES;\n" | mysql -u root
- mysql -e 'create database test_site' &&
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('test_site') WHERE user='test_site';\nFLUSH PRIVILEGES;\n" | mysql -u root

24 changes: 18 additions & 6 deletions frappe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from __future__ import unicode_literals
import os

import time
import subprocess
import frappe

site_arg_optional = ['serve', 'build', 'watch', 'celery', 'resize_images']
Expand Down Expand Up @@ -342,7 +343,6 @@ def update(remote=None, branch=None, reload_gunicorn=False):
build()
latest()
if reload_gunicorn:
import subprocess
subprocess.check_output("killall -HUP gunicorn".split())

@cmd
Expand Down Expand Up @@ -703,11 +703,23 @@ def smtp_debug_server():
@cmd
def run_tests(app=None, module=None, doctype=None, verbose=False, tests=()):
import frappe.test_runner
ret = frappe.test_runner.main(app and app[0], module and module[0], doctype and doctype[0], verbose,
tests=tests)
frappe.local.localhost = "http://localhost:8888"
pipe = subprocess.Popen(["frappe", "--serve", "--port", "8888"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while not pipe.stderr.readline():
time.sleep(1)
if verbose:
print "Test server started"

ret = 1
try:
ret = frappe.test_runner.main(app and app[0], module and module[0], doctype and doctype[0], verbose,
tests=tests)
if len(ret.failures) == 0 and len(ret.errors) == 0:
ret = 0
finally:
pipe.terminate()

if len(ret.failures) > 0 or len(ret.errors) > 0:
return 1
return ret

@cmd
def serve(port=8000, profile=False, sites_path='.', site=None):
Expand Down
79 changes: 39 additions & 40 deletions frappe/core/doctype/customize_form/test_customize_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,41 @@ def insert_custom_field(self):
"options": "\nCustom 1\nCustom 2\nCustom 3",
"default": "Custom 3"
}).insert()

def delete_custom_field(self):
frappe.delete_doc("Custom Field", "User-test_custom_field")


def setUp(self):
self.insert_custom_field()
frappe.db.commit()
frappe.clear_cache(doctype="User")

def tearDown(self):
self.delete_custom_field()
frappe.delete_doc("Custom Field", "User-test_custom_field")
frappe.db.commit()
frappe.clear_cache(doctype="User")

def get_customize_form(self, doctype=None):
d = frappe.get_doc("Customize Form")
if doctype:
d.doc_type = doctype
d.run_method("fetch_to_customize")
return d

def test_fetch_to_customize(self):
d = self.get_customize_form()
self.assertEquals(d.doc_type, None)
self.assertEquals(len(d.get("customize_form_fields")), 0)

d = self.get_customize_form("Event")
self.assertEquals(d.doc_type, "Event")
self.assertEquals(len(d.get("customize_form_fields")), 30)

d = self.get_customize_form("User")
self.assertEquals(d.doc_type, "User")
self.assertEquals(len(d.get("customize_form_fields")), 53)
self.assertEquals(d.get("customize_form_fields")[-1].fieldname, "test_custom_field")
self.assertEquals(d.get("customize_form_fields", {"fieldname": "location"})[0].in_list_view, 1)

return d

def test_save_customization_idx(self):
d = self.get_customize_form("User")
original_sequence = [df.fieldname for df in d.get("customize_form_fields")]
Expand All @@ -64,67 +63,67 @@ def test_save_customization_idx(self):
d.append("customize_form_fields", location_field)
d.run_method("save_customization")
frappe.clear_cache(doctype=d.doc_type)
property_setter_name, _idx = frappe.db.get_value("Property Setter",

property_setter_name, _idx = frappe.db.get_value("Property Setter",
{"doc_type": d.doc_type, "property": "_idx"}, ("name", "value"))
self.assertTrue(_idx)

_idx = json.loads(_idx)
for i, df in enumerate(frappe.get_meta(d.doc_type).get("fields")):
self.assertEquals(_idx[i], df.fieldname)

frappe.delete_doc("Property Setter", property_setter_name)
frappe.clear_cache(doctype=d.doc_type)

for i, df in enumerate(frappe.get_meta(d.doc_type).get("fields")):
self.assertEquals(original_sequence[i], df.fieldname)

def test_save_customization_property(self):
d = self.get_customize_form("User")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "allow_copy"}, "value"), None)

d.allow_copy = 1
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "allow_copy"}, "value"), '1')

d.allow_copy = 0
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "allow_copy"}, "value"), None)

def test_save_customization_field_property(self):
d = self.get_customize_form("User")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), None)

location_field = d.get("customize_form_fields", {"fieldname": "location"})[0]
location_field.reqd = 1
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), '1')

location_field = d.get("customize_form_fields", {"fieldname": "location"})[0]
location_field.reqd = 0
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Property Setter",
self.assertEquals(frappe.db.get_value("Property Setter",
{"doc_type": "User", "property": "reqd", "field_name": "location"}, "value"), '0')

def test_save_customization_custom_field_property(self):
d = self.get_customize_form("User")
self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), None)

custom_field = d.get("customize_form_fields", {"fieldname": "test_custom_field"})[0]
custom_field.reqd = 1
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 1)

custom_field = d.get("customize_form_fields", {"is_custom_field": True})[0]
custom_field.reqd = 0
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Custom Field", "User-test_custom_field", "reqd"), 0)

def test_save_customization_new_field(self):
d = self.get_customize_form("User")
d.append("customize_form_fields", {
Expand All @@ -133,30 +132,30 @@ def test_save_customization_new_field(self):
"__islocal": 1
})
d.run_method("save_customization")
self.assertEquals(frappe.db.get_value("Custom Field",
self.assertEquals(frappe.db.get_value("Custom Field",
"User-test_add_custom_field_via_customize_form", "fieldtype"), "Data")

frappe.delete_doc("Custom Field", "User-test_add_custom_field_via_customize_form")
self.assertEquals(frappe.db.get_value("Custom Field",
self.assertEquals(frappe.db.get_value("Custom Field",
"User-test_add_custom_field_via_customize_form"), None)

def test_save_customization_remove_field(self):
d = self.get_customize_form("User")
custom_field = d.get("customize_form_fields", {"fieldname": "test_custom_field"})[0]
d.get("customize_form_fields").remove(custom_field)
d.run_method("save_customization")

self.assertEquals(frappe.db.get_value("Custom Field", custom_field.name), None)

frappe.local.test_objects["Custom Field"] = []
make_test_records_for_doctype("Custom Field")

def test_reset_to_defaults(self):
d = frappe.get_doc("Customize Form")
d.doc_type = "User"
d.run_method('reset_to_defaults')

self.assertEquals(d.get("customize_form_fields", {"fieldname": "location"})[0].in_list_view, None)

frappe.local.test_objects["Property Setter"] = []
make_test_records_for_doctype("Property Setter")
1 change: 1 addition & 0 deletions frappe/core/doctype/user/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class TestUser(unittest.TestCase):
def test_delete(self):
frappe.get_doc("User", "[email protected]").add_roles("_Test Role 2")
self.assertRaises(frappe.LinkExistsError, delete_doc, "Role", "_Test Role 2")
frappe.db.sql("""delete from tabUserRole where role='_Test Role 2'""")
delete_doc("Role","_Test Role 2")
Expand Down
3 changes: 0 additions & 3 deletions frappe/core/doctype/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ def autoname(self):
self.email = self.email.strip()
self.name = self.email

if frappe.db.exists("User", self.name):
throw(_("Name Exists"))

def validate(self):
self.in_insert = self.get("__islocal")
if self.name not in STANDARD_USERS:
Expand Down
7 changes: 3 additions & 4 deletions frappe/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def sql_ddl(self, query, values=()):
self.sql(query)

def check_transaction_status(self, query):
if not frappe.flags.in_test and self.transaction_writes and \
if self.transaction_writes and \
query and query.strip().split()[0].lower() in ['start', 'alter', 'drop', 'create', "begin"]:
raise Exception, 'This statement can cause implicit commit'

Expand All @@ -169,7 +169,7 @@ def check_transaction_status(self, query):

if query[:6].lower() in ['update', 'insert']:
self.transaction_writes += 1
if not frappe.flags.in_test and self.transaction_writes > 10000:
if self.transaction_writes > 10000:
if self.auto_commit_on_many_writes:
frappe.db.commit()
else:
Expand Down Expand Up @@ -469,8 +469,7 @@ def begin(self):
return # not required

def commit(self):
if not frappe.flags.in_test:
self.sql("commit")
self.sql("commit")
frappe.local.rollback_observers = []

def rollback(self):
Expand Down
2 changes: 2 additions & 0 deletions frappe/hooks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ scheduler_event:daily = frappe.core.doctype.notification_count.notification_coun
scheduler_event:daily = frappe.core.doctype.event.event.send_event_digest
scheduler_event:hourly = frappe.templates.generators.website_group.clear_event_cache

before_tests = frappe.utils.install.before_tests

# TODO
# on_session_creation = frappe.auth.notify_administrator_login

Expand Down
9 changes: 3 additions & 6 deletions frappe/public/js/frappe/form/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,11 @@ frappe.ui.form.ControlSelect = frappe.ui.form.ControlData.extend({
if(!this.frm) return;
var fl = frappe.model.docinfo[this.frm.doctype][this.frm.docname];
if(fl && fl.attachments) {
fl = fl.attachments;
this.set_description("");
var options = [""];
for(var fname in fl) {
if(fname.indexOf("/")===-1)
fname = "files/" + fname;
options.push(fname);
}
$.each(fl.attachments, function(i, f) {
options.push(f.file_url)
});
return options;
} else {
this.set_description(__("Please attach a file first."))
Expand Down
4 changes: 2 additions & 2 deletions frappe/public/js/frappe/ui/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ frappe.ui.toolbar.Toolbar = Class.extend({
<li><a href="http://frappe.io/apps" target="_blank">\
<i class="icon-fixed-width icon-file"></i> '+__('Documentation')+'</a></li> \
<li><a href="http://frappe.io/getting-help" target="_blank">\
<i class="icon-fixed-width icon-file"></i> '+__('Forums')+'</a></li> \
<i class="icon-fixed-width icon-question-sign"></i> '+__('Forums')+'</a></li> \
<li><a href="http://github.com/frappe/erpnext/issues" target="_blank">\
<i class="icon-fixed-width icon-file"></i> '+__('Report an Issue')+'</a></li> \
<i class="icon-fixed-width icon-warning-sign"></i> '+__('Report an Issue')+'</a></li> \
<li class="divider"></li> \
<li><a href="#" onclick="return frappe.ui.toolbar.clear_cache();">\
<i class="icon-fixed-width icon-refresh"></i> '
Expand Down
Loading

0 comments on commit 487a4fe

Please sign in to comment.