[fix] test cases for limits change

This commit is contained in:
Anand Doshi 2016-06-25 19:07:21 +05:30
parent 17d9177c86
commit 571de33901
5 changed files with 17 additions and 10 deletions

View file

@ -104,9 +104,10 @@ class TestFile(unittest.TestCase):
update_limits({
'space': 1,
'space_usage': {
'files_size': (1024 * 1024),
'files_size': (1024 ** 2),
'database_size': 0,
'backup_size': 0
'backup_size': 0,
'total': (1024 ** 2)
}
})

View file

@ -11,6 +11,7 @@ from frappe import _dict
from frappe.limits import SiteExpiredError, update_limits, clear_limit
from frappe.utils import get_url
from frappe.installer import update_site_config
from frappe.core.doctype.user.user import MaxUsersReachedError
test_records = frappe.get_test_records('User')
@ -93,7 +94,7 @@ class TestUser(unittest.TestCase):
user.email = 'test_max_users@example.com'
user.first_name = 'Test_max_user'
self.assertRaises(frappe.utils.user.MaxUsersReachedError, user.add_roles, 'System Manager')
self.assertRaises(MaxUsersReachedError, user.add_roles, 'System Manager')
if frappe.db.exists('User', 'test_max_users@example.com'):
frappe.delete_doc('User', 'test_max_users@example.com')

View file

@ -159,7 +159,7 @@ def validate_space_limit(file_size):
file_size = file_size / (1024.0 ** 2)
if flt(usage.total + file_size, 2) > space_limit:
if flt(flt(usage.total) + file_size, 2) > space_limit:
# Stop from attaching file
frappe.throw(_("You have exceeded the max space of {0} for your plan. {1}.").format(
"<b>{0}MB</b>".format(cint(space_limit)) if (space_limit < 1024) else "<b>{0}GB</b>".format(limits.space),

View file

@ -61,6 +61,8 @@ class TestScheduler(TestCase):
user.save()
restrict_scheduler_events_if_dormant()
frappe.local.conf = _dict(frappe.get_site_config())
self.assertFalse("all" in get_enabled_scheduler_events())
self.assertTrue(frappe.conf.get('dormant', False))
@ -72,16 +74,18 @@ class TestScheduler(TestCase):
update_limits({'expiry': add_to_date(today(), days=-1)})
frappe.local.conf = _dict(frappe.get_site_config())
user = frappe.new_doc('User')
user.email = 'test_scheduler@example.com'
user.first_name = 'Test_scheduler'
user.add_roles('System Manager')
if not frappe.db.exists('User', 'test_scheduler@example.com'):
user = frappe.new_doc('User')
user.email = 'test_scheduler@example.com'
user.first_name = 'Test_scheduler'
user.save()
user.add_roles('System Manager')
frappe.db.commit()
frappe.set_user("test_scheduler@example.com")
disable_scheduler_on_expiry()
ss = frappe.get_doc("System Settings")
self.assertFalse(ss.enable_scheduler)

View file

@ -15,6 +15,7 @@ import json
import schedule
import time
import os
import MySQLdb
import frappe.utils
from frappe.utils import get_sites, get_site_path, touch_file
from datetime import datetime
@ -190,6 +191,7 @@ def toggle_scheduler(enable):
ss = frappe.get_doc("System Settings")
ss.enable_scheduler = 1 if enable else 0
ss.flags.ignore_mandatory = True
ss.flags.ignore_permissions = True
ss.save()
def enable_scheduler():
@ -272,7 +274,6 @@ def restrict_scheduler_events(*args, **kwargs):
val = json.dumps(["daily", "daily_long", "weekly", "weekly_long", "monthly", "monthly_long"])
frappe.db.set_global('enabled_scheduler_events', val)
def is_dormant(since = 345600):
last_active = get_datetime(get_last_active())
# Get now without tz info