def setUpClass(cls): cls.domain = Domain(name='foo') cls.domain.save() cls.user = CommCareUser.create(cls.domain.name, 'somebody', 'password') cls.user_id = cls.user._id cls.factory = CaseFactory(domain='foo', case_defaults={'owner_id': cls.user_id}) ENABLE_LOADTEST_USERS.set('foo', True, namespace='domain')
def setUpClass(cls): super(LoadtestUserTest, cls).setUpClass() cls.domain = Domain(name='foo') cls.domain.save() cls.user = CommCareUser.create(cls.domain.name, 'somebody', 'password', None, None) cls.user_id = cls.user._id cls.factory = CaseFactory(domain='foo', case_defaults={'owner_id': cls.user_id}) ENABLE_LOADTEST_USERS.set('foo', True, namespace=NAMESPACE_DOMAIN)
def get_loadtest_factor_for_user(domain, user_id): from corehq.apps.users.models import CouchUser, CommCareUser if ENABLE_LOADTEST_USERS.enabled(domain) and user_id: user = CouchUser.get_by_user_id(user_id, domain=domain) if isinstance(user, CommCareUser): return user.loadtest_factor or 1 return 1
def loadtest_factor(self): """ Gets the loadtest factor for a domain and user. Is always 1 unless both the toggle is enabled for the domain, and the user has a non-zero, non-null factor set. """ if ENABLE_LOADTEST_USERS.enabled(self.domain): return self._loadtest_factor or 1 return 1
def get_loadtest_factor(domain, user): """ Gets the loadtest factor for a domain and user. Is always 1 unless both the toggle is enabled for the domain, and the user has a non-zero, non-null factor set. """ if domain and ENABLE_LOADTEST_USERS.enabled(domain): return getattr(user, 'loadtest_factor', 1) or 1 return 1
def setUp(self): delete_all_cases() self.assertTrue(ENABLE_LOADTEST_USERS.enabled('foo'))