Skip to content

Commit 3fd8422

Browse files
committed
Push local changes
1 parent 29f5674 commit 3fd8422

File tree

7 files changed

+185
-42
lines changed

7 files changed

+185
-42
lines changed

.github/workflows/publish.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Install Poetry
17+
run: pip install poetry
18+
19+
- name: Install dependencies
20+
run: poetry install --no-dev
21+
22+
- name: Build and Publish
23+
env:
24+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
25+
run: poetry publish --build

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ __pycache__/
66
# C extensions
77
*.so
88

9+
# Virtual environment
10+
env/
11+
.venv/
12+
913
# Distribution / packaging
1014
.Python
11-
env/
1215
build/
1316
develop-eggs/
1417
dist/
@@ -24,6 +27,13 @@ var/
2427
.installed.cfg
2528
*.egg
2629

30+
# Pytest cache
31+
.pytest_cache/
32+
33+
# IDE files
34+
.vscode/
35+
.idea/
36+
2737
# PyInstaller
2838
# Usually these files are written by a python script from a template
2939
# before PyInstaller builds the exe, so as to inject date/other infos into it.

README.md

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# pyRail
22

3-
A Python wrapper for the iRail API.
3+
A Python wrapper for the iRail API, designed to make interacting with iRail simple and efficient.
44

55
## Overview
6+
pyRail is a Python library that provides a convenient interface for interacting with the iRail API. It supports various endpoints such as stations, liveboard, vehicle, connections, and disturbances. The library includes features like caching and rate limiting to optimize API usage.
67

7-
pyRail is a Python library that provides a convenient interface for interacting with the iRail API. It supports various endpoints such as stations, liveboard, vehicle, connections, and disturbances. The library also includes features like caching and rate limiting to optimize API usage.
8+
## Features
9+
- Retrieve real-time train information, including liveboards and vehicle details.
10+
- Access train station data, connections, and disturbances.
11+
- Supports API endpoints: stations, liveboard, vehicle, connections, and disturbances.
12+
- Caching and conditional GET requests using ETags.
13+
- Rate limiting to handle API request limits efficiently.
814

915
## Installation
10-
1116
To install pyRail, use pip:
1217

13-
```sh
18+
```bash
1419
pip install pyrail
1520
```
1621

@@ -24,35 +29,42 @@ from pyrail.irail import iRail
2429
api = iRail(format='json', lang='en')
2530

2631
# Make a request to the 'stations' endpoint
27-
response = api.do_request('stations')
32+
stations = api.get_stations()
2833

2934
# Print the response
30-
print(response)
35+
print(stations)
3136
```
3237

33-
## Features
34-
35-
- Supports multiple endpoints: stations, liveboard, vehicle, connections, disturbances
36-
- Caching and conditional GET requests using ETag
37-
- Rate limiting to handle API rate limits
38-
3938
## Configuration
40-
4139
You can configure the format and language for the API requests:
4240

4341
```python
4442
api = iRail(format='json', lang='en')
4543
```
4644

47-
Supported formats: json, xml, jsonp
48-
49-
Supported languages: nl, fr, en, de
45+
- Supported formats: json, xml, jsonp
46+
- Supported languages: nl, fr, en, de
47+
48+
## Development
49+
1. Clone the repository:
50+
```bash
51+
git clone https://github.com/tjorim/pyrail.git
52+
```
53+
2. Install dependencies using Poetry:
54+
```bash
55+
poetry install
56+
```
57+
3. Run tests:
58+
```bash
59+
poetry run pytest
60+
```
5061

5162
## Logging
52-
5363
You can set the logging level at runtime to get detailed logs:
5464

5565
```python
66+
import logging
67+
5668
api.set_logging_level(logging.DEBUG)
5769
```
5870

@@ -64,7 +76,4 @@ Contributions are welcome! Please open an issue or submit a pull request.
6476
- @jcoetsie
6577

6678
## License
67-
68-
This project is licensed under the MIT License. See the LICENSE file for details.
69-
70-
79+
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

poetry.lock

+86-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ packages = [
2020
python = "^3.12"
2121
requests = "^2.32.3"
2222

23+
[tool.poetry.group.test.dependencies]
24+
pytest = "^8.3.4"
25+
pytest-mock = "^3.14.0"
26+
2327
[build-system]
2428
requires = ["poetry-core>=1.0.0"]
2529
build-backend = "poetry.core.masonry.api"

tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from pyrail.irail import irail
1+
from pyrail.irail import iRail

tests/test_irail.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
import unittest
1+
import pytest
22
from unittest.mock import patch, MagicMock
33
from pyrail.irail import iRail
44

5-
class TestiRailAPI(unittest.TestCase):
5+
@patch('requests.Session.get')
6+
def test_successful_request(mock_get):
7+
# Mock the response to simulate a successful request
8+
mock_response = MagicMock()
9+
mock_response.status_code = 200
10+
mock_response.json.return_value = {'data': 'some_data'}
11+
mock_get.return_value = mock_response
612

7-
@patch('requests.Session.get')
8-
def test_successful_request(self, mock_get):
9-
# Mock the response to simulate a successful request
10-
mock_response = MagicMock()
11-
mock_response.status_code = 200
12-
mock_response.json.return_value = {'data': 'some_data'}
13-
mock_get.return_value = mock_response
13+
api = iRail()
14+
response = api.do_request('stations')
1415

15-
irail_instance = iRail()
16-
17-
# Call the method that triggers the API request
18-
response = irail_instance.do_request('stations')
16+
# Check that the request was successful
17+
assert mock_get.call_count == 1, "Expected one call to the requests.Session.get method"
18+
assert response == {'data': 'some_data'}, "Expected response data to match the mocked response"
1919

20-
# Check that the request was successful
21-
self.assertEqual(mock_get.call_count, 1, "Expected one call to the requests.Session.get method")
22-
self.assertEqual(response, {'data': 'some_data'}, "Expected response data to match the mocked response")
20+
def test_get_stations():
21+
api = iRail()
22+
stations = api.get_stations()
2323

24+
# Ensure the response is not None
25+
assert stations is not None, "The response should not be None"
2426

25-
if __name__ == '__main__':
26-
unittest.main()
27+
# Validate that the response is a dictionary
28+
assert isinstance(stations, dict), "Expected response to be a dictionary"
29+
30+
# Validate the presence of key fields
31+
assert 'station' in stations, "Expected the response to contain a 'station' key"
32+
33+
# Validate the structure of station data
34+
station_list = stations.get('station', [])
35+
assert isinstance(station_list, list), "Expected 'station' to be a list"
36+
assert len(station_list) > 0, "Expected at least one station in the response"

0 commit comments

Comments
 (0)