class APITester():
    def __init__(self, swaggerFile, apiCaller, basepath=None):
        self._parser = SwaggerParser(swagger_path=swaggerFile)
        self._apiCaller = apiCaller
        self._basepath = self._parser.base_path if (basepath is None) else basepath

    def doTest(self):
        expectedSchema = genson.Schema()
        observedSchema = genson.Schema()

        for path, pathSpec in self._parser.paths.iteritems():
            callPath = path

            # If a baseURL different from the the one specified in swaggerFile
            # then we the default for the given one.
            if self._basepath!=self._parser.base_path:
                callPath = callPath.replace(self._parser.base_path, self._basepath)

            for method, methodDesc in pathSpec.iteritems():
                for status, responseClass in methodDesc['responses'].iteritems():
                    if not status == '200':
                        # print '   Ignoring non 200 status:', status, responseClass
                        continue

                    if method=='get':
                        # Is self the best way to get the expected repsonse ?
                        expectedResponse = self._parser.get_response_example(self._parser.paths[path][method]['responses'][status])
                        observedResponse = self._apiCaller.get(callPath)
                    elif method=='post':
                        dummyData = self._parser.get_send_request_correct_body(path, 'post')
                        expectedResponse = self._parser.get_response_example(self._parser.paths[path][method]['responses'][status])
                        observedResponse = self._apiCaller.post(callPath, dummyData)
                    else:
                        print 'What do we do for method',method,'?'
                        continue

                    expected = expectedSchema.add_object(expectedResponse).to_dict()
                    observed = observedSchema.add_object(observedResponse).to_dict()

                    if expected!=observed:
                        listDiffs = getDictDiff(expected, observed)
                        raise APIException('API response does not match schema while calling: ' + path, listDiffs)