From d3c59acb3f2f0ef5bbb4e89688352c522a994956 Mon Sep 17 00:00:00 2001 From: Real-Gecko Date: Tue, 16 Jun 2020 11:04:09 +0600 Subject: [PATCH] More tests for computes --- computes/forms.py | 28 ---------------------------- computes/tests.py | 14 ++++++++++++-- computes/urls.py | 10 +++++++--- computes/views.py | 2 +- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/computes/forms.py b/computes/forms.py index 3a27a39..8bf6d07 100644 --- a/computes/forms.py +++ b/computes/forms.py @@ -40,31 +40,3 @@ class SocketComputeForm(forms.ModelForm): class Meta: model = Compute fields = ['name', 'details', 'hostname', 'type'] - - -class ComputeEditHostForm(forms.Form): - host_id = forms.CharField() - name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, max_length=64) - hostname = forms.CharField(error_messages={'required': _('No IP / Domain name has been entered')}, max_length=100) - login = forms.CharField(error_messages={'required': _('No login has been entered')}, max_length=100) - password = forms.CharField(max_length=100) - details = forms.CharField(max_length=50, required=False) - - def clean_name(self): - name = self.cleaned_data['name'] - have_symbol = re.match('[^a-zA-Z0-9._-]+', name) - if have_symbol: - raise forms.ValidationError(_('The name of the host must not contain any special characters')) - elif len(name) > 20: - raise forms.ValidationError(_('The name of the host must not exceed 20 characters')) - return name - - def clean_hostname(self): - hostname = self.cleaned_data['hostname'] - have_symbol = re.match('[^a-zA-Z0-9._-]+', hostname) - wrong_ip = re.match('^0.|^255.', hostname) - if have_symbol: - raise forms.ValidationError(_('Hostname must contain only numbers, or the domain name separated by "."')) - elif wrong_ip: - raise forms.ValidationError(_('Wrong IP address')) - return hostname diff --git a/computes/tests.py b/computes/tests.py index 391abd5..4197be3 100644 --- a/computes/tests.py +++ b/computes/tests.py @@ -125,6 +125,16 @@ class ComputesTestCase(TestCase): response = self.client.get(reverse('machines', kwargs={'compute_id': 1, 'arch': 'x86_64'})) self.assertEqual(response.status_code, 200) - # TODO: get_compute_disk_buses + def test_compute_disk_buses(self): + response = self.client.get( + reverse('buses', kwargs={ + 'compute_id': 1, + 'arch': 'x86_64', + 'machine': 'pc', + 'disk': 'disk', + })) + self.assertEqual(response.status_code, 200) - # TODO: domcaps + def test_dom_capabilities(self): + response = self.client.get(reverse('domcaps', kwargs={'compute_id': 1, 'arch': 'x86_64', 'machine': 'pc'})) + self.assertEqual(response.status_code, 200) diff --git a/computes/urls.py b/computes/urls.py index 81c37a5..0649cf4 100644 --- a/computes/urls.py +++ b/computes/urls.py @@ -36,8 +36,12 @@ urlpatterns = [ path('secrets/', secrets, name='secrets'), path('create/', create_instance_select_type, name='create_instance_select_type'), path('create/archs//machines//', create_instance, name='create_instance'), - path('archs//machines', views.get_compute_machine_types, name='machines'), - path('archs//machines//disks//buses', views.get_compute_disk_buses, name='buses'), - path('archs//machines//capabilities', views.get_dom_capabilities, name='domcaps'), + path('archs//machines/', views.get_compute_machine_types, name='machines'), + path( + 'archs//machines//disks//buses/', + views.get_compute_disk_buses, + name='buses', + ), + path('archs//machines//capabilities/', views.get_dom_capabilities, name='domcaps'), ])), ] diff --git a/computes/views.py b/computes/views.py index 7a947d7..d832c0e 100644 --- a/computes/views.py +++ b/computes/views.py @@ -9,7 +9,7 @@ from libvirt import libvirtError from accounts.models import UserInstance from admin.decorators import superuser_only -from computes.forms import (ComputeEditHostForm, SocketComputeForm, SshComputeForm, TcpComputeForm, TlsComputeForm) +from computes.forms import (SocketComputeForm, SshComputeForm, TcpComputeForm, TlsComputeForm) from computes.models import Compute from instances.models import Instance from vrtManager.connection import (CONN_SOCKET, CONN_SSH, CONN_TCP, CONN_TLS, connection_manager, wvmConnect)