def test_rqh_check_eq_dne(self, _): with transaction.atomic(): user = User.objects.create_user(username="******", email="*****@*****.**", password="******") resource_quota_handler = WorkspaceQuotaHandler(user) self.assertEquals("workspace_quota", resource_quota_handler.codename) self.assertTrue(resource_quota_handler.check())
def test_rqh_check_eq_app_passes(self, _): resource_quota_handler = WorkspaceQuotaHandler(self.app_model) self.assertTrue(resource_quota_handler.check())
def test_rqh_check_rq_dne(self, _): bad_rqh = WorkspaceQuotaHandler("not.a.user") self.assertTrue(bad_rqh.check())
class ResourceQuotaHandlerTest(TestCase): def setUp(self): user = User.objects.create_user(username="******", email="*****@*****.**", password="******") self.resource_quota_handler = WorkspaceQuotaHandler(user) self.resource_quota_user = ResourceQuota( codename='test_user_codename', name='test_name', description='test_description', default=1.21, units='gb', applies_to='django.contrib.auth.models.User', impose_default=False, help='Exceeded quota', _handler='tethys_quotas.handlers.workspace.WorkspaceQuotaHandler') self.resource_quota_user.save() self.entity_quota_user = UserQuota( resource_quota=self.resource_quota_user, entity=user, value=100, ) self.entity_quota_user.save() self.resource_quota_app = ResourceQuota( codename='test_app_codename', name='test_name', description='test_description', default=1.21, units='gb', applies_to='tethys_apps.models.TethysApp', impose_default=True, help='Exceeded quota', _handler='tethys_quotas.handlers.workspace.WorkspaceQuotaHandler') self.resource_quota_app.save() self.app_model = TethysApp(name='Test App') self.app_model.save() self.entity_quota_app = TethysAppQuota( resource_quota=self.resource_quota_app, entity=self.app_model, value=200, ) self.entity_quota_app.save() def tearDown(self): self.resource_quota_user.delete() self.entity_quota_user.delete() self.resource_quota_app.delete() self.entity_quota_app.delete() self.app_model.delete() @mock.patch('tethys_quotas.utilities.log') def test_rqh_check_rq_dne(self, _): bad_rqh = WorkspaceQuotaHandler("not.a.user") self.assertTrue(bad_rqh.check()) @mock.patch('tethys_quotas.utilities.log') def test_rqh_check_eq_dne(self, _): with transaction.atomic(): user = User.objects.create_user(username="******", email="*****@*****.**", password="******") resource_quota_handler = WorkspaceQuotaHandler(user) self.assertEquals("workspace_quota", resource_quota_handler.codename) self.assertTrue(resource_quota_handler.check()) @mock.patch('tethys_quotas.utilities.log') def test_rqh_check_eq_passes(self, _): self.assertTrue(self.resource_quota_handler.check()) @mock.patch('tethys_quotas.utilities.log') def test_rqh_check_eq_app_passes(self, _): resource_quota_handler = WorkspaceQuotaHandler(self.app_model) self.assertTrue(resource_quota_handler.check())