fix message of allocate bug
This commit is contained in:
parent
33fd574f18
commit
af30453c12
|
@ -603,21 +603,39 @@ class AllocateForm(ActionFormMix):
|
||||||
end_users = IntegerField('End users', [validators.Optional()])
|
end_users = IntegerField('End users', [validators.Optional()])
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
is_valid = super().validate(extra_validators)
|
if not super().validate(extra_validators):
|
||||||
|
return False
|
||||||
|
|
||||||
if self.type.data not in ['Allocate', 'Deallocate']:
|
if self.type.data not in ['Allocate', 'Deallocate']:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not self.validate_dates():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.check_devices():
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def validate_dates(self):
|
||||||
start_time = self.start_time.data
|
start_time = self.start_time.data
|
||||||
end_time = self.end_time.data
|
end_time = self.end_time.data
|
||||||
|
|
||||||
|
if not start_time:
|
||||||
|
self.start_time.errors = ['Not a valid date value.!']
|
||||||
|
return False
|
||||||
|
|
||||||
if start_time and end_time and end_time < start_time:
|
if start_time and end_time and end_time < start_time:
|
||||||
error = ['The action cannot finish before it starts.']
|
error = ['The action cannot finish before it starts.']
|
||||||
self.end_time.errors = error
|
self.end_time.errors = error
|
||||||
is_valid = False
|
return False
|
||||||
|
|
||||||
if is_valid and not end_time:
|
if not end_time:
|
||||||
self.end_time.data = self.start_time.data
|
self.end_time.data = self.start_time.data
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def check_devices(self):
|
||||||
if self.type.data == 'Allocate':
|
if self.type.data == 'Allocate':
|
||||||
txt = "You need deallocate before allocate this device again"
|
txt = "You need deallocate before allocate this device again"
|
||||||
for device in self._devices:
|
for device in self._devices:
|
||||||
|
@ -636,7 +654,7 @@ class AllocateForm(ActionFormMix):
|
||||||
|
|
||||||
device.allocated = False
|
device.allocated = False
|
||||||
|
|
||||||
return is_valid
|
return True
|
||||||
|
|
||||||
|
|
||||||
class DataWipeDocumentForm(Form):
|
class DataWipeDocumentForm(Form):
|
||||||
|
|
|
@ -668,7 +668,7 @@ def test_action_allocate_error_required(user3: UserClientFlask):
|
||||||
body, status = user3.post(uri, data=data)
|
body, status = user3.post(uri, data=data)
|
||||||
assert status == '200 OK'
|
assert status == '200 OK'
|
||||||
assert 'Action Allocate error' in body
|
assert 'Action Allocate error' in body
|
||||||
assert 'You need to specify a number of users!' in body
|
assert 'Not a valid date value.' in body
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
|
Reference in New Issue