Debian Codegraph @

tests/models/test_inspection.py

raw
1 #!/usr/bin/env python
2
3 # Copyright New York University and the in-toto contributors
4 # SPDX-License-Identifier: Apache-2.0
5
6 """
7 <Program Name>
8 test_inspection.py
9
10 <Author>
11 Santiago Torres-Arias <[email protected]>
12
13 <Started>
14 Nov 18, 2016
15
16 <Copyright>
17 See LICENSE for licensing information.
18
19 <Purpose>
20 Test inspection class functions.
21
22 """
23
24 import unittest
25
26 import securesystemslib.exceptions
27
28 from in_toto.models.layout import Inspection
29
30
31 class TestInspectionValidator(unittest.TestCase):
32 """Test verifylib.verify_delete_rule(rule, artifact_queue)"""
33
34 def setUp(self):
35 """Populate a base layout that we can use."""
36 self.inspection = Inspection(name="some-inspection")
37
38 def test_wrong_type(self):
39 """Test the type field within Validate()."""
40
41 self.inspection._type = "wrong"
42 with self.assertRaises(securesystemslib.exceptions.FormatError):
43 self.inspection._validate_type()
44
45 with self.assertRaises(securesystemslib.exceptions.FormatError):
46 self.inspection.validate()
47
48 self.inspection._type = "inspection"
49 self.inspection._validate_type()
50
51 def test_wrong_run(self):
52 """Test that the run validators catch malformed values."""
53
54 self.inspection.run = -1
55 with self.assertRaises(securesystemslib.exceptions.FormatError):
56 self.inspection._validate_run()
57
58 with self.assertRaises(securesystemslib.exceptions.FormatError):
59 self.inspection.validate()
60
61 self.inspection.run = ["somecommand"]
62 self.inspection._validate_run()
63 self.inspection.validate()
64
65 def test_set_run_from_string(self):
66 """Test shelx parse command string to list."""
67 inspection = Inspection()
68 inspection.set_run_from_string("echo 'foo bar'")
69 self.assertListEqual(inspection.run, ["echo", "foo bar"])
70
71
72 if __name__ == "__main__":
73 unittest.main()