Skip to content

Commit 5ae00f1

Browse files
Merge branch 'master' into example/01_setup_python_dependencies
2 parents 6d714b6 + 046293f commit 5ae00f1

25 files changed

+650
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130
.idea
131+
.vscode/
132+
data/

Pipfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ verify_ssl = true
88
[packages]
99
requests = "*"
1010
pytest = "*"
11+
assertpy = "*"
12+
lxml = "*"
13+
jsonpath-ng = "*"
14+
cerberus = "*"
15+
reportportal-client = "*"
16+
pytest-reportportal = "*"
17+
pytest-xdist = {extras = ["psutil"], version = "*"}
1118

1219
[requires]
1320
python_version = "3.10"

Pipfile.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,75 @@
1-
# course-api-framework-python
2-
TAU course on Building an API framework with python
1+
# Building an API test automation framework with Python
2+
3+
## Purpose
4+
5+
Code for TAU (Test automation university) course on building an API framework with Python. Once
6+
ready this would be published at
7+
[Test automation university](https://testautomationu.applitools.com/), You can also find a series of
8+
blogs that I'm writing for this course on my blog
9+
[https://automationhacks.io/](https://automationhacks.io/tags/) under `Python` tag. However, the
10+
video courses are going to have much more context and in depth discussions
11+
12+
## Setup
13+
14+
Ensure you have
15+
[pipenv already installed](https://automationhacks.io/2020/07/12/how-to-manage-your-python-virtualenvs-with-pipenv/):
16+
17+
```zsh
18+
# Activate virtualenv
19+
pipenv shell
20+
# Install all dependencies in your virtualenv
21+
pipenv install
22+
```
23+
24+
## How to navigate
25+
26+
Each chapter has its own dedicated branch in `/example/<chapter_no>_<topic>` format. For e.g.
27+
`example/01_setup_python_dependencies`
28+
29+
You can either use your IDE or terminal to switch to that branch and see the last updated commit.
30+
31+
```zsh
32+
# Checkout the entire branch
33+
git checkout example/01_setup_python_dependencies
34+
# Checkout to a specific commit, here <sha> can be found using `git log` command
35+
git checkout <sha>
36+
```
37+
38+
## Application under test
39+
40+
This automated test suite covers features of `people-api`, Please refer the Github repo
41+
[here](https://github.com/automationhacks/people-api).
42+
43+
Note: These tests expect the `people-api` and `covid-tracker` API to be up. You would find
44+
instructions in the `people-api` repo
45+
46+
## How to run
47+
48+
```zsh
49+
# Setup report portal on docker
50+
# Update rp_uuid in pytest.ini with project token
51+
docker-compose -f docker-compose.yml -p reportportal up -d
52+
53+
# Launch pipenv
54+
pipenv shell
55+
56+
# Install all packages
57+
pipenv install
58+
59+
# Run tests via pytest (single threaded)
60+
python -m pytest
61+
62+
# Run tests in parallel
63+
python -m pytest -n auto
64+
65+
# Report results to report portal
66+
python -m pytest -n auto ./tests --reportportal
67+
```
68+
69+
## Discuss?
70+
71+
Feel free to use the
72+
[Github discussions](https://github.com/automationhacks/course-api-framework-python/discussions/1)
73+
in this repo to ✍🏼 your thoughts or even use the disqus comments section on the blogs.
74+
75+
Happy learning!

clients/__init__.py

Whitespace-only changes.

clients/people/__init__.py

Whitespace-only changes.

clients/people/base_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class BaseClient:
2+
def __init__(self):
3+
self.headers = {
4+
'Content-Type': 'application/json',
5+
'Accept': 'application/json'
6+
}

clients/people/people_client.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from json import dumps
2+
from uuid import uuid4
3+
4+
from clients.people.base_client import BaseClient
5+
from config import BASE_URI
6+
from utils.request import APIRequest
7+
8+
9+
class PeopleClient(BaseClient):
10+
def __init__(self):
11+
super().__init__()
12+
13+
self.base_url = BASE_URI
14+
self.request = APIRequest()
15+
16+
def create_person(self, body=None):
17+
last_name, response = self.__create_person_with_unique_last_name(body)
18+
return last_name, response
19+
20+
def __create_person_with_unique_last_name(self, body=None):
21+
if body is None:
22+
last_name = f'User {str(uuid4())}'
23+
payload = dumps({
24+
'fname': 'New',
25+
'lname': last_name
26+
})
27+
else:
28+
last_name = body['lname']
29+
payload = dumps(body)
30+
31+
response = self.request.post(self.base_url, payload, self.headers)
32+
return last_name, response
33+
34+
def read_one_person_by_id(self, person_id):
35+
pass
36+
37+
def read_all_persons(self):
38+
return self.request.get(self.base_url)
39+
40+
def update_person(self):
41+
pass
42+
43+
def delete_person(self, person_id):
44+
url = f'{BASE_URI}/{person_id}'
45+
return self.request.delete(url)

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BASE_URI = 'http://0.0.0.0:5000/api/people'
2+
COVID_TRACKER_HOST = 'http://127.0.0.1:3000'

0 commit comments

Comments
 (0)