Beispiel #1
0
    def test_run_should_exit_with_error_when_non_existing_file_is_given(self):
        mock_when(yadt_lint)._get_configuration(any_value()).thenRaise(IOError)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint._validate_yaml_input(IOError)

        verify(yadt_lint.sys).exit(1)
Beispiel #2
0
    def test_run_should_exit_with_error_when_target_yaml_parsing_fails(self):
        problem_mark = Mark('name', 1, 2, 3, '', '')
        mock_when(yadt_lint)._get_configuration(any_value()).thenRaise(ScannerError(problem_mark=problem_mark))
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint._validate_yaml_input(problem_mark)

        verify(yadt_lint.sys).exit(1)
        verify(yadt_lint.logger).error('Invalid YAML Format check position: (line:column) -> (2:4)')
Beispiel #3
0
    def test_should_not_exit_with_error_when_config_validation_succeeds(self):
        mock_schema = mock()
        mock_when(mock_schema).validate_config(any_value()).thenReturn(None)
        mock_when(yadt_lint.phyles).package_spec(any_value(), any_value(), any_value(), any_value()).thenReturn(None)
        mock_when(yadt_lint.phyles).load_schema(any_value(), any_value()).thenReturn(mock_schema)
        mock_when(yadt_lint.phyles).sample_config(any_value()).thenReturn(None)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint._validate_target_schema(mock())

        verify(yadt_lint.sys, never).exit(any_value())
Beispiel #4
0
    def test_should_call_exit_with_error_when_config_validation_failed(self):
        mock_schema = mock()
        mock_when(mock_schema).validate_config(any_value()).thenRaise(phyles.ConfigError)
        mock_when(yadt_lint.phyles).package_spec(any_value(), any_value(), any_value(), any_value()).thenReturn(None)
        mock_when(yadt_lint.phyles).load_schema(any_value(), any_value()).thenReturn(mock_schema)
        mock_when(yadt_lint.phyles).sample_config(any_value()).thenReturn(None)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint._validate_target_schema(mock())

        verify(yadt_lint.sys).exit(1)
Beispiel #5
0
    def test_should_exit_with_error_when_target_file_name_is_wrong(self):
        mock_args = {'<file>': 'foobar',
                     'target_validate': True,
                     'services_validate': False}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint)._get_configuration(any_value()).thenReturn(None)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_yaml_input(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint.sys).exit(1)
Beispiel #6
0
    def test_should_exit_when_invalid_targetfile_name_is_given(self):
        mock_args = {'<file>': 'foobar',
                     'target_validate': True,
                     'services_validate': False}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_target_schema(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_yaml_input(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint.sys).exit(1)
Beispiel #7
0
    def test_should_exit_when_invalid_targetfile_name_is_given(self):
        mock_args = {'<file>': 'foobar',
                     'target_validate': True,
                     'services_validate': False}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_target_schema_new(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_yaml_input(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint.sys).exit(1)
Beispiel #8
0
    def test_run_should_exit_with_error_when_non_existing_file_is_given(self):
        mock_args = {'<file>': 'target',
                     'target_validate': True,
                     'services_validate': False}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint)._get_configuration(any_value()).thenRaise(IOError)
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint.sys).exit(1)
Beispiel #9
0
    def test_should_initialize_docopt(self):
        mock_args = {'<file>': 'target',
                     'services_validate': False,
                     'target_validate': True}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint)._get_configuration(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_target_schema(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint).docopt(yadt_lint.__doc__, version=yadt_lint.__version__)
Beispiel #10
0
    def test_should_initialize_docopt(self):
        mock_args = {'<file>': 'target',
                     'services_validate': False,
                     'target_validate': True}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_when(yadt_lint)._get_configuration(any_value()).thenReturn(None)
        mock_when(yadt_lint)._validate_target_schema_new(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint).docopt(yadt_lint.__doc__, version=yadt_lint.__version__)
Beispiel #11
0
    def test_run_should_exit_with_error_when_target_yaml_parsing_fails(self):
        mock_args = {'<file>': 'target',
                     'target_validate': True,
                     'services_validate': False}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        problem_mark = Mark('name', 1, 2, 3, '', '')
        mock_when(yadt_lint)._get_configuration(any_value()).thenRaise(ScannerError(problem_mark=problem_mark))
        mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint.sys).exit(1)
        verify(yadt_lint.logger).error('Invalid YAML Format check position: (3:4)')
Beispiel #12
0
    def test_run_should_call_get_configuration_and_validate_target_schema(self):
        mock_args = {'<file>': 'target',
                     'services_validate': False,
                     'target_validate': True}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_configuration = mock()
        mock_when(yadt_lint)._get_configuration(any_value()).thenReturn(mock_configuration)
        mock_when(yadt_lint)._validate_target_schema(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint)._get_configuration(mock_args)
        verify(yadt_lint)._validate_target_schema(mock_configuration)
Beispiel #13
0
    def test_run_should_call_get_configuration_and_validate_target_schema_new(self):
        mock_args = {'<file>': 'target',
                     'services_validate': False,
                     'target_validate': True}
        mock_when(yadt_lint).docopt(any_value(), version=any_value()).thenReturn(mock_args)
        mock_configuration = mock()
        mock_when(yadt_lint)._get_configuration(any_value()).thenReturn(mock_configuration)
        mock_when(yadt_lint)._validate_target_schema_new(any_value()).thenReturn(None)

        yadt_lint.run()

        verify(yadt_lint)._get_configuration(mock_args)
        verify(yadt_lint)._validate_target_schema_new(mock_configuration)
Beispiel #14
0
 def setUp(self):
     mock_when(yadt_lint.logger).info(any_value()).thenReturn(None)
     mock_when(yadt_lint.logger).error(any_value()).thenReturn(None)
     mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)
Beispiel #15
0
 def setUp(self):
     mock_when(yadt_lint.logger).warn(any_value()).thenReturn(None)
     mock_when(yadt_lint.logger).info(any_value()).thenReturn(None)
     mock_when(yadt_lint.logger).error(any_value()).thenReturn(None)
     mock_when(yadt_lint.sys).exit(any_value()).thenReturn(None)