How to use is_multi_user method in tempest

Best Python code snippet using tempest_python

mobile_device_prestage_all_of.py

Source:mobile_device_prestage_all_of.py Github

copy

Full Screen

...86 if self.local_vars_configuration.client_side_validation and is_allow_pairing is None: # noqa: E50187 raise ValueError("Invalid value for `is_allow_pairing`, must not be `None`") # noqa: E50188 self._is_allow_pairing = is_allow_pairing89 @property90 def is_multi_user(self):91 """Gets the is_multi_user of this MobileDevicePrestageAllOf. # noqa: E50192 :return: The is_multi_user of this MobileDevicePrestageAllOf. # noqa: E50193 :rtype: bool94 """95 return self._is_multi_user96 @is_multi_user.setter97 def is_multi_user(self, is_multi_user):98 """Sets the is_multi_user of this MobileDevicePrestageAllOf.99 :param is_multi_user: The is_multi_user of this MobileDevicePrestageAllOf. # noqa: E501100 :type is_multi_user: bool101 """102 if self.local_vars_configuration.client_side_validation and is_multi_user is None: # noqa: E501103 raise ValueError("Invalid value for `is_multi_user`, must not be `None`") # noqa: E501104 self._is_multi_user = is_multi_user105 @property106 def is_supervised(self):107 """Gets the is_supervised of this MobileDevicePrestageAllOf. # noqa: E501108 :return: The is_supervised of this MobileDevicePrestageAllOf. # noqa: E501109 :rtype: bool110 """111 return self._is_supervised...

Full Screen

Full Screen

organization.py

Source:organization.py Github

copy

Full Screen

1#!/usr/bin/env python2# Licensed to Cloudera, Inc. under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. Cloudera, Inc. licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing, software13# distributed under the License is distributed on an "AS IS" BASIS,14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15# See the License for the specific language governing permissions and16# limitations under the License.17import logging18import uuid19from crequest.middleware import CrequestMiddleware20from django.contrib.auth.models import models, AbstractUser, BaseUserManager21from django.utils.functional import SimpleLazyObject22from django.utils.translation import ugettext_lazy as _t23from desktop.conf import ENABLE_ORGANIZATIONS24LOG = logging.getLogger(__name__)25def get_user_request_organization():26 request = CrequestMiddleware.get_request()27 return request.user.organization if request and hasattr(request, 'user') and request.user.is_authenticated() else None28def _fitered_queryset(queryset, by_owner=False):29 request = CrequestMiddleware.get_request()30 # Avoid infinite recursion on very first retrieval of the user31 if ENABLE_ORGANIZATIONS.get() and \32 request and hasattr(request, 'user') and hasattr(request.user, '_wrapped') and type(request.user._wrapped) is not object and \33 request.user.is_authenticated():34 if by_owner:35 filters = {'owner__organization': request.user.organization}36 else:37 filters = {'organization': request.user.organization}38 queryset = queryset.filter(**filters)39 return queryset40def get_organization(email, is_multi_user=False):41 domain = email.split('@')[1] if is_multi_user else email42 if domain:43 organization, created = Organization.objects.get_or_create(name=domain, domain=domain, is_multi_user=is_multi_user)44 LOG.info("Materializing organization %s in the database, is_multi_user=%s" % (domain, is_multi_user))45 else:46 LOG.warn('No organization domain found for email %s' % email) # For Backends without emails or when organization enabled by default47 organization = None48 return organization49def uuid_default():50 return str(uuid.uuid4())51class OrganizationManager(models.Manager):52 use_in_migrations = True53 def get_by_natural_key(self, name):54 return self.get(name=name)55if ENABLE_ORGANIZATIONS.get():56 class Organization(models.Model):57 """58 Organizations handle contained sets of setups (user, group, connectors...).59 An external user create an account and gets attached to its single user organization and becomes its admin. The organization can60 be later converted to a multi user organization (if the domain name is owned by the first user).61 An organization admin is not a Hue admin. The later is the true super user and has access to the server logs and metrics.62 """63 name = models.CharField(max_length=200, help_text=_t("The name of the organization"), unique=True)64 uuid = models.CharField(default=uuid_default, max_length=36, unique=True)65 domain = models.CharField(max_length=200, help_text=_t("The domain name of the organization, e.g. gethue.com"), unique=True)66 customer_id = models.CharField(_t('Customer id'), max_length=128, default=None, null=True)67 is_active = models.BooleanField(default=True)68 is_multi_user = models.BooleanField(default=True)69 objects = OrganizationManager()70 def __str__(self):71 return self.name or self.domain72class OrganizationGroupManager(models.Manager):73 def get_queryset(self):74 """Make sure to restrict to only organization's groups"""75 queryset = super(OrganizationGroupManager, self).get_queryset()76 return _fitered_queryset(queryset)77 def natural_key(self):78 return (self.organization, self.name,)79if ENABLE_ORGANIZATIONS.get():80 class OrganizationGroup(models.Model):81 name = models.CharField(_t('name'), max_length=80, unique=False)82 organization = models.ForeignKey(Organization)83 permissions = models.ManyToManyField(84 'HuePermission',85 verbose_name=_t('permissions'),86 blank=True,87 )88 # Could also have a set of Roles at some point.89 objects = OrganizationGroupManager()90 def __init__(self, *args, **kwargs):91 if not kwargs.get('organization'):92 kwargs['organization'] = get_user_request_organization()93 super(OrganizationGroup, self).__init__(*args, **kwargs)94 class Meta:95 verbose_name = _t('organization group')96 verbose_name_plural = _t('organization groups')97 unique_together = ('name', 'organization',)98 def __str__(self):99 return '%s @ %s' % (self.name, self.organization)100class UserManager(BaseUserManager):101 """Define a model manager for User model with no username field."""102 use_in_migrations = True103 def get_queryset(self):104 """Make sure to restrict to only organization's user"""105 queryset = super(UserManager, self).get_queryset()106 return _fitered_queryset(queryset)107 def get(self, *args, **kwargs):108 if kwargs.get('username'):109 kwargs['email'] = kwargs.pop('username')110 request = CrequestMiddleware.get_request()111 # Avoid infinite recursion112 if request and hasattr(request, 'user') and hasattr(request.user, '_wrapped') and type(request.user._wrapped) is not object:113 organization = get_user_request_organization()114 if organization:115 kwargs['organization'] = organization116 return super(UserManager, self).get(*args, **kwargs)117 def order_by(self, *args, **kwargs):118 if 'username' in args:119 args = list(args)120 args.remove('username')121 args.append('email')122 return super(UserManager, self).order_by(*args, **kwargs)123 def filter(self, *args, **kwargs):124 f = super(UserManager, self).filter(*args, **kwargs)125 # f.values_list = self.values_list # Patch so that chaining after a filter is backward compatible. However creates wrong result.126 return f127 def values_list(self, *args, **kwargs):128 if 'username' in args:129 args = list(args)130 args.remove('username')131 args.append('email')132 return super(UserManager, self).values_list(*args, **kwargs)133 def _create_user(self, email, password, **extra_fields):134 """Create and save a User with the given email and password."""135 if not email:136 raise ValueError('The given email must be set')137 email = self.normalize_email(email)138 user = self.model(email=email, **extra_fields)139 user.set_password(password)140 user.save(using=self._db)141 return user142 def create_user(self, email=None, password=None, **extra_fields):143 """Create and save a regular User with the given email and password."""144 if extra_fields.get('username'):145 email = extra_fields.pop('username')146 if not extra_fields.get('organization'):147 extra_fields['organization'] = get_user_request_organization()148 if not extra_fields['organization']:149 extra_fields['organization'] = get_organization(email=email)150 extra_fields.setdefault('is_staff', False)151 extra_fields.setdefault('is_superuser', False)152 extra_fields.setdefault('is_admin', False)153 return self._create_user(email, password, **extra_fields)154 def create_superuser(self, email, password, **extra_fields):155 """Create and save a SuperUser with the given email and password."""156 extra_fields.setdefault('is_staff', False)157 extra_fields.setdefault('is_superuser', False)158 extra_fields.setdefault('is_admin', True)159 if extra_fields.get('is_staff') is not False:160 raise ValueError('Organization superuser must have is_staff=False.')161 if extra_fields.get('is_superuser') is not False:162 raise ValueError('Organization superuser must have is_superuser=False.')163 if extra_fields.get('is_admin') is not True:164 raise ValueError('Organization superuser must have is_admin=True.')165 return self._create_user(email, password, **extra_fields)166if ENABLE_ORGANIZATIONS.get():167 class OrganizationUser(AbstractUser):168 """User model in a multi tenant setup."""169 username = None170 email = models.EmailField(_t('Email address'), unique=True)171 token = models.CharField(_t('Token'), max_length=128, default=None, null=True)172 organization = models.ForeignKey(Organization, on_delete=models.CASCADE)173 is_admin = models.BooleanField(default=False)174 groups = models.ManyToManyField(175 OrganizationGroup,176 verbose_name=_t('groups'),177 blank=True,178 help_text=_t(179 'The groups this user belongs to. A user will get all permissions granted to each of their groups.'180 ),181 related_name="user_set",182 related_query_name="user",183 )184 USERNAME_FIELD = 'email'185 REQUIRED_FIELDS = []186 objects = UserManager()187 def __str__(self):188 return '%s @ %s' % (self.email, self.organization)189 @property190 def username(self):191 return self.email192 @property193 def username_short(self):194 return self.email.split('@')[0]195 @username.setter196 def username(self, value):...

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 tempest 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