def testRun(self):
        """Verify plain RestAPI GET request"""
        try:
            json_str = self.setup_class()
            if json_str['url4']['path']:
                url = constructURL.constURL(
                    baseurl=json_str['url4']['baseurl'],
                    path=json_str['url4']['path'])
            else:
                url = json_str['url4']['baseurl']

            json = json_str['url4']['json']

            req = Api(url=url)

            resp = req.put(json=json)
            self.assertEqual(200, resp.status_code)
            response_type = resp.headers["content-type"]
            if re.search(r'json', response_type):
                response = resp.json()
            else:
                raise Exception("Response type is not json")
        except Exception as e:
            print("Exception occurred during test run", e)

        self.assertEqual("zion resident", response['job'])
Exemple #2
0
    def testRun(self):
        log = logging.getLogger('Running example test for REST GET Request')
        try:
            json_str = self.setup_class()
            log.debug("Constructing URL")
            if json_str['url1']['path']:
                url = constructURL.constURL(
                    baseurl=json_str['url1']['baseurl'],
                    path=json_str['url1']['path'])
            else:
                url = json_str['url1']['baseurl']

            req = Api(url=url)

            log.debug("Check response of GET Request")
            resp = req.get()
            print "Checking response type"
            print type(resp)
            self.assertEqual(200, resp.status_code)
        except Exception as e:
            print("Exception occurred during test run", e)

        log.debug("Verifying response type is json")
        response_type = resp.headers["content-type"]
        if re.search(r'json', response_type):
            response = resp.json()
        else:
            sys.exit()

        log.debug("Finally verify test case expected output")
        self.assertEqual("Afghanistan",
                         response['RestResponse']['result'][0]['name'])
    def runTest(baseurl,
                path,
                params=None,
                body=None,
                json=None,
                data=None,
                files=None,
                auth=None,
                method=None,
                dataCount=0):

        try:
            url = constructURL.constURL(baseurl=baseurl, path=path)

            req = Api(url=url)

            if params:
                params = DataRead.readData(params)
                params = DataRead.dataDict(params, dataCount)

            if data:
                data = DataRead.readData(data)
                data = DataRead.dataDict(data, dataCount)

            if json:
                json = DataRead.readData(json)
                json = DataRead.dataDict(json, dataCount)

            if method == 'get':
                resp = req.get(params=params)
            elif method == 'post':
                resp = req.post(json=json, data=data)
            elif method == 'put':
                resp = req.put(params=params, json=json, data=data)
            else:
                resp = req.delete(params=params,
                                  json=json,
                                  data=data,
                                  body=body)

        except Exception as e:
            print("Exception occurred during runner as", e)

        return resp
    def runTest(baseurl,
                path,
                params=None,
                body=None,
                json=None,
                data=None,
                files=None,
                auth=None,
                method=None):

        try:
            url = constructURL.constURL(baseurl=baseurl, path=path)

            if params:
                params = Paramparser.parse(params)

            if json:
                json = Paramparser.parse(json)

            if data:
                data = Paramparser.parse(data)

            if body:
                body = Paramparser.parse(body)

            req = Api(url=url)

            if method == 'get':
                resp = req.get(params=params)
            elif method == 'post':
                resp = req.post(json=json, data=data)
            elif method == 'put':
                resp = req.put(params=params, json=json, data=data)
            else:
                resp = req.delete(params=params,
                                  json=json,
                                  data=data,
                                  body=body)
        except Exception as e:
            print("Runner failed with exception", e)

        return resp