Pyclinic

Latest version: v0.3.3

Safety actively analyzes 622315 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.3.0

Overview

PyClinic can now automatically generate functions from **Swagger2** Spec Files! 🚀 🎉

How to use

Identical to the `OpenAPI` runner, there is now a `Swagger` class.

python
from pyclinic.swagger import Swagger

spec_path = "./tests/examples/petstore.swagger2.json"
runner = Swagger(spec_path)
response = runner.Pet.add_pet()

> 💡 For more details, check out the `demo_openapi3_runner.ipynb` notebook since the experience for Swagger 2 and OpenAPI 3 are basically the same 👀

0.2.0

Overview

PyClinic can now automatically generate functions from **OpenApi3** Spec Files! 🌮 🎉

How to use

Similar to the Postman runner, there is now an `OpenApi` class

python
from pyclinic.openapi import OpenApi

collection_path = "./tests/examples/petstore.openapi3.yaml"
runner = OpenApi(collection_path)
response = runner.Pet.add_pet()

> 💡 For more details, check out the `demo_openapi3_runner.ipynb` notebook 👀

0.1.6

Overview

PostmanFolder objects have a `.help()` method so you can see which request functions it includes. However, in practice, it was much more helpful to have more info about the request function!

So, we have added a `.help()` method to PostmanExecutableRequest objects.

Example

python
runner = Postman("bookstore.postman_collection.json")
runner.Account.create_user.help()

""" Output:
{
'method': 'POST',
'url': 'https://demoqa.com/Account/v1/User',
'data': {'userName': '{{$randomFullName}}', 'password': 'P$$w0rd'},
'headers': {}
}
"""


More Info

> 💡 Please checkout the [README at our GitHub Repo](https://github.com/ElSnoMan/pyclinic) for more information

Detailed Example

> 💪🏽 Refer to the [demo_postman_runner.ipynb](https://github.com/ElSnoMan/pyclinic/blob/main/demo_postman_runner.ipynb) notebook for a guide that dives deeper into how to practically use PyClinic 😎

v.0.1.4

0.1.4

I recommend checking our the [README](https://github.com/ElSnoMan/pyclinic) since it goes over a lot of stuff:

- Quickstart
- In-Depth Example
- Automated Test Example
- Working with Variables
- Setup and Contribute

This release included the `pyclinic` CLI tool to extract Pydantic Models from a Postman Collection as well as more easily showing the Folder and Functions that are parsed when making an instance of the `Postman` runner.

We still aren't at V1, but I would appreciate any questions or feedback you have to make this tool even better. Right now it mainly supports Postman Collections, so create a collection, export it, and give PyClinic a try!

> Remember, the entire purpose of PyClinic is to make it easier to do Service Testing, so any feedback or ideas you have towards this goal is super helpful! Thanks 😊 🙏

0.1.0

Overview

Pyclinic is a library to make it easier and faster to get your Service Testing up and running! With the first release, we wanted to focus on integrating with Postman users so you can export a Postman Collection and use it to automatically generate python functions!

> 💡 This allows you to quickly write automation to work with many endpoints or even write automated tests against those endpoints!

Simple Example

1. Export your Postman Collection (as `example.postman_collection.json`, for example)

2. Make an instance of `Postman` and pass in the file path to your JSON file

python
from pyclinic.postman import Postman

runner = Postman("example.postman_collection.json")


3. Then call the endpoint function!

python
runner.Pets.list_all_pets()


In-depth Example

When you instantiate `Postman()`, it converts the Postman Collection JSON and turns each request to an executable function!

Take this [Deck of Cards API Collection](https://github.com/ElSnoMan/pyclinic/blob/main/tests/examples/deckofcards.postman_collection.json) example. Here is what the folder structure looks like in Postman:

- Root
- ↪️ Create shuffled deck
- 📂 Folder 1
- ↪ Reshuffle Deck
- 📂 Folder 1.1
- ↪️ Draw Cards
- 📂 Folder 2
- ↪️ List Cards in Piles

1. Make an instance of Postman

python
from pyclinic.postman import Postman

runner = Postman("deckofcards.postman_collection.json")


2. To call the `Create shuffle deck` endpoint at the Collection Root, you would use

python
response = runner.Root.create_shuffled_deck()
`

3. Then do what you need with the Response!

> 💡 pyclinic uses the `requests` library to make requests and to work with responses!

python
assert response.ok
print(response.json())

"""
Output:
{
"success": true,
"deck_id": "3p40paa87x90",
"shuffled": true,
"remaining": 52
}
"""


4. If you want to call the `Draw Cards` item under `Folder 1 > Folder 1.1`, then use:

python
response = runner.Folder11.draw_cards()


> 💡 All folders in the Postman Collection are flattened, so you don't have to do `runner.Folder1.Folder11.draw_cards()`

Normalizing Folder Names and Function Names

Observe how, in the last example with `runner.Folder11.draw_cards()`, each Postman item name is turned into Pythonic syntax:

- Folders are turned into classes, so `Folder 1` turns into `Folder1`
- Requests are turned into functions, so `Draw Cards` turns into `draw_cards`

Work with them like normal functions

python
def test_deckofcards_multiple_calls():
runner = Postman("deckofcards.postman_collection.json")

create_response = runner.Root.create_shuffled_deck()
deck_id = create_response.json().get("deck_id")

response = runner.Folder11.draw_cards({"deck_id": deck_id})
assert response.ok
assert len(response.json()["cards"]) == 2, "Should draw two cards from deck"

Links

Releases

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.