How to use create_setting method in lisa

Best Python code snippet using lisa_python

settings.py

Source:settings.py Github

copy

Full Screen

...22logger = logging.getLogger(__name__)23# This settings, which are not set in the view, are saved in MongoDB collection24EXCLUDE_SETTINGS = ['maintenance_mode']25# Create a setting from the default values26def create_setting(key):27 default_settings = get_current_registry().settings28 setting = Setting()29 setting.key = key30 if key == "update_error_interval":31 appstruct = {'key': key, 'type': 'number',32 'value': default_settings.get('update_error_interval')}33 elif key == "repositories":34 appstruct = {'key': key, 'type': 'URLs',35 'value': default_settings.get('repositories')}36 elif key == "printers.urls":37 appstruct = {'key': key, 'type': 'URLs',38 'value': default_settings.get('printers.urls')}39 elif key == "mimetypes":40 appstruct = {'key': key, 'type': 'Mimetypes',41 'value': default_settings.get(key)}42 else:43 appstruct = {'key': key, 'type': 'string',44 'value': default_settings.get(key)}45 return Setting().serialize(appstruct)46@view_config(route_name='settings', renderer='templates/settings.jinja2',47 permission='is_superuser')48def settings(_context, request):49 settings_data_count = request.db.settings.count_documents(50 {'key':{'$nin': EXCLUDE_SETTINGS}})51 result = []52 if settings_data_count == 0:53 # If there aren't settings in the database then load the default values54 55 # firstboot_api.comments56 result.append(create_setting("firstboot_api.comments"))57 58 # firstboot_api.organization_name59 result.append(create_setting("firstboot_api.organization_name"))60 61 # firstboot_api.version62 result.append(create_setting("firstboot_api.version"))63 # update_error_interval64 result.append(create_setting("update_error_interval"))65 66 # repositories67 result.append(create_setting("repositories"))68 69 # printers.urls70 result.append(create_setting("printers.urls"))71 72 # mimetypes73 result.append(create_setting("mimetypes"))74 75 76 else:77 includesMimeTypes = False78 settings_data = request.db.settings.find(79 {'key':{'$nin': EXCLUDE_SETTINGS}}).sort(80 [("type", pymongo.DESCENDING), ("key", pymongo.ASCENDING)])81 82 for setting in settings_data:83 if setting['key'] == "mimetypes":84 includesMimeTypes = True85 result.append(Setting().deserialize(setting))86 else:87 result.append(Setting().deserialize(setting))88 89 if not includesMimeTypes:90 result.append(create_setting("mimetypes"))91 #logger.debug('settings= %s'%(str(result)))92 return { "settings": result }93@view_config(route_name='settings_save', permission='is_superuser')94def settings_save(_context, request):95 data = request.POST.get('data')96 response = Response()97 if data is not None:98 data = json.loads(data)99 for key in data:100 k = key.replace("___", ".")101 setting_data = request.db.settings.find_one({"key": k })102 if setting_data is None:103 setting = create_setting(k)104 else:105 setting = Setting().deserialize(setting_data)106 107 if isinstance(data[key], str):108 Setting().set_value(setting, 'value', data[key])109 else:110 Setting().set_value(setting, 'value', json.dumps(data[key]))111 112 # Save in mongoDB113 obj = Setting().serialize(setting)114 if obj['_id'] == colander.null:115 del obj['_id']116 request.db.settings.insert_one(obj)117 else:...

Full Screen

Full Screen

test_settings.py

Source:test_settings.py Github

copy

Full Screen

...5# cacerts is readOnly, and should not be able to be set through the API6def test_create_read_only(admin_mc, remove_resource):7 client = admin_mc.client8 with pytest.raises(ApiError) as e:9 client.create_setting(name="cacerts", value="a")10 assert e.value.error.status == 40511 assert "readOnly" in e.value.error.message12# cacerts is readOnly setting, and should not be able to be updated through API13def test_update_read_only(admin_mc, remove_resource):14 client = admin_mc.client15 with pytest.raises(ApiError) as e:16 client.update_by_id_setting(id="cacerts", value="b")17 assert e.value.error.status == 40518 assert "readOnly" in e.value.error.message19# cacerts is readOnly, and should be able to be read20def test_get_read_only(admin_mc, remove_resource):21 client = admin_mc.client22 client.by_id_setting(id="cacerts")23# cacerts is readOnly, and user should not be able to delete24def test_delete_read_only(admin_mc, remove_resource):25 client = admin_mc.client26 setting = client.by_id_setting(id="cacerts")27 with pytest.raises(ApiError) as e:28 client.delete(setting)29 assert e.value.error.status == 40530 assert "readOnly" in e.value.error.message31# user should be able to create a setting that does not exist yet32def test_create(admin_mc, remove_resource):33 client = admin_mc.client34 setting = client.create_setting(name="samplesetting1", value="a")35 remove_resource(setting)36 assert setting.value == "a"37# user should not be able to create a setting if it already exists38def test_create_existing(admin_mc, remove_resource):39 client = admin_mc.client40 setting = client.create_setting(name="samplefsetting2", value="a")41 remove_resource(setting)42 with pytest.raises(ApiError) as e:43 setting2 = client.create_setting(name="samplefsetting2", value="a")44 remove_resource(setting2)45 assert e.value.error.status == 40946 assert e.value.error.code == "AlreadyExists"47# user should be able to update a setting if it exists48def test_update(admin_mc, remove_resource):49 client = admin_mc.client50 setting = client.create_setting(name="samplesetting3", value="a")51 remove_resource(setting)52 setting = client.update_by_id_setting(id="samplesetting3", value="b")53 assert setting.value == "b"54# user should not be able to update a setting if it does not exists55def test_update_nonexisting(admin_mc, remove_resource):56 client = admin_mc.client57 with pytest.raises(ApiError) as e:58 setting = client.update_by_id_setting(id="samplesetting4", value="a")59 remove_resource(setting)60 assert e.value.error.status == 40461 assert e.value.error.code == "NotFound"62def test_update_link(admin_mc, user_factory, remove_resource):63 client = admin_mc.client64 setting = client.create_setting(name=random_str(), value="a")65 remove_resource(setting)66 wait_until(lambda: client.reload(setting) is not None)67 # admin should see update link68 setting = client.reload(setting)69 assert 'update' in setting.links70 # create standard user71 user = user_factory()72 # this user should not be able to see update link73 setting = user.client.reload(setting)...

Full Screen

Full Screen

test_notificationsetting.py

Source:test_notificationsetting.py Github

copy

Full Screen

...7 provider=ExternalProviders.EMAIL, type=NotificationSettingTypes.ISSUE_ALERTS, **kwargs8 )9def assert_no_notification_settings(**kwargs):10 assert NotificationSetting.objects._filter(**kwargs).count() == 011def create_setting(**kwargs):12 NotificationSetting.objects.update_settings(13 value=NotificationSettingOptionValues.ALWAYS,14 **_get_kwargs(kwargs),15 )16class NotificationSettingTest(TestCase):17 def test_remove_for_user(self):18 create_setting(user=self.user)19 # Deletion is deferred and tasks aren't run in tests.20 self.user.delete()21 self.user.actor.delete()22 assert_no_notification_settings()23 def test_remove_for_team(self):24 create_setting(team=self.team, project=self.project)25 # Deletion is deferred and tasks aren't run in tests.26 self.team.delete()27 self.team.actor.delete()28 assert_no_notification_settings()29 def test_remove_for_project(self):30 create_setting(user=self.user, project=self.project)31 self.project.delete()32 assert_no_notification_settings()33 def test_remove_for_organization(self):34 create_setting(user=self.user, organization=self.organization)35 self.organization.delete()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful