def test_read_line_state_read_response_tag_with_consecutive_responses(self):
     v = ApiaryValidator()
     response_file = path.join(_current_file_path, 'response', 'response_good_example001.json')
     # setup the validator
     v.state = _state_read_response_tag
     v._read_newline = True
     self._load_content_to_validator(v, content_file=response_file)
     # test with the 2nd response tag
     valid, error = v._read_line(_TEST_RESPONSE_TAG)
     if error and DEBUG:
         print('\nUnexpected Error: %s' % error)
     self.assertTrue(valid)
     self.assertFalse(v._read_newline)
     self.assertIsNone(error)
    def test_for_check_code_block_newline(self):
        v = ApiaryValidator()
        # valid cases:
        newline_examples = [' ', '\n', '\r', '   \n', '     \r']
        for newline in newline_examples:
            for state in [_state_read_response_tag, _state_read_request_tag]:
                v.decoder.clear()
                v.state = state
                v._read_newline = False
                v._read_line(newline)
                valid, error = v._read_line('        {')
                if error and DEBUG:
                    print('\nUnexpected Error: %s' % error)
                self.assertTrue(valid)
                self.assertIsNone(error)

        # invalid cases:
        for state in [_state_read_request_tag, _state_read_request_tag]:
            v.decoder.clear()
            v.state = state
            v._read_newline = False
            valid, error = v._read_line('        {')
            self.assertFalse(valid)
            self.assertEqual(error.type, ApiarySyntaxError().type)
    def test_for_check_code_block_newline(self):
        v = ApiaryValidator()
        # valid cases:
        newline_examples = [' ', '\n', '\r', '   \n', '     \r']
        for newline in newline_examples:
            for state in [_state_read_response_tag, _state_read_request_tag]:
                v.decoder.clear()
                v.state = state
                v._read_newline = False
                v._read_line(newline)
                valid, error = v._read_line('        {')
                if error and DEBUG:
                    print('\nUnexpected Error: %s' % error)
                self.assertTrue(valid)
                self.assertIsNone(error)

        # invalid cases:
        for state in [_state_read_request_tag, _state_read_request_tag]:
            v.decoder.clear()
            v.state = state
            v._read_newline = False
            valid, error = v._read_line('        {')
            self.assertFalse(valid)
            self.assertEqual(error.type, ApiarySyntaxError().type)
 def test_read_line_state_read_response_tag_with_consecutive_responses(
         self):
     v = ApiaryValidator()
     response_file = path.join(_current_file_path, 'response',
                               'response_good_example001.json')
     # setup the validator
     v.state = _state_read_response_tag
     v._read_newline = True
     self._load_content_to_validator(v, content_file=response_file)
     # test with the 2nd response tag
     valid, error = v._read_line(_TEST_RESPONSE_TAG)
     if error and DEBUG:
         print('\nUnexpected Error: %s' % error)
     self.assertTrue(valid)
     self.assertFalse(v._read_newline)
     self.assertIsNone(error)