5 from autotest_lib
.frontend
import setup_django_environment
6 from autotest_lib
.frontend
.afe
import frontend_test_utils
, rpc_utils
7 from autotest_lib
.frontend
.tko
import models
as tko_models
8 from autotest_lib
.frontend
.planner
import models
, model_attributes
9 from autotest_lib
.frontend
.planner
import planner_test_utils
12 class ModelWithHashTestBase(frontend_test_utils
.FrontendTestMixin
):
14 self
._frontend
_common
_setup
(fill_data
=False)
18 self
._frontend
_common
_teardown
()
21 def _model_class(self
):
22 raise NotImplementedError('Subclasses must override _model_class()')
26 raise NotImplementedError('Subclasses must override _test_data()')
29 def test_disallowed_operations(self
):
31 self
._model
_class
().objects
.create(**self
._test
_data
())
32 self
.assertRaises(Exception, _call_create
)
34 model
= self
._model
_class
().objects
.get_or_create(
35 **self
._test
_data
())[0]
36 self
.assertRaises(Exception, model
.save
)
39 def test_hash_field(self
):
40 model
= self
._model
_class
().objects
.get_or_create(
41 **self
._test
_data
())[0]
42 self
.assertNotEqual(model
.id, None)
43 self
.assertEqual(self
._model
_class
()._compute
_hash
(**self
._test
_data
()),
47 class ControlFileTest(ModelWithHashTestBase
, unittest
.TestCase
):
48 def _model_class(self
):
49 return models
.ControlFile
53 return {'contents' : 'test_control'}
56 class KeyValTest(ModelWithHashTestBase
, unittest
.TestCase
):
57 def _model_class(self
):
62 return {'key' : 'test_key',
63 'value' : 'test_value'}
66 class AdditionalParameterTest(frontend_test_utils
.FrontendTestMixin
,
69 self
._frontend
_common
_setup
()
70 self
.plan
= models
.Plan
.objects
.create(name
='plan')
71 self
.param_type
= model_attributes
.AdditionalParameterType
.VERIFY
74 self
._frontend
_common
_teardown
()
77 def test_find_applicable_control_parameter_match(self
):
78 parameter
= models
.AdditionalParameter
.objects
.create(
79 plan
=self
.plan
, hostname_regex
='host.*',
80 param_type
=self
.param_type
, application_order
=0)
81 found
= models
.AdditionalParameter
.find_applicable_additional_parameter(
82 plan
=self
.plan
, hostname
='host1', param_type
=self
.param_type
)
84 self
.assertEqual(parameter
, found
)
87 def test_find_applicable_additional_parameter_ordered(self
):
88 additional1
= models
.AdditionalParameter
.objects
.create(
89 plan
=self
.plan
, hostname_regex
='host.*',
90 param_type
=self
.param_type
, application_order
=0)
91 additional2
= models
.AdditionalParameter
.objects
.create(
92 plan
=self
.plan
, hostname_regex
='.*',
93 param_type
=self
.param_type
, application_order
=1)
96 models
.AdditionalParameter
.find_applicable_additional_parameter(
97 plan
=self
.plan
, hostname
='host1',
98 param_type
=self
.param_type
))
100 models
.AdditionalParameter
.find_applicable_additional_parameter(
101 plan
=self
.plan
, hostname
='other',
102 param_type
=self
.param_type
))
104 self
.assertEqual(additional1
, found1
)
105 self
.assertEqual(additional2
, found2
)
108 def test_find_applicable_additional_parameter_no_match(self
):
109 models
.AdditionalParameter
.objects
.create(
110 plan
=self
.plan
, hostname_regex
='host.*',
111 param_type
=self
.param_type
, application_order
=0)
112 found
= models
.AdditionalParameter
.find_applicable_additional_parameter(
113 plan
=self
.plan
, hostname
='other', param_type
=self
.param_type
)
115 self
.assertEqual(None, found
)
118 class JobTest(planner_test_utils
.PlannerTestMixin
,
121 self
._planner
_common
_setup
()
122 self
._setup
_active
_plan
()
126 self
._planner
_common
_teardown
()
129 def test_active(self
):
130 self
.assertEqual(True, self
._planner
_job
.active())
131 self
._afe
_job
.hostqueueentry_set
.update(complete
=True)
132 self
.assertEqual(False, self
._planner
_job
.active())
135 def test_all_tests_passed_active(self
):
136 self
.assertEqual(True, self
._planner
_job
.active())
137 self
.assertEqual(False, self
._planner
_job
.all_tests_passed())
140 def test_all_tests_passed_failed_queue_entry(self
):
141 self
._afe
_job
.hostqueueentry_set
.update(complete
=True, status
='Failed')
142 self
.assertEqual(False, self
._planner
_job
.active())
144 self
.assertEqual(False, self
._planner
_job
.all_tests_passed())
147 def _setup_test_all_tests_passed(self
, status
):
148 self
._afe
_job
.hostqueueentry_set
.update(complete
=True,
150 tko_test
= tko_models
.Test
.objects
.create(job
=self
._tko
_job
,
152 kernel
=self
._tko
_kernel
,
153 machine
=self
._tko
_machine
)
154 self
.assertEqual(False, self
._planner
_job
.active())
157 def test_all_tests_passed_success(self
):
158 self
._setup
_test
_all
_tests
_passed
(self
._good
_status
)
159 self
.assertEqual(True, self
._planner
_job
.all_tests_passed())
162 def test_all_tests_passed_failure(self
):
163 self
._setup
_test
_all
_tests
_passed
(self
._fail
_status
)
164 self
.assertEqual(False, self
._planner
_job
.all_tests_passed())
167 if __name__
== '__main__':