Esempio n. 1
0
 def test_template_resource__refers_to_other_jobs(self):
     other_unit = UnitWithId({'id': 'some-unit'}, provider=self.provider)
     unit = self.unit_cls({'template-resource': 'some-unit'},
                          provider=self.provider)
     message = ("field 'template-resource',"
                " the referenced unit is not a job")
     self.provider.unit_list = [unit, other_unit]
     self.provider.problem_list = []
     context = UnitValidationContext([self.provider])
     issue_list = unit.check(context=context)
     self.assertIssueFound(issue_list,
                           self.unit_cls.Meta.fields.template_resource,
                           Problem.bad_reference, Severity.error, message)
Esempio n. 2
0
 def test_requires__refers_to_other_jobs(self):
     other_unit = UnitWithId({
         'id': 'some_unit'
     }, provider=self.provider)
     unit = self.unit_cls({
         'requires': 'some_unit.attr == "value"'
     }, provider=self.provider)
     message = "field 'requires', the referenced unit is not a job"
     self.provider.unit_list = [unit, other_unit]
     context = UnitValidationContext([self.provider])
     issue_list = unit.check(context=context)
     self.assertIssueFound(
         issue_list, self.unit_cls.Meta.fields.requires,
         Problem.bad_reference, Severity.error, message)
Esempio n. 3
0
 def test_category_id__refers_to_other_jobs(self):
     other_unit = UnitWithId({
         'id': 'some-unit'
     }, provider=self.provider)
     unit = self.unit_cls({
         'category_id': 'some-unit'
     }, provider=self.provider)
     message = "field 'category_id', the referenced unit is not a category"
     self.provider.unit_list = [unit, other_unit]
     context = UnitValidationContext([self.provider])
     issue_list = unit.check(context=context)
     self.assertIssueFound(
         issue_list, self.unit_cls.Meta.fields.category_id,
         Problem.bad_reference, Severity.error, message)
Esempio n. 4
0
 def test_validate(self):
     # Empty units are valid, with or without parameters
     Unit({}).validate()
     Unit({}, parameters={}).validate()
     # Fields cannot refer to parameters that are not supplied
     with self.assertRaises(ValidationError) as boom:
         Unit({'field': '{param}'}, parameters={}).validate()
     self.assertEqual(boom.exception.field, 'field')
     self.assertEqual(boom.exception.problem, Problem.wrong)
     # Fields must obey template constraints. (id: vary)
     with self.assertRaises(ValidationError) as boom:
         UnitWithId({'id': 'a-simple-id'}, parameters={}).validate()
     self.assertEqual(boom.exception.field, 'id')
     self.assertEqual(boom.exception.problem, Problem.constant)
     # Fields must obey template constraints. (unit: const)
     with self.assertRaises(ValidationError) as boom:
         Unit({'unit': '{parametric_id}'},
              parameters={'parametric_id': 'foo'}).validate()
     self.assertEqual(boom.exception.field, 'unit')
     self.assertEqual(boom.exception.problem, Problem.variable)