def test_file_upload_limit(self): from dataent.utils.file_manager import MaxFileSizeReachedError from dataent.limits import update_limits, clear_limit from dataent import _dict update_limits({ 'space': 1, 'space_usage': { 'files_size': (1024**2), 'database_size': 0, 'backup_size': 0, 'total': (1024**2) } }) # Rebuild the dataent.local.conf to take up the changes from site_config dataent.local.conf = _dict(dataent.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 dataent.local.conf clear_limit("space") dataent.local.conf = _dict(dataent.get_site_config())
def test_user_limit_for_site_with_simultaneous_sessions(self): clear_limit('users') # make sure this user counts user = dataent.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 dataent.db.exists("User", "*****@*****.**"): user = dataent.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(dataent.db.get_value("User", "*****@*****.**", "enabled"), 0) if dataent.db.exists("User", "*****@*****.**"): delete_contact('*****@*****.**') dataent.delete_doc('User', '*****@*****.**') # Clear the user limit clear_limit('users')
def test_site_expiry(self): user = dataent.get_doc('User', '*****@*****.**') user.enabled = 1 user.new_password = '******' user.save() update_limits({'expiry': add_to_date(today(), days=-1), 'support_email': '*****@*****.**'}) dataent.local.conf = _dict(dataent.get_site_config()) dataent.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") dataent.local.conf = _dict(dataent.get_site_config())
def test_user_limit_for_site(self): update_limits({'users': get_total_users()}) # reload site config from dataent import _dict dataent.local.conf = _dict(dataent.get_site_config()) # Create a new user user = dataent.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test_max_user' self.assertRaises(MaxUsersReachedError, user.add_roles, 'System Manager') if dataent.db.exists('User', '*****@*****.**'): delete_contact('*****@*****.**') dataent.delete_doc('User', '*****@*****.**') # Clear the user limit clear_limit('users')
def test_disable_scheduler_on_expiry(self): update_limits({'expiry': add_to_date(today(), days=-1)}) dataent.local.conf = _dict(dataent.get_site_config()) if not dataent.db.exists('User', '*****@*****.**'): user = dataent.new_doc('User') user.email = '*****@*****.**' user.first_name = 'Test_scheduler' user.save() user.add_roles('System Manager') dataent.db.commit() dataent.set_user("*****@*****.**") disable_scheduler_on_expiry() ss = dataent.get_doc("System Settings") self.assertFalse(ss.enable_scheduler) clear_limit("expiry") dataent.local.conf = _dict(dataent.get_site_config())
def _set_limits(context, site, limits): import datetime if not limits: return if not site: site = get_site(context) with dataent.init_site(site): dataent.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'): dataent.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 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})