Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit aca1499

Browse files
Merge pull request #8 from alexandre-eymael/sprint5-cicd-pytest
Sprint5 cicd pytest
2 parents f9789a4 + 2c4013c commit aca1499

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/workflows/pytest.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Pytest
5+
6+
on: [push]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python 3.10.13
19+
uses: actions/setup-python@v3
20+
with:
21+
python-version: "3.10.13"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements/tests/requirements.txt
26+
- name: Test with pytest
27+
run: |
28+
pytest tests/

requirements/tests/requirements.txt

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

tests/test_api.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Tests for the API
3+
"""
4+
5+
import requests
6+
7+
URLS_API = ["http://hessian.be/api", "http://hessian.be/api/billing"]
8+
9+
def test_api_status():
10+
"""
11+
Test that the API is:
12+
(1) reachable
13+
(2) available (i.e. returns status code 200)
14+
"""
15+
16+
for url in URLS_API:
17+
18+
# (1) Check if the API is reachable
19+
try:
20+
response = requests.get(url, timeout=5)
21+
except requests.exceptions.RequestException as e:
22+
error = f"Error occured while trying to API `{url}`: {e}"
23+
raise requests.exceptions.RequestException(error)
24+
25+
# (2) Check if the API is available
26+
assert response.status_code == 200, \
27+
f"API `{url}` is reachable but returned status code {response.status_code}"

0 commit comments

Comments
 (0)