def _set_limits(context, site, limits): import datetime if not limits: return if not site: site = get_site(context) with frappe.init_site(site): frappe.connect() new_limits = {} for limit, value in limits: if limit not in ('daily_emails', 'emails', 'space', 'users', 'email_group', 'currency', 'expiry', 'support_email', 'support_chat', 'upgrade_url', 'subscription_id', 'subscription_type', 'current_plan', 'subscription_base_price', 'upgrade_plan', 'upgrade_base_price', 'cancellation_url'): frappe.throw(_('Invalid limit {0}').format(limit)) if limit=='expiry' and value: try: datetime.datetime.strptime(value, '%Y-%m-%d') except ValueError: raise ValueError("Incorrect data format, should be YYYY-MM-DD") elif limit in ('space', 'subscription_base_price', 'upgrade_base_price'): value = float(value) elif limit in ('users', 'emails', 'email_group', 'daily_emails'): value = int(value) new_limits[limit] = value update_limits(new_limits)
def test_site_expiry(self): user = frappe.get_doc('User', '*****@*****.**') user.enabled = 1 user.new_password = '******' user.save() update_limits({ 'expiry': add_to_date(today(), days=-1), 'support_email': '*****@*****.**' }) frappe.local.conf = _dict(frappe.get_site_config()) frappe.db.commit() res = requests.post(get_url(), params={ 'cmd': 'login', 'usr': '******', 'pwd': 'Eastern_43A1W', 'device': 'desktop' }) # While site is expired status code returned is 417 Failed Expectation self.assertEqual(res.status_code, 417) clear_limit("expiry") frappe.local.conf = _dict(frappe.get_site_config())
def _set_limits(context, site, limits): import datetime if not limits: return if not site: site = get_site(context) with frappe.init_site(site): frappe.connect() new_limits = {} for limit, value in limits: if limit not in ('daily_emails', 'emails', 'space', 'users', 'email_group', 'expiry', 'support_email', 'support_chat', 'upgrade_url'): frappe.throw(_('Invalid limit {0}').format(limit)) if limit=='expiry' and value: try: datetime.datetime.strptime(value, '%Y-%m-%d') except ValueError: raise ValueError("Incorrect data format, should be YYYY-MM-DD") elif limit=='space': value = float(value) elif limit in ('users', 'emails', 'email_group', 'daily_emails'): value = int(value) new_limits[limit] = value update_limits(new_limits)
def test_deactivate_additional_users(self): update_limits({'users': get_total_users() + 1}) if not frappe.db.exists( "User", "*****@*****.**"): user = frappe.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test Deactivate Additional Users' user.add_roles("System Manager") #update limits update_limits({"users": get_total_users() - 1}) self.assertEqual( frappe.db.get_value( "User", "*****@*****.**", "enabled"), 0) if frappe.db.exists("User", "*****@*****.**"): delete_contact('*****@*****.**') frappe.delete_doc('User', '*****@*****.**') # Clear the user limit clear_limit('users')
def _set_limits(context, site, limits): import datetime if not limits: return if not site: site = get_site(context) with frappe.init_site(site): new_limits = {} for limit, value in limits: if limit not in ('emails', 'space', 'users', 'email_group', 'expiry', 'support_email', 'support_chat', 'upgrade_url'): frappe.throw('Invalid limit {0}'.format(limit)) if limit == 'expiry': try: datetime.datetime.strptime(value, '%Y-%m-%d') except ValueError: raise ValueError( "Incorrect data format, should be YYYY-MM-DD") elif limit == 'space': value = float(value) elif limit in ('users', 'emails', 'email_group'): value = int(value) new_limits[limit] = value update_limits(new_limits)
def test_site_expiry(self): update_limits({'expiry': add_to_date(today(), days=-1)}) frappe.local.conf = _dict(frappe.get_site_config()) frappe.db.commit() res = requests.post(get_url(), params={'cmd': 'login', 'usr': '******', 'pwd': 'testpassword', 'device': 'desktop'}) # While site is expired status code returned is 417 Failed Expectation self.assertEqual(res.status_code, 417) clear_limit("expiry") frappe.local.conf = _dict(frappe.get_site_config())
def test_site_expiry(self): update_limits({"expiry": add_to_date(today(), days=-1)}) frappe.local.conf = _dict(frappe.get_site_config()) frappe.db.commit() res = requests.post( get_url(), params={"cmd": "login", "usr": "******", "pwd": "testpassword", "device": "desktop"} ) # While site is expired status code returned is 417 Failed Expectation self.assertEqual(res.status_code, 417) clear_limit("expiry") frappe.local.conf = _dict(frappe.get_site_config())
def test_user_limit_for_site_with_simultaneous_sessions(self): clear_limit('users') # make sure this user counts user = frappe.get_doc('User', '*****@*****.**') user.add_roles('Website Manager') user.save() update_limits({'users': get_total_users()}) user.simultaneous_sessions = user.simultaneous_sessions + 1 self.assertRaises(MaxUsersReachedError, user.save) # Clear the user limit clear_limit('users')
def test_deactivate_additional_users(self): update_limits({'users': get_total_users()+1}) if not frappe.db.exists("User", "*****@*****.**"): user = frappe.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test Deactivate Additional Users' user.add_roles("System Manager") #update limits update_limits({"users": get_total_users()-1}) self.assertEqual(frappe.db.get_value("User", "*****@*****.**", "enabled"), 0) if frappe.db.exists("User", "*****@*****.**"): frappe.delete_doc('User', '*****@*****.**') # Clear the user limit clear_limit('users')
def test_user_limit_for_site(self): update_limits({'users': get_total_users()}) # reload site config from frappe import _dict frappe.local.conf = _dict(frappe.get_site_config()) # Create a new user user = frappe.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test_max_user' self.assertRaises(MaxUsersReachedError, user.add_roles, 'System Manager') if frappe.db.exists('User', '*****@*****.**'): frappe.delete_doc('User', '*****@*****.**') # Clear the user limit clear_limit('users')
def test_site_expiry(self): user = frappe.get_doc('User', '*****@*****.**') user.enabled = 1 user.new_password = '******' user.save() update_limits({'expiry': add_to_date(today(), days=-1), 'support_email': '*****@*****.**'}) frappe.local.conf = _dict(frappe.get_site_config()) frappe.db.commit() res = requests.post(get_url(), params={'cmd': 'login', 'usr': '******', 'pwd': 'Eastern_43A1W', 'device': 'desktop'}) # While site is expired status code returned is 417 Failed Expectation self.assertEqual(res.status_code, 417) clear_limit("expiry") frappe.local.conf = _dict(frappe.get_site_config())
def test_disable_scheduler_on_expiry(self): update_limits({'expiry': add_to_date(today(), days=-1)}) frappe.local.conf = _dict(frappe.get_site_config()) if not frappe.db.exists('User', '*****@*****.**'): user = frappe.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test_scheduler' user.save() user.add_roles('System Manager') frappe.db.commit() frappe.set_user("*****@*****.**") disable_scheduler_on_expiry() ss = frappe.get_doc("System Settings") self.assertFalse(ss.enable_scheduler) clear_limit("expiry") frappe.local.conf = _dict(frappe.get_site_config())
def test_user_limit_for_site(self): from frappe.core.doctype.user.user import get_total_users update_limits({"users": get_total_users()}) # reload site config from frappe import _dict frappe.local.conf = _dict(frappe.get_site_config()) # Create a new user user = frappe.new_doc("User") user.email = "*****@*****.**" user.first_name = "Test_max_user" self.assertRaises(MaxUsersReachedError, user.add_roles, "System Manager") if frappe.db.exists("User", "*****@*****.**"): frappe.delete_doc("User", "*****@*****.**") # Clear the user limit clear_limit("users")
def test_file_upload_limit(self): from frappe.core.doctype.file.file import MaxFileSizeReachedError from frappe.limits import update_limits, clear_limit from frappe import _dict update_limits({ 'space': 1, 'space_usage': { 'files_size': (1024**2), 'database_size': 0, 'backup_size': 0, 'total': (1024**2) } }) # Rebuild the frappe.local.conf to take up the changes from site_config frappe.local.conf = _dict(frappe.get_site_config()) _file = frappe.get_doc({ "doctype": "File", "file_name": "_test_max_space.txt", "attached_to_name": "", "attached_to_doctype": "", "folder": self.get_folder("Test Folder 2", "Home").name, "content": "This file tests for max space usage" }) self.assertRaises(MaxFileSizeReachedError, _file.save) # Scrub the site_config and rebuild frappe.local.conf clear_limit("space") frappe.local.conf = _dict(frappe.get_site_config())
def test_file_upload_limit(self): from frappe.utils.file_manager import MaxFileSizeReachedError from frappe.limits import update_limits, clear_limit from frappe import _dict update_limits({ 'space': 1, 'space_usage': { 'files_size': (1024 ** 2), 'database_size': 0, 'backup_size': 0, 'total': (1024 ** 2) } }) # Rebuild the frappe.local.conf to take up the changes from site_config frappe.local.conf = _dict(frappe.get_site_config()) self.assertRaises(MaxFileSizeReachedError, save_file, '_test_max_space.txt', 'This files test for max space usage', "", "", self.get_folder("Test Folder 2", "Home").name) # Scrub the site_config and rebuild frappe.local.conf clear_limit("space") frappe.local.conf = _dict(frappe.get_site_config())
def execute(): limits = get_limits() if limits and limits.upgrade_link: upgrade_url = limits.upgrade_link clear_limit('upgrade_link') update_limits({'upgrade_url': upgrade_url})