Exemple #1
0
    def test_mock_request_response(self):
        components = [
            root, 'data', 'JSON-Schema-Test-Suite', 'draft4', 'refRemote'
        ]

        with open(
                path((root, 'data', 'JSON-Schema-Test-Suite', 'draft4',
                      'refRemote', 'integer.json'))) as file:
            m = MockRequestResponse(components,
                                    'http://localhost:1234/integer.json')
            data = json.loads(file.read())
            self.assertEqual(m.json(), data)

        with open(
                path((root, 'data', 'JSON-Schema-Test-Suite', 'draft4',
                      'refRemote', 'subSchemas.json'))) as file:
            data = json.loads(file.read())
            self.assertEqual(
                m.json('http://localhost:1234/subSchemas.json#/integer'), data)

        with open(
                path((root, 'data', 'JSON-Schema-Test-Suite', 'draft4',
                      'refRemote', 'folder', 'folderInteger.json'))) as file:
            data = json.loads(file.read())
            self.assertEqual(
                m.json('http://localhost:1234/folder/folderInteger.json'),
                data)
def expand_paths(path_components):
    if type(path_components) == tuple:
        if path_components[-1].startswith('*.'):
            p = paths(path_components)
        else:
            p = [path(path_components)]
    elif type(path_components) == list:
        p = []
        for c in path_components:
            if c[-1].startswith('*.'):
                p.extend(paths(c))
            else:
                p.append(path(c))
    else:
        raise ValueError('path_components must either be a list or a tuple')
    return p
Exemple #3
0
 def run_errors(self, components):
     if components[-1].startswith('*.'):
         for p in paths(components):
             self.run_error_count(p)
     else:
         self.run_error_count(path(components))
Exemple #4
0
 def run_validation(self, components):
     if components[-1].startswith('*.'):
         for p in paths(components):
             self.run_is_valid(p)
     else:
         self.run_is_valid(path(components))
 def urlopen(self, url):
     components = self._components + urlparse(url).path.split('/')
     return self.MockData(open(path(components)))