Skip to content

Commit 0057625

Browse files
Initial commit - API Automation Framework setup
1 parent c3801f6 commit 0057625

23 files changed

+130
-0
lines changed

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/api-automation-framework-python.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configurations/config.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[restfulBooker]
2+
base_url = https://restful-booker.herokuapp.com

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

service/__init__.py

Whitespace-only changes.
222 Bytes
Binary file not shown.
1.32 KB
Binary file not shown.
1.91 KB
Binary file not shown.
Binary file not shown.

service/api_client.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from utilities.read_properties import ReadConfig
2+
from tests.conftest import access_token
3+
from service.api_request import APIRequest
4+
5+
api_request = APIRequest()
6+
7+
class APIClient:
8+
def __init__(self):
9+
self.base_url = ReadConfig.get_base_url()
10+
self.token = access_token()
11+
12+
print(self.token)
13+
14+
def get_booking_ids(self):
15+
return api_request.get_booking_ids(base_url=self.base_url, token= self.token)
16+
17+

service/api_request.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import requests
2+
from dataclasses import dataclass
3+
4+
@dataclass
5+
class APIResponse:
6+
status_code : str
7+
text : str
8+
as_dict : object
9+
headers : dict
10+
11+
class APIRequest:
12+
'''
13+
GET , POST , PUT , DELETE and collect all resp
14+
'''
15+
16+
def get_response(self, response):
17+
status_code = response.status_code
18+
text = response.text
19+
headers = response.headers
20+
try:
21+
as_dict = response.json()
22+
except Exception:
23+
as_dict = {}
24+
25+
return APIResponse(status_code, text, as_dict, headers)
26+
27+
# GET
28+
def get_booking_ids(self, base_url, token):
29+
url = f"{base_url}/booking"
30+
headers = {
31+
"Content-Type": "application/json",
32+
"Authorization": token
33+
}
34+
35+
response = requests.request("GET", url=url, headers=headers)
36+
return self.get_response(response)
37+
38+
39+
40+

tests/__init__.py

Whitespace-only changes.
220 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/conftest.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
3+
base_url = "https://restful-booker.herokuapp.com"
4+
5+
def access_token():
6+
url = f"{base_url}/auth"
7+
headers = {"Content-Type": "application/json"}
8+
data = {"username": "admin", "password": "password123"}
9+
10+
response = requests.request("POST", url=url, headers=headers, json=data)
11+
token = response.json()["token"]
12+
return token
13+
14+
15+
16+

tests/test_api.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from service.api_client import APIClient
2+
api_client = APIClient()
3+
4+
def test_get_booking_ids():
5+
response = api_client.get_booking_ids()
6+
assert response.status_code == 200
7+
Binary file not shown.

utilities/read_properties.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import configparser
2+
3+
config =configparser.ConfigParser()
4+
config.read("configurations/config.ini")
5+
6+
class ReadConfig:
7+
@staticmethod
8+
def get_base_url():
9+
return config.get("restfulBooker", "base_url")

0 commit comments

Comments
 (0)