예제 #1
0
    def test_path_item(self):
        folder = get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'path_item')
        )

        def _pf(s):
            return six.moves.urllib.parse.urlunparse((
                'file',
                '',
                folder,
                '',
                '',
                s))

        app = App.create(folder)
        s = Scanner(app)
        c = CycleDetector()
        s.scan(root=app.raw, route=[c])
        self.assertEqual(sorted(c.cycles['path_item']), sorted([[
            _pf('/paths/~1p1'),
            _pf('/paths/~1p2'),
            _pf('/paths/~1p3'),
            _pf('/paths/~1p4'),
            _pf('/paths/~1p1')
        ]]))
예제 #2
0
 def test_random_name_v1_2(self):
     """
     """
     path = get_test_data_folder(version='1.2', which='random_file_name')
     path = os.path.join(path, 'test_random.json')
     # should not raise ValueError
     app = App.create(path)
예제 #3
0
    def test_v2_0(self):
        """ convert from 2.0 to 2.0 """
        path = get_test_data_folder(version='2.0', which='wordnik')
        app = App.create(path)

        # load swagger.json into dict
        origin = None
        with open(os.path.join(path, 'swagger.json')) as r:
            origin = json.loads(r.read())

        # diff for empty list or dict is allowed
        d = app.dump()
        self.assertEqual(
            sorted(_diff_(origin, d, exclude=['$ref'])),
            sorted([('paths/~1pet~1{petId}/get/security/0/api_key', "list",
                     "NoneType"),
                    ('paths/~1store~1inventory/get/parameters', None, None),
                    ('paths/~1store~1inventory/get/security/0/api_key', "list",
                     "NoneType"),
                    ('paths/~1user~1logout/get/parameters', None, None)]))

        # try to load the dumped dict back, to see if anything wrong
        tmp = {'_tmp_': {}}
        with SwaggerContext(tmp, '_tmp_') as ctx:
            ctx.parse(d)
예제 #4
0
    def test_float_dump(self):
        """ failed to dump an object with float property

        refer to issue: https://github.com/mission-liao/pyswagger/issues/92
        """
        app = App.create(get_test_data_folder(version='2.0', which=os.path.join('schema', 'floatDump')))
        app.dump() # should not raise exception
예제 #5
0
    def test_authorization(self):
        """
        """
        app = App.create(get_test_data_folder(
            version='1.2', which='simple_auth')
        )

        expect = {
            'type':'apiKey',
            'in':'query',
            'name':'simpleQK'
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_key').dump()
        ), [])

        expect = {
            'type':'apiKey',
            'in':'header',
            'name':'simpleHK'
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_key2').dump()
        ), [])


        expect = {
            'type':'basic',
        }
        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/simple_basic').dump()
        ), [])
예제 #6
0
    def test_deref(self):
        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'schema'),
        ),
                         strict=False)

        s = app.resolve('#/definitions/s1')
        self.assertRaises(errs.CycleDetectionError, utils.deref, s)
예제 #7
0
    def __get_or_create_app(self, url, cache_key):
        """ Get the app from cache or generate a new one if required

        Because app object doesn't have etag/expiry, we have to make
        a head() call before, to have these informations first... """
        headers = {"Accept": "application/json"}
        app_url = '%s?datasource=%s' % (url, self.datasource)

        cached = self.cache.get(cache_key, (None, None, 0))
        if cached is None or len(cached) != 3:
            self.cache.invalidate(cache_key)
            cached_app, cached_headers, cached_expiry = (cached, None, 0)
        else:
            cached_app, cached_headers, cached_expiry = cached

        if cached_app is not None and cached_headers is not None:
            # we didn't set custom expire, use header expiry
            expires = cached_headers.get('expires', None)
            cache_timeout = -1
            if self.expire is None and expires is not None:
                cache_timeout = get_cache_time_left(cached_headers['expires'])
                if cache_timeout >= 0:
                    return cached_app

            # we set custom expire, check this instead
            else:
                if self.expire == 0 or cached_expiry >= time.time():
                    return cached_app

            # if we have etags, add the header to use them
            etag = cached_headers.get('etag', None)
            if etag is not None:
                headers['If-None-Match'] = etag

            # if nothing makes us use the cache, invalidate it
            if ((expires is None or cache_timeout < 0
                 or cached_expiry < time.time()) and etag is None):
                self.cache.invalidate(cache_key)

        # set timeout value in case we have to cache it later
        timeout = 0
        if self.expire is not None and self.expire > 0:
            timeout = time.time() + self.expire

        # we are here, we know we have to make a head call...
        res = requests.head(app_url, headers=headers)
        if res.status_code == 304 and cached_app is not None:
            self.cache.set(cache_key, (cached_app, res.headers, timeout))
            return cached_app

        # ok, cache is not accurate, make the full stuff
        app = App.create(app_url)
        if self.caching:
            self.cache.set(cache_key, (app, res.headers, timeout))

        return app
예제 #8
0
    def test_primfactory(self):
        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'schema'),
            ),
            strict=False
        )

        s = app.resolve('#/definitions/s1')
        self.assertRaises(errs.CycleDetectionError, app.prim_factory.produce, s, {})
예제 #9
0
 def test_random_name_v1_2(self):
     """
     """
     path = get_test_data_folder(
         version='1.2',
         which='random_file_name'
     )
     path = os.path.join(path, 'test_random.json')
     # should not raise ValueError
     app = App.create(path)
예제 #10
0
    def test_primfactory(self):
        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'schema'),
            ),
            strict=False
        )

        s = app.resolve('#/definitions/s1')
        self.assertRaises(errs.CycleDetectionError, app.prim_factory.produce, s, {})
예제 #11
0
    def test_deref(self):
        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'schema'),
            ),
            strict=False
        )

        s = app.resolve('#/definitions/s1')
        self.assertRaises(errs.CycleDetectionError, utils.deref, s)
예제 #12
0
파일: app.py 프로젝트: akakjs/EsiPy
    def __get_or_create_app(self, app_url, cache_key):
        """ Get the app from cache or generate a new one if required """
        app = self.cache.get(cache_key, None)

        if app is None:
            app = App.create(app_url)
            if self.caching:
                self.cache.set(cache_key, app, self.expire)

        return app
예제 #13
0
 def test_empty_operation_id(self):
     """ when operationId is empty, should not raise SchemaError """
     try:
         app = App.create(
             get_test_data_folder(version="2.0",
                                  which=os.path.join("schema", "emptyOp")))
     except errs.SchemaError:
         self.fail(
             "SchemaError is raised when 'operationId' is empty and 'tags' is not"
         )
예제 #14
0
    def test_no_host_basePath(self):
        """ test case for swagger.json without
        'host' and 'basePath' defined
        """
        path = get_test_data_folder(
            version='2.0',
            which=os.path.join('patch', 'no_host_schemes')
        )
        fu = utils.normalize_url(path) # file uri version of path

        # load swagger.json from a file path
        app = App.create(path)
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//localhost/t1')
        self.assertEqual(req.schemes, ['file'])
        req.prepare(scheme='file', handle_files=False)
        self.assertEqual(req.url, 'file://localhost/t1')

        # load swagger.json from a file uri
        self.assertNotEqual(six.moves.urllib.parse.urlparse(fu).scheme, '')
        app = App.create(fu)
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//localhost/t1')
        self.assertEqual(req.schemes, ['file'])
        req.prepare(scheme='file', handle_files=False)
        self.assertEqual(req.url, 'file://localhost/t1')

        # load swagger.json from a remote uri
        def _hook(url):
            # no matter what url, return the path of local swagger.json
            return fu

        url = 'test.com/api/v1'
        app = App.load('https://'+url, url_load_hook=_hook)
        app.prepare()
        # try to make a Request and verify its url
        req, _ = app.s('t1').get()
        self.assertEqual(req.url, '//test.com/t1')
        self.assertEqual(req.schemes, ['https'])
        req.prepare(scheme='https', handle_files=False)
        self.assertEqual(req.url, 'https://test.com/t1')
예제 #15
0
    def __init__(
        self,
        api_key: str,
        swagger_file:
        str = "http://www.mingweisamuel.com/riotapi-schema/swaggerspec-2.0.yml"
    ):

        self.api_key = api_key
        self.swagger_file = swagger_file
        self.app = App.create(swagger_file)
        self.auth = Security(self.app)
        self.auth.update_with("api_key", api_key)
        self.client = Client(self.auth)
예제 #16
0
    def test_overwrite(self):
        """ overrite type/format handler used in pyswagger """
        m1 = self.app.resolve('#/definitions/m1')
        v = m1._prim_({"job": "man"}, self.app.prim_factory)
        # should not raise
        self.assertEqual(v.job, "man")

        app = App.create(
            get_test_data_folder(version='2.0',
                                 which=os.path.join('schema', 'extension')))
        m1 = app.resolve('#/definitions/m1')
        self.assertRaises(errs.ValidationError, m1._prim_, {'job': 'man'},
                          app.prim_factory)
예제 #17
0
    def test_cookie(self):
        global cookie_cache

        app = App.create(
            get_test_data_folder(version='2.0',
                                 which=os.path.join('io', 'cookie')))
        client = Webapp2TestClient(cookie_app, keep_cookie=True)
        resp = client.request(app.op['get_cookie']())
        self.assertEqual(resp.status, 200)

        resp = client.request(app.op['keep_cookie']())
        self.assertEqual(resp.status, 200)

        self.assertEqual(cookie_cache, 'test 123')
예제 #18
0
    def test_dict_getter_v2_0(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 2.0
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(
            version='2.0',
            which='wordnik'
        )

        origin_app = App.create(path)

        with open(os.path.join(path, 'swagger.json'), 'r') as f:
            spec = json.loads(f.read())

        getter = DictGetter([path], {
            os.path.join(path, 'swagger.json'): spec
        })
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump())), [])

        #
        # loading via wrong path, should be ok when all internal $ref are not absoluted
        #
        getter = DictGetter([''], {
            '': spec
        })
        app = App.load('', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])), [])

        #
        # faking http path
        #
        getter = DictGetter(['https://petstore.com'], {
            'https://petstore.com': spec
        })
        app = App.load('https://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])), [])
예제 #19
0
    def test_overwrite(self):
        """ overrite type/format handler used in pyswagger """
        m1 = self.app.resolve('#/definitions/m1')
        v = m1._prim_({
            "job":"man"
        }, self.app.prim_factory)
        # should not raise
        self.assertEqual(v.job, "man")

        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('schema', 'extension')
        ))
        m1 = app.resolve('#/definitions/m1')
        self.assertRaises(errs.ValidationError, m1._prim_, {'job':'man'}, app.prim_factory)
예제 #20
0
    def test_cookie(self):
        global cookie_cache

        app = App.create(get_test_data_folder(
            version='2.0',
            which=os.path.join('io', 'cookie')
        ))
        client = Webapp2TestClient(cookie_app, keep_cookie=True)
        resp = client.request(app.op['get_cookie']())
        self.assertEqual(resp.status, 200)

        resp = client.request(app.op['keep_cookie']())
        self.assertEqual(resp.status, 200)

        self.assertEqual(cookie_cache, 'test 123')
예제 #21
0
    def test_dict_getter_v2_0(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 2.0
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(version='2.0', which='wordnik')

        origin_app = App.create(path)

        with open(os.path.join(path, 'swagger.json'), 'r') as f:
            spec = json.loads(f.read())

        getter = DictGetter([path], {os.path.join(path, 'swagger.json'): spec})
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), origin_app.dump())), [])

        #
        # loading via wrong path, should be ok when all internal $ref are not absoluted
        #
        getter = DictGetter([''], {'': spec})
        app = App.load('', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(
            sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])),
            [])

        #
        # faking http path
        #
        getter = DictGetter(['https://petstore.com'],
                            {'https://petstore.com': spec})
        app = App.load('https://petstore.com',
                       resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(
            sorted(_diff_(app.dump(), origin_app.dump(), exclude=['$ref'])),
            [])
예제 #22
0
    def test_load_from_url_without_file(self):
        """ try to load from a url withou swagger.json """
        data = None
        with open(os.path.join(get_test_data_folder(
            version='2.0',
            which='wordnik'), 'swagger.json')) as f:
            data = f.read()

        httpretty.register_uri(
            httpretty.GET,
            'http://10.0.0.10:8080/swaggerapi/api/v1beta2',
            body=data
        )

        # no exception should be raised
        app = App.create('http://10.0.0.10:8080/swaggerapi/api/v1beta2')
        self.assertTrue(app.schemes, ['http'])
        self.assertTrue(isinstance(app.root, BaseObj))
예제 #23
0
    def test_token_endpoint(self):
        """
        """
        app = App.create(
            get_test_data_folder(version='1.2', which='simple_auth'))

        expect = {
            'tokenUrl': 'http://petstore.swagger.wordnik.com/api/oauth/token',
            'type': 'oauth2',
            'flow': 'access_code',
            'scopes': {
                'test:anything': 'for testing purpose'
            }
        }

        self.assertEqual(
            _diff_(expect,
                   app.resolve('#/securityDefinitions/oauth2').dump()), [])
예제 #24
0
    def test_path_item(self):
        folder = utils.normalize_url(get_test_data_folder(
            version='2.0',
            which=os.path.join('circular', 'path_item')
        ))

        def _pf(s):
            return folder + '#' + s

        app = App.create(folder)
        s = Scanner(app)
        c = CycleDetector()
        s.scan(root=app.raw, route=[c])
        self.assertEqual(sorted(c.cycles['path_item']), sorted([[
            _pf('/paths/~1p1'),
            _pf('/paths/~1p2'),
            _pf('/paths/~1p3'),
            _pf('/paths/~1p4'),
            _pf('/paths/~1p1')
        ]]))
예제 #25
0
    def test_token_endpoint(self):
        """
        """
        app = App.create(get_test_data_folder(
            version='1.2', which='simple_auth')
        )

        expect={
            'tokenUrl':'http://petstore.swagger.wordnik.com/api/oauth/token',
            'type':'oauth2',
            'flow':'access_code',
            'scopes': {
                'test:anything':'for testing purpose'
            }
        }

        self.assertEqual(_diff_(
            expect,
            app.resolve('#/securityDefinitions/oauth2').dump()
        ), [])
예제 #26
0
    def test_path_item(self):
        folder = utils.normalize_url(
            get_test_data_folder(version='2.0',
                                 which=os.path.join('circular', 'path_item')))

        def _pf(s):
            return folder + '#' + s

        app = App.create(folder)
        s = Scanner(app)
        c = CycleDetector()
        s.scan(root=app.raw, route=[c])
        self.assertEqual(
            sorted(c.cycles['path_item']),
            sorted([[
                _pf('/paths/~1p1'),
                _pf('/paths/~1p2'),
                _pf('/paths/~1p3'),
                _pf('/paths/~1p4'),
                _pf('/paths/~1p1')
            ]]))
예제 #27
0
    def test_v2_0(self):
        """ convert from 2.0 to 2.0 """
        path = get_test_data_folder(version='2.0', which='wordnik')
        app = App.create(path)

        # load swagger.json into dict
        origin = None
        with open(os.path.join(path, 'swagger.json')) as r:
            origin = json.loads(r.read())

        # diff for empty list or dict is allowed
        d = app.dump()
        self.assertEqual(sorted(_diff_(origin, d, exclude=['$ref'])), sorted([
            ('paths/~1pet~1{petId}/get/security/0/api_key', "list", "NoneType"),
            ('paths/~1store~1inventory/get/parameters', None, None),
            ('paths/~1store~1inventory/get/security/0/api_key', "list", "NoneType"),
            ('paths/~1user~1logout/get/parameters', None, None)
        ]))

        # try to load the dumped dict back, to see if anything wrong
        tmp = {'_tmp_': {}}
        with SwaggerContext(tmp, '_tmp_') as ctx:
            ctx.parse(d)
예제 #28
0
    def test_authorization(self):
        """
        """
        app = App.create(
            get_test_data_folder(version='1.2', which='simple_auth'))

        expect = {'type': 'apiKey', 'in': 'query', 'name': 'simpleQK'}
        self.assertEqual(
            _diff_(expect,
                   app.resolve('#/securityDefinitions/simple_key').dump()), [])

        expect = {'type': 'apiKey', 'in': 'header', 'name': 'simpleHK'}
        self.assertEqual(
            _diff_(expect,
                   app.resolve('#/securityDefinitions/simple_key2').dump()),
            [])

        expect = {
            'type': 'basic',
        }
        self.assertEqual(
            _diff_(expect,
                   app.resolve('#/securityDefinitions/simple_basic').dump()),
            [])
예제 #29
0
 def setUpClass(kls):
     kls.app = App.create(get_test_data_folder(
         which=path.join('operation')
     ))
     kls.rnd = FakeRequestRenderer()
예제 #30
0
def app():
    spec_path = os.path.join(os.path.dirname(__file__), '..', '..', 'share',
                             'api', 'swagger.yaml')
    return App.create(spec_path)
예제 #31
0
 def update_logger(self, url):
     self.logger = App.create(url)
예제 #32
0
 def __init__(self, url=URL):
     self.url = url
     self.logger = App.create(url)
예제 #33
0
파일: request.py 프로젝트: chaharv/privapi
 def _api_to_requests(self, fname, org):
     self.app = App.create(fname)
     self.org = org
     s = Scanner(self.app)
     s.scan(route=[self], root=self.app.raw)
예제 #34
0
 def test_create(self):
     """ make sure we could load a yml with status-code in int """
     app = App.create(get_test_data_folder(
         version='2.0',
         which='yaml'
     ))
예제 #35
0
    def test_dict_getter_v1_2(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 1.2
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(version='1.2', which='wordnik')

        path_resource_list = os.path.join(path, 'resource_list.json')
        path_pet = os.path.join(path, 'pet.json')
        path_store = os.path.join(path, 'store.json')
        path_user = os.path.join(path, 'user.json')
        with open(path_resource_list, 'r') as f:
            resource_list = json.loads(f.read())
        with open(path_pet, 'r') as f:
            pet = json.loads(f.read())
        with open(path_store, 'r') as f:
            store = json.loads(f.read())
        with open(path_user, 'r') as f:
            user = json.loads(f.read())

        getter = DictGetter(
            [
                path_resource_list,
                path_pet,
                path_user,
                path_store,
            ], {
                path_resource_list: resource_list,
                path_pet: pet,
                path_store: store,
                path_user: user,
            })
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(),
                                       App.create(path).dump())), [])

        #
        # different path, mocking an url
        #
        getter = DictGetter(
            [
                'http://petstore.com',
                'http://petstore.com/pet.json',
                'http://petstore.com/user.json',
                'http://petstore.com/store.json',
            ], {
                'http://petstore.com': resource_list,
                'http://petstore.com/pet.json': pet,
                'http://petstore.com/store.json': store,
                'http://petstore.com/user.json': user
            })
        app = App.load('http://petstore.com',
                       resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(
            sorted(
                _diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])),
            [])

        #
        # provide empty path
        #
        getter = DictGetter(
            [
                '',
                'pet.json',
                'user.json',
                'store.json',
            ], {
                '': resource_list,
                'pet.json': pet,
                'store.json': store,
                'user.json': user
            })
        app = App.load('http://petstore.com',
                       resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(
            sorted(
                _diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])),
            [])
예제 #36
0
def get_esi_app():
    return App.create('https://esi.evetech.net/latest/swagger.json')
예제 #37
0
def get_api() -> App:
    global cached_api
    if cached_api is None:
        cached_api = App.create('resources/swagger.json')
    return cached_api
예제 #38
0
 def setUpClass(kls):
     kls.app = App.create(get_test_data_folder(
         version='2.0',
         which=path.join('render', 'operation')
     ))
     kls.rnd = Renderer()
예제 #39
0
 def test_create(self):
     """ make sure we could load a yml with status-code in int """
     app = App.create(get_test_data_folder(version='2.0', which='yaml'))
예제 #40
0
 def setUpClass(kls):
     kls.app = App.create(get_test_data_folder(
         version='2.0',
         which=path.join('render', 'operation')
     ))
     kls.rnd = Renderer()
예제 #41
0
 def setUpClass(kls):
     kls.app = App.create(
         get_test_data_folder(version='2.0',
                              which=os.path.join('io', 'response')))
예제 #42
0
from pyswagger import App
from pyswagger.contrib.client.requests import Client

# load Swagger resource file into App object
app = App.create(
    'https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility')
swaggerclient = Client()

response = swaggerclient.request(app.op['post_universe_names'](ids={
    ids: [35, 165]
}))

# auth = Security(app)
# auth.update_with('api_key', '12312312312312312313q') # api key
# auth.update_with('petstore_auth', '12334546556521123fsfss') # oauth2

# # init swagger client
# client = Client(auth)

# # a dict is enough for representing a Model in Swagger
# pet_Tom=dict(id=1, name='Tom', photoUrls=['http://test'])
# # a request to create a new pet
# client.request(app.op['addPet'](body=pet_Tom))

# # - access an Operation object via App.op when operationId is defined
# # - a request to get the pet back
# pet = client.request(app.op['getPetById'](petId=1)).data
# assert pet.id == 1
# assert pet.name == 'Tom'

# # new ways to get Operation object corresponding to 'getPetById'.
예제 #43
0
 def test_empty_operation_id(self):
     """ when operationId is empty, should not raise SchemaError """
     try:
         app = App.create(get_test_data_folder(version="2.0", which=os.path.join("schema", "emptyOp")))
     except errs.SchemaError:
         self.fail("SchemaError is raised when 'operationId' is empty and 'tags' is not")
예제 #44
0
    def test_dict_getter_v1_2(self):
        """ make sure 'DictGetter' works the same as 'LocalGetter'
        for Swagger 1.2
        """

        #
        # loading via DictGetter
        #
        path = get_test_data_folder(
            version='1.2',
            which='wordnik'
        )

        path_resource_list = os.path.join(path, 'resource_list.json')
        path_pet = os.path.join(path, 'pet.json')
        path_store = os.path.join(path, 'store.json')
        path_user = os.path.join(path, 'user.json')
        with open(path_resource_list, 'r') as f:
            resource_list = json.loads(f.read())
        with open(path_pet, 'r') as f:
            pet = json.loads(f.read())
        with open(path_store, 'r') as f:
            store = json.loads(f.read())
        with open(path_user, 'r') as f:
            user = json.loads(f.read())

        getter = DictGetter([
            path_resource_list,
            path_pet,
            path_user,
            path_store,
        ], {
            path_resource_list: resource_list,
            path_pet: pet,
            path_store: store,
            path_user: user,
        })
        app = App.load(path, resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump())), [])

        #
        # different path, mocking an url
        #
        getter = DictGetter([
            'http://petstore.com',
            'http://petstore.com/pet.json',
            'http://petstore.com/user.json',
            'http://petstore.com/store.json',
        ], {
            'http://petstore.com': resource_list,
            'http://petstore.com/pet.json': pet,
            'http://petstore.com/store.json': store,
            'http://petstore.com/user.json': user
        })
        app = App.load('http://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])), [])

        #
        # provide empty path
        #
        getter = DictGetter([
            '',
            'pet.json',
            'user.json',
            'store.json',
        ], {
            '': resource_list,
            'pet.json': pet,
            'store.json': store,
            'user.json': user
        })
        app = App.load('http://petstore.com', resolver=Resolver(default_getter=getter))
        app.prepare()

        # make sure it produce the same App in default way
        self.assertEqual(sorted(_diff_(app.dump(), App.create(path).dump(), exclude=['$ref'])), [])
예제 #45
0
 def setUpClass(kls):
     kls.app = App.create(get_test_data_folder(
         version='2.0',
         which=os.path.join('io', 'response')
     ))
예제 #46
0
 def setUpClass(kls):
     kls.app = App.create(get_test_data_folder(
         version='1.2',
         which='wordnik'
     ))