parent
6c31555a52
commit
011fb4816f
|
@ -77,7 +77,9 @@ class LoginTest(TestCase):
|
||||||
Tests if login template renders
|
Tests if login template renders
|
||||||
"""
|
"""
|
||||||
resp = self.client.get(reverse("accounts.login"))
|
resp = self.client.get(reverse("accounts.login"))
|
||||||
self.assertEqual(b"A free forge ecosystem for free developers" in resp.content, True)
|
self.assertEqual(
|
||||||
|
b"A free forge ecosystem for free developers" in resp.content, True
|
||||||
|
)
|
||||||
|
|
||||||
def test_login_works(self):
|
def test_login_works(self):
|
||||||
"""
|
"""
|
||||||
|
@ -234,7 +236,9 @@ class RegistrationTest(TestCase):
|
||||||
Tests if register template renders
|
Tests if register template renders
|
||||||
"""
|
"""
|
||||||
resp = self.client.get(reverse("accounts.register"))
|
resp = self.client.get(reverse("accounts.register"))
|
||||||
self.assertEqual(b"A free forge ecosystem for free developers." in resp.content, True)
|
self.assertEqual(
|
||||||
|
b"A free forge ecosystem for free developers." in resp.content, True
|
||||||
|
)
|
||||||
|
|
||||||
def test_register_works(self):
|
def test_register_works(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -23,6 +23,8 @@ from .models import Instance, InstanceConfiguration
|
||||||
@unique
|
@unique
|
||||||
class VmErrors(Enum):
|
class VmErrors(Enum):
|
||||||
NAME_EXISTS = "Instance name exists, please try again with a different name"
|
NAME_EXISTS = "Instance name exists, please try again with a different name"
|
||||||
|
ILLEGAL_NAME = "Only alphanumeric characters are allowed in instance name"
|
||||||
|
NAME_TOO_LONG = "Instance name must be less than 20 characters"
|
||||||
NO_CONFIG = "Configuration doesn't exist, please try again."
|
NO_CONFIG = "Configuration doesn't exist, please try again."
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
@ -46,6 +48,11 @@ def create_instance(vm_name: str, configuration_name: str, user: User) -> Instan
|
||||||
Create instance view
|
Create instance view
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if len(vm_name) > 20:
|
||||||
|
raise VmException(code=VmErrors.NAME_TOO_LONG)
|
||||||
|
if not str.isalnum(vm_name):
|
||||||
|
raise VmException(code=VmErrors.ILLEGAL_NAME)
|
||||||
|
|
||||||
if Instance.objects.filter(name=vm_name).exists():
|
if Instance.objects.filter(name=vm_name).exists():
|
||||||
raise VmException(code=VmErrors.NAME_EXISTS)
|
raise VmException(code=VmErrors.NAME_EXISTS)
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,7 @@ def create_instance(request):
|
||||||
return redirect(reverse("billing.invoice.generate", args=(instance.name,)))
|
return redirect(reverse("billing.invoice.generate", args=(instance.name,)))
|
||||||
except VmException as e:
|
except VmException as e:
|
||||||
ctx = get_ctx()
|
ctx = get_ctx()
|
||||||
if e.code == VmErrors.NAME_EXISTS:
|
reason = e.error
|
||||||
reason = ("Instance name exists, please try again with a different name",)
|
|
||||||
elif e.code == VmErrors.NO_CONFIG:
|
|
||||||
reason = "Configuration doesn't exist, please try again."
|
|
||||||
|
|
||||||
ctx["error"] = {
|
ctx["error"] = {
|
||||||
"title": "Can't create instance",
|
"title": "Can't create instance",
|
||||||
|
|
Loading…
Reference in New Issue