Пример #1
0
    def test_response_strings_fail_big_payload(self):
        string_handler = core.StringResponseHandler()
        # Register the JSON handler so response_data is set.
        json_handler = jsonhandler.JSONHandler()
        self.test.response_handlers = [string_handler, json_handler]
        self.test.content_handlers = [json_handler]
        self.test.content_type = "application/json"
        self.test.test_data = {'response_strings': ['foobar']}
        self.test.response_data = {
            'objects': [{
                'name': 'cw',
                'location': 'barn'
            }, {
                'name': 'chris',
                'location': 'house'
            }] * 100
        }
        self.test.output = json.dumps(self.test.response_data)
        with self.assertRaises(AssertionError) as cm:
            self._assert_handler(string_handler)

        msg = str(cm.exception)
        self.assertEqual(2038, len(msg))
        # Check the pprint of the json
        self.assertIn('      "location": "house"', msg)
Пример #2
0
 def test_response_json_paths_regex_path_match(self):
     handler = jsonhandler.JSONHandler()
     self.test.content_type = "application/json"
     self.test.test_data = {'response_json_paths': {
         '$.pathtest': '//bar//',
     }}
     self.test.response_data = {
         'pathtest': '/foo/bar/baz'
     }
     self._assert_handler(handler)
Пример #3
0
 def test_response_json_paths_dict_type(self):
     handler = jsonhandler.JSONHandler()
     self.test.test_data = {
         'name': 'omega test',
         'response_json_paths': ['alpha', 'beta']
     }
     self.test.output = 'omega\n'
     with self.assertRaises(GabbiFormatError) as exc:
         self._assert_handler(handler)
         self.assertIn('has incorrect type', str(exc))
         self.assertIn("response_json_paths in 'omega test'", str(exc))
Пример #4
0
 def test_response_json_paths_substitution_esc_regex(self):
     handler = jsonhandler.JSONHandler()
     self.test.location = '/foo/bar?query'
     self.test.prior = self.test
     self.test.content_type = "application/json"
     self.test.test_data = {'response_json_paths': {
         '$.pathtest': '/$LOCATION/',
     }}
     self.test.response_data = {
         'pathtest': '/foo/bar?query=value'
     }
     self._assert_handler(handler)
Пример #5
0
    def test_response_replace_with_history(self):
        self.test.test_data = '$HISTORY["mytest"].$RESPONSE["$.object.name"]'
        json_handler = jsonhandler.JSONHandler()
        self.test.content_type = "application/json"
        self.test.content_handlers = [json_handler]
        self.test.history["mytest"] = self.test
        self.test.response = {'content-type': 'application/json'}
        self.test.response_data = {'object': {'name': 'test history'}}

        response = self.test('test_request').replace_template(
            self.test.test_data)
        self.assertEqual('test history', response)
Пример #6
0
    def test_response_replace_prior_regex(self):
        self.test.test_data = '/$RESPONSE["$.object.name"]/'
        json_handler = jsonhandler.JSONHandler()
        self.test.content_type = "application/json"
        self.test.content_handlers = [json_handler]
        self.test.prior = self.test
        self.test.response = {'content-type': 'application/json'}
        self.test.response_data = {'object': {'name': 'test history.'}}

        response = self.test('test_request').replace_template(
            self.test.test_data, escape_regex=True)
        self.assertEqual(r'/test\ history\./', response)
Пример #7
0
 def test_response_json_paths_regex_number(self):
     handler = jsonhandler.JSONHandler()
     self.test.content_type = "application/json"
     self.test.test_data = {'response_json_paths': {
         '$.objects[0].name': '/\d+/',
     }}
     self.test.response_data = {
         'objects': [{'name': 99,
                      'location': 'barn'},
                     {'name': 'chris',
                      'location': 'house'}]
     }
     self._assert_handler(handler)
Пример #8
0
 def test_response_json_paths_substitution_noregex(self):
     handler = jsonhandler.JSONHandler()
     self.test.location = '/foo/bar/'
     self.test.prior = self.test
     self.test.content_type = "application/json"
     self.test.test_data = {'response_json_paths': {
         '$.pathtest': '$LOCATION',
     }}
     self.test.response_data = {
         'pathtest': '/foo/bar/baz'
     }
     with self.assertRaises(AssertionError):
         self._assert_handler(handler)
Пример #9
0
 def test_response_json_paths_fail_path(self):
     handler = jsonhandler.JSONHandler()
     self.test.content_type = "application/json"
     self.test.test_data = {'response_json_paths': {
         '$.objects[1].name': 'cow',
     }}
     self.test.response_data = {
         'objects': [{'name': 'cow',
                      'location': 'barn'},
                     {'name': 'chris',
                      'location': 'house'}]
     }
     with self.assertRaises(AssertionError):
         self._assert_handler(handler)
Пример #10
0
    def test_empty_response_handler(self):
        self.test.test_data = {'url': '$RESPONSE["barnabas"]'}
        self.test.response = {'content-type': 'unmatchable'}
        self.test.response_data = ''
        self.test.prior = self.test

        url = self.test('test_request').replace_template(
            self.test.test_data['url'])
        self.assertEqual('barnabas', url)

        self.test.response_data = None
        self.test.content_handlers = [jsonhandler.JSONHandler()]
        url = self.test('test_request').replace_template(
            self.test.test_data['url'])
        self.assertEqual('barnabas', url)
Пример #11
0
 def test_response_json_paths_from_disk_json_path(self):
     handler = jsonhandler.JSONHandler()
     lhs = '$.pets[?type = "cat"].sound'
     rhs = '$.values[0].pets[?type = "cat"].sound'
     self.test.test_directory = os.path.dirname(__file__)
     self.test.test_data = {'response_json_paths': {
         lhs: '<@gabbits_handlers/values.json:' + rhs,
     }}
     self.test.response_data = {
         "pets": [
             {"type": "cat", "sound": "meow"},
             {"type": "dog", "sound": "woof"}
         ]
     }
     self._assert_handler(handler)
Пример #12
0
 def __init__(self):
     super(CompareHandler, self).__init__()
     self.json = jsonhandler.JSONHandler()