Commit c4c51784 authored by xaingling's avatar xaingling

update the tests

parent 3121bd2f
......@@ -65,11 +65,10 @@ class SensorOnInstrumentForm(ModelForm):
def clean(self):
cleaned_data = super().clean()
instrument = cleaned_data.get("instrument")
sensor = cleaned_data.get("sensor")
start_time = cleaned_data.get("start_time")
end_time = cleaned_data.get("end_time")
base_soi_qs = SensorOnInstrument.objects.filter(instrument=instrument, sensor=sensor)
base_soi_qs = SensorOnInstrument.objects.filter(sensor=sensor)
self_instance = self.instance
soi_qs_overlap = qs_time_overlap(base_soi_qs, start_time, end_time)
the_id = self_instance.id
......@@ -87,7 +86,7 @@ class SensorOnInstrumentForm(ModelForm):
raise forms.ValidationError(
mark_safe(msg)
)
return self.cleaned_data
class InstrumentCommentBoxForm(ModelForm):
......
from datetime import datetime
from instruments.model_form import SensorOnInstrumentForm
from django.test import SimpleTestCase, TestCase
from instruments.tests.create_mock_sensor_tracker_database import create_mock_database
from app_common.utilities.time_format_functions import str_to_timeobj
class SensorOnInstrumentFormTest(TestCase):
def setUp(self):
create_mock_database()
def test_sensor_on_instrument_exists(self):
data = {'instrument': 1, "sensor": 1, "start_time": datetime.now(), "end_time": None, "comment": "hj"}
form = SensorOnInstrumentForm(data)
form.is_valid()
try:
form.clean()
except Exception as e:
self.assertTrue(True)
else:
self.assertTrue(False)
def test_sensor_on_instrument_no_exist(self):
data = {'instrument': 100, "sensor": 100, "start_time": datetime.now(), "end_time": None, "comment": "hj"}
form = SensorOnInstrumentForm(data)
try:
form.is_valid()
form.clean()
except Exception as e:
self.assertTrue(False)
else:
self.assertTrue(True)
def test_sensor_on_instrument_exists2(self):
data = {'instrument': 1, "sensor": 2, "start_time": datetime.now(), "end_time": None, "comment": "hj"}
form = SensorOnInstrumentForm(data)
form.is_valid()
try:
form.clean()
except Exception as e:
self.assertTrue(True)
else:
self.assertTrue(False)
def test_sensor_on_instrument_exists3(self):
data = {'instrument': 1, "sensor": 1,
"start_time": str_to_timeobj("2017-11-15T16:25:32Z", time_format='%Y-%m-%dT%H:%M:%SZ'),
"end_time": datetime.now(),
"comment": "hj"}
form = SensorOnInstrumentForm(data)
form.is_valid()
try:
form.clean()
except Exception as e:
self.assertTrue(False)
else:
self.assertTrue(True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment