RESTI API Automation using python

Install the below packages

1.Install Python

2.Install Pytest (command -pip install pytest)

3.Install requests (command-pip install requests)

4.Install unittests (command-pip install unitest)


POST REQUEST

import unittest
import json
import requests
import pytest

class UserCreate(unittest.TestCase):
   
   @pytest.mark.run(order=1)
    def test_positive_usercreate(self):

     url = ('your POST API)

     headers = {'Content-type': 'application/json'}

     body = {

            'deviceId': 'your device id',  
            'notificationId': 'null',
            'manufacturingDetails': 'null',
            'advertisementId': 'null',
            'platform': 'android',
            'deviceToken': 'your device token'        }

     response = requests.post(url, data=json.dumps(body), headers=headers)
     print(json.dumps(response.json(), indent=4))
     print(response.status_code)
     print(response.headers)
     assert True



PUT REQUEST

import unittest
import json
import requests
import urllib3


class FbUserProfilePUT(unittest.TestCase):


  def test_FBuserprofilePUT(self):

        url = "Your PUT API"
          

        headers = {'Content-type': 'application/json', 'SessionKey': '6cfc6f16-c92d-4857-       a14c-12c278ec7a9c', 'UserKey':'b37bae03-a4ee-4af9-9c81-b6b1271af522'}

        body ={

            'education': 'BE', 
            'channel': 'Fb', 
            'email': '', 
            'mobileNumber': '',
            'name': '',
            'language': '', 
            'gender': ''        }

        response = requests.get(url, data=json.dumps(body), headers=headers)
        print(json.dumps(response.json(), indent=4))
        print(response.status_code)
        print(response.headers)


GET REQUEST

import unittest
import json
import requests
import  pytest


class UserSettingsGetLat(unittest.TestCase):

  @pytest.mark.run(order=1)
  def test_positive_usersettingsGETlat(self):

        url = "ypur GET API"
        headers = {'Content-type': 'application/json', 'SessionKey': '6cfc6f16-c92d-4857-a14c-12c278ec7a9c'}

        response = requests.get(url, data=json.dumps(headers), headers=headers)
        print(json.dumps(response.json(), indent=4))
        print(response.status_code)
        print(response.headers)



Download sample project

https://github.com/ManjunathDjm/REST-API-automation-using-python-pytest















Comments