Skip to content

LaidonerS/api-testing-lab

Repository files navigation

Absolutely — I’ll rebuild the entire README.md with clean formatting, proper spacing, headings, icons, consistent style, and great readability for GitHub.

This version is copy-paste ready, fully structured, and looks professional + human-written.


🌤️ Weatherstack API Testing Lab

A compact Python project for API testing, offline test design, and generating weather cards — powered by CI.


🧪 Overview

This project originally started as a tiny API testing sandbox and gradually evolved into a practical, hands-on QA mini-framework. It now includes:

  • ✔️ Live API tests against the Weatherstack service
  • ✔️ Resilient test behavior (auto-skip on 401, rate-limits, etc.)
  • ✔️ Offline tests (no network required)
  • ✔️ A PNG weather card generator
  • ✔️ GitHub Actions CI with HTML test reports + generated images

It’s intentionally lightweight, readable, and useful both as a personal lab and as a portfolio piece for QA/SDET roles.


🏗️ Tech Stack

Component Purpose
Python 3.12 Base language
pytest Test runner
requests HTTP client
responses Offline mocking
Pillow (PIL) Weather card PNG creation
GitHub Actions CI pipeline

No heavy frameworks — everything is simple and dependency-minimal.


🚀 Getting Started

1. Clone the repo

git clone https://github.com/LaidonerS/api-testing-lab
cd api-testing-lab

2. Create and activate your virtual environment

python3 -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

🔑 Weatherstack API Key Setup

Create a free account at: https://weatherstack.com/

Then export your key:

export WEATHERSTACK_API_KEY="your_real_key_here"

Verify:

echo $WEATHERSTACK_API_KEY

If it prints your key, you’re good to go.


🧪 Running Tests

Run all tests (live + offline):

pytest -v

Run only offline tests:

pytest -k offline -v

Run only Weatherstack live tests:

pytest -k "weather and not offline" -v

🟡 Built-in Real-World Resilience

Weather APIs love to throw:

  • 401 Unauthorized
  • 429 rate_limit_reached
  • {"success": false, "error": ...}

This project automatically skips tests when those happen, so your CI stays green and readable.


🎨 Generating a Weather Card (PNG)

This project includes a script that grabs the current weather and renders it into a simple PNG “card.”

Run it like this:

export WEATHERSTACK_API_KEY="your_key"
CITY="Bangkok" python generate_weather_image.py

You will get:

weather_Bangkok.png

The card includes:

  • City & country
  • Temperature and “feels like”
  • Weather description
  • Humidity
  • Background color based on temperature category

It’s a small feature, but surprisingly handy for dashboards or quick-sharing.


🧱 Project Structure

api-testing-lab/
│
├── utils/
│   ├── api_client.py                # Auth + GET wrapper for Weatherstack
│   └── weather_models.py            # WeatherSnapshot model + temp categories
│
├── tests/
│   ├── test_weather_current.py      # Live API tests
│   ├── test_weather_parsing_offline.py  # Offline JSON structure tests
│   └── test_weather_models_offline.py   # Model & categorization tests
│
├── generate_weather_image.py        # PNG weather card generator
│
├── .github/workflows/tests.yml      # CI pipeline
└── requirements.txt                 # Dependencies

Each piece is intentionally kept small and straightforward.


🤖 Continuous Integration (GitHub Actions)

Every push to main automatically triggers:

  1. Dependency installation

  2. pytest execution (with HTML report)

  3. Weather card generation

  4. Artifact upload:

    • report.html
    • weather_<city>.png

To enable CI, set the repo secret:

WEATHERSTACK_API_KEY

Path: GitHub → Settings → Secrets and Variables → Actions

You can download CI artifacts under: Actions → select a run → Artifacts


❓ Why Weatherstack?

A real API means real problems:

  • Authentication failures
  • Rate limiting
  • Odd error structures
  • Occasional city mismatches
  • Network variance

This makes it a perfect API for practicing robust test automation — not the “clean textbook” examples, but the messy real stuff.


💡 Ideas for Future Expansion

Some potential next steps:

  • Add async tests using httpx
  • Add Playwright UI tests for viewing weather cards
  • Create a CLI tool: weathercli London
  • Add caching or retry logic
  • Generate weekly trend charts
  • Build a tiny FastAPI wrapper around WeatherSnapshot

This repo is intentionally flexible — easy to grow if you want more challenges.


🙌 Final Notes

This project aims to be:

  • Authentic
  • Practical
  • Easy to read
  • Demonstrative of real-world API testing challenges
  • Useful as a QA/SDET portfolio reference

If you'd like help expanding it, polishing it further, or adding advanced features, just ask — happy to guide you through the next steps!


If you want a “badge section” (build passing ✨), screenshots, or a more playful intro, I can add those too.

About

Using API from https://weatherstack.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published