def test_admin_user_limits_create_edit_delete(self): self.login_as_user() url = reverse('admin_user_limits_create', args=[self.user.safe_id]) resp = self.client.post(url, {'running_apps': 0, 'memory_per_worker': 16, 'workers': 8, 'packages_per_app': 4, 'max_log_size': 3}) self.assertEqual(resp.status_code, 302) l = UserLimits.objects(user=self.user).first() self.assertNotEqual(l, None) self.assertEqual(l.running_apps, 0) self.assertEqual(l.memory_per_worker, 16) self.assertEqual(l.workers, 8) self.assertEqual(l.packages_per_app, 4) self.assertEqual(l.max_log_size, 3) self.assertEqual(self.user.limits_settings, l) self.assertEqual(self.user.limits['running_apps'], 0) self.assertEqual(self.user.limits['memory_per_worker'], 16) self.assertEqual(self.user.limits['workers'], 8) self.assertEqual(self.user.limits['packages_per_app'], 4) self.assertEqual(self.user.limits['max_log_size'], 3) url = reverse('admin_user_limits_edit', args=[l.safe_id]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) resp = self.client.post(url, {'running_apps': 2, 'memory_per_worker': 32, 'workers': 4, 'packages_per_app': 2, 'max_log_size': 8}) self.assertEqual(resp.status_code, 302) l.reload() self.assertEqual(l.running_apps, 2) self.assertEqual(l.memory_per_worker, 32) self.assertEqual(l.workers, 4) self.assertEqual(l.packages_per_app, 2) self.assertEqual(l.max_log_size, 8) url = reverse('admin_user_limits_delete', args=[l.safe_id]) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) resp = self.client.post(url, {}) self.assertEqual(resp.status_code, 302) self.assertEqual(UserLimits.objects(user=self.user).first(), None)
def limits(self): ret = UserLimits.get_default_limits() user_limits = self.limits_settings if user_limits: for name in UserLimits.limit_fields: value = getattr(user_limits, name) if value is not None: ret[name] = value return ret
def limits_settings(self): return UserLimits.objects(user=self).first()
def get_initial(self): return UserLimits.get_default_limits()