Skip to content

Chapter1 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: example/01_setup_python_dependencies
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
785a6c8
Added a test for read all API of people application and which makes u…
Aug 4, 2020
e72acc1
Updated README.md
Aug 4, 2020
e4a208c
Merging 01_setup_python_dependencies into master
Nov 25, 2020
edc7e8a
Added assert py into Pipfile
Nov 25, 2020
09caa48
Added test to show use of POST method to create a new person and asse…
Nov 25, 2020
ae5ac93
- Added test to show use of POST method to create a new person and as…
Nov 25, 2020
1a494c4
Showing off user of requests.codes to have readable http codes
Nov 25, 2020
ec6c3cd
Extracted create person into its own method and added test for delete…
Nov 27, 2020
342f060
Extracted search for users as a function
Nov 27, 2020
3f9fc63
Removed explicit assertion since that is already made within create u…
Nov 27, 2020
2ca9964
Replaced get methods assetions with assertpy's fluent assertion
Dec 1, 2020
657cf98
Added lxml dependency and covid_test.py to demo how to work with xml …
Dec 14, 2020
d369979
Added another test to show couple of ways we can get values from XML …
Dec 15, 2020
d2d9252
- Added a json file to store the template for a request
Dec 22, 2020
701791c
Formatted json
Dec 25, 2020
becf0d7
Added example of schema validation for Read all operation in people API
Dec 27, 2020
2ed2046
Extracted schema outside the functions and added a separate function …
Dec 28, 2020
e8c0016
Updated schema tests to use assertpy fluent assertions to validate in…
Dec 28, 2020
6204734
- Abstracted API methods into a people_client which makes use of a cu…
Dec 28, 2020
e5fe846
- Created BaseClient with default headers
Dec 28, 2020
8d2157d
Replaced specific method imports with *
Dec 29, 2020
77c7702
Updated README.md
Dec 29, 2020
69034c7
Added docker-compose for report portal
Jan 20, 2021
dec1b56
Added report portal agent into dependencies and added config for loca…
Jan 20, 2021
33308f2
Added logger in conftest.py and updated a test method to log to the c…
Jan 20, 2021
b390b1b
Updated docker-compose to generate report portal environment, Updated…
Feb 2, 2021
d4482fa
- Added pytest-xdist to Pipfile
Feb 23, 2021
924e0fa
Updated readme
Feb 23, 2021
c8dd36a
Bump lxml from 4.6.2 to 4.6.5
dependabot[bot] Dec 13, 2021
7977ac5
Merge pull request #7 from automationhacks/dependabot/pip/lxml-4.6.5
automationhacks Mar 12, 2022
046293f
Updated dependencies versions
Mar 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ dmypy.json
# Pyre type checker
.pyre/
.idea
.vscode/
data/
7 changes: 7 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ verify_ssl = true
[packages]
requests = "*"
pytest = "*"
assertpy = "*"
lxml = "*"
jsonpath-ng = "*"
cerberus = "*"
reportportal-client = "*"
pytest-reportportal = "*"
pytest-xdist = {extras = ["psutil"], version = "*"}

[requires]
python_version = "3.8"
308 changes: 259 additions & 49 deletions Pipfile.lock

Large diffs are not rendered by default.

77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
# course-api-framework-python
TAU course on Building an API framework with python
# Building an API test automation framework with Python

## Purpose

Code for TAU (Test automation university) course on building an API framework with Python. Once
ready this would be published at
[Test automation university](https://testautomationu.applitools.com/), You can also find a series of
blogs that I'm writing for this course on my blog
[https://automationhacks.io/](https://automationhacks.io/tags/) under `Python` tag. However, the
video courses are going to have much more context and in depth discussions

## Setup

Ensure you have
[pipenv already installed](https://automationhacks.io/2020/07/12/how-to-manage-your-python-virtualenvs-with-pipenv/):

```zsh
# Activate virtualenv
pipenv shell
# Install all dependencies in your virtualenv
pipenv install
```

## How to navigate

Each chapter has its own dedicated branch in `/example/<chapter_no>_<topic>` format. For e.g.
`example/01_setup_python_dependencies`

You can either use your IDE or terminal to switch to that branch and see the last updated commit.

```zsh
# Checkout the entire branch
git checkout example/01_setup_python_dependencies
# Checkout to a specific commit, here <sha> can be found using `git log` command
git checkout <sha>
```

## Application under test

This automated test suite covers features of `people-api`, Please refer the Github repo
[here](https://github.com/automationhacks/people-api).

Note: These tests expect the `people-api` and `covid-tracker` API to be up. You would find
instructions in the `people-api` repo

## How to run

```zsh
# Setup report portal on docker
# Update rp_uuid in pytest.ini with project token
docker-compose -f docker-compose.yml -p reportportal up -d

# Launch pipenv
pipenv shell

# Install all packages
pipenv install

# Run tests via pytest (single threaded)
python -m pytest

# Run tests in parallel
python -m pytest -n auto

# Report results to report portal
python -m pytest -n auto ./tests --reportportal
```

## Discuss?

Feel free to use the
[Github discussions](https://github.com/automationhacks/course-api-framework-python/discussions/1)
in this repo to ✍🏼 your thoughts or even use the disqus comments section on the blogs.

Happy learning!
Empty file added clients/__init__.py
Empty file.
Empty file added clients/people/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions clients/people/base_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class BaseClient:
def __init__(self):
self.headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
45 changes: 45 additions & 0 deletions clients/people/people_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from json import dumps
from uuid import uuid4

from clients.people.base_client import BaseClient
from config import BASE_URI
from utils.request import APIRequest


class PeopleClient(BaseClient):
def __init__(self):
super().__init__()

self.base_url = BASE_URI
self.request = APIRequest()

def create_person(self, body=None):
last_name, response = self.__create_person_with_unique_last_name(body)
return last_name, response

def __create_person_with_unique_last_name(self, body=None):
if body is None:
last_name = f'User {str(uuid4())}'
payload = dumps({
'fname': 'New',
'lname': last_name
})
else:
last_name = body['lname']
payload = dumps(body)

response = self.request.post(self.base_url, payload, self.headers)
return last_name, response

def read_one_person_by_id(self, person_id):
pass

def read_all_persons(self):
return self.request.get(self.base_url)

def update_person(self):
pass

def delete_person(self, person_id):
url = f'{BASE_URI}/{person_id}'
return self.request.delete(url)
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_URI = 'http://0.0.0.0:5000/api/people'
COVID_TRACKER_HOST = 'http://127.0.0.1:3000'
Loading