Beispiel #1
0
 def test_invoke_2(self):
     # Tests that when adding a new test definition and writing it to file
     # a correct YAML structure is created.
     self.mocked_raw_input.return_value = "\n"
     new_command = new(self.parser, self.args)
     new_command.config = self.config
     new_command.invoke()
     expected = {
         'run': {
             'steps': ["./mytest.sh"]
         },
         'metadata': {
             'environment': ['lava_test_shell'],
             'format': 'Lava-Test Test Definition 1.0',
             'version': '1.0',
             'description': '',
             'name': ''
         },
         'parse': {
             'pattern': '^\\s*(?P<test_case_id>\\w+)=(?P<result>\\w+)\\s*$'
         },
     }
     obtained = None
     with open(self.file_path, 'r') as read_file:
         obtained = yaml.load(read_file)
     self.assertEqual(expected, obtained)
Beispiel #2
0
 def test_invoke_1(self):
     # Test that when passing an already existing file, an exception is
     # thrown.
     self.args.FILE = self.temp_yaml.name
     new_command = new(self.parser, self.args)
     new_command.config = self.config
     self.assertRaises(CommandError, new_command.invoke)
Beispiel #3
0
 def test_invoke_4(self):
     # Tests that when passing values for the "steps" ListParameter, we get
     # back the correct data structure.
     self.mocked_raw_input.side_effect = [
         "foo", "\n", "\n", "\n", "\n", "\n"
     ]
     new_command = new(self.parser, self.args)
     new_command.config = self.config
     new_command.invoke()
     expected = {
         'run': {
             'steps': ["./mytest.sh"]
         },
         'metadata': {
             'environment': ['lava_test_shell'],
             'format': 'Lava-Test Test Definition 1.0',
             'version': '1.0',
             'description': '',
             'name': 'foo'
         },
         'parse': {
             'pattern': '^\\s*(?P<test_case_id>\\w+)=(?P<result>\\w+)\\s*$'
         },
     }
     obtained = None
     with open(self.file_path, 'r') as read_file:
         obtained = yaml.load(read_file)
     self.assertEqual(expected, obtained)
Beispiel #4
0
 def test_invoke_0(self):
     # Test that passing a file on the command line, it is created on the
     # file system.
     self.mocked_raw_input.return_value = "\n"
     new_command = new(self.parser, self.args)
     new_command.config = self.config
     new_command.invoke()
     self.assertTrue(os.path.exists(self.file_path))
Beispiel #5
0
 def test_invoke_3(self):
     # Tests that when adding a new test definition and writing it to a file
     # in a directory withour permissions, exception is raised.
     self.args.FILE = "/test_file.yaml"
     self.mocked_raw_input.return_value = "\n"
     new_command = new(self.parser, self.args)
     new_command.config = self.config
     self.assertRaises(CommandError, new_command.invoke)
     self.assertFalse(os.path.exists(self.args.FILE))
Beispiel #6
0
    def test_register_arguments(self):
        # Make sure that the parser add_argument is called and we have the
        # correct argument.
        new_command = new(self.parser, self.args)
        new_command.register_arguments(self.parser)

        # Make sure we do not forget about this test.
        self.assertEqual(2, len(self.parser.method_calls))

        _, args, _ = self.parser.method_calls[0]
        self.assertIn("--non-interactive", args)

        _, args, _ = self.parser.method_calls[1]
        self.assertIn("FILE", args)