Skip to content

Commit

Permalink
Push local changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tjorim committed Jan 1, 2025
1 parent 29f5674 commit 3fd8422
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 42 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish to PyPI

on:
push:
tags:
- "v*"

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Poetry
run: pip install poetry

- name: Install dependencies
run: poetry install --no-dev

- name: Build and Publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: poetry publish --build
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ __pycache__/
# C extensions
*.so

# Virtual environment
env/
.venv/

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -24,6 +27,13 @@ var/
.installed.cfg
*.egg

# Pytest cache
.pytest_cache/

# IDE files
.vscode/
.idea/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
51 changes: 30 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# pyRail

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

## Overview
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.

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.
## Features
- Retrieve real-time train information, including liveboards and vehicle details.
- Access train station data, connections, and disturbances.
- Supports API endpoints: stations, liveboard, vehicle, connections, and disturbances.
- Caching and conditional GET requests using ETags.
- Rate limiting to handle API request limits efficiently.

## Installation

To install pyRail, use pip:

```sh
```bash
pip install pyrail
```

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

# Make a request to the 'stations' endpoint
response = api.do_request('stations')
stations = api.get_stations()

# Print the response
print(response)
print(stations)
```

## Features

- Supports multiple endpoints: stations, liveboard, vehicle, connections, disturbances
- Caching and conditional GET requests using ETag
- Rate limiting to handle API rate limits

## Configuration

You can configure the format and language for the API requests:

```python
api = iRail(format='json', lang='en')
```

Supported formats: json, xml, jsonp

Supported languages: nl, fr, en, de
- Supported formats: json, xml, jsonp
- Supported languages: nl, fr, en, de

## Development
1. Clone the repository:
```bash
git clone https://github.com/tjorim/pyrail.git
```
2. Install dependencies using Poetry:
```bash
poetry install
```
3. Run tests:
```bash
poetry run pytest
```

## Logging

You can set the logging level at runtime to get detailed logs:

```python
import logging
api.set_logging_level(logging.DEBUG)
```

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

## License

This project is licensed under the MIT License. See the LICENSE file for details.


This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
87 changes: 86 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ packages = [
python = "^3.12"
requests = "^2.32.3"

[tool.poetry.group.test.dependencies]
pytest = "^8.3.4"
pytest-mock = "^3.14.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from pyrail.irail import irail
from pyrail.irail import iRail
46 changes: 28 additions & 18 deletions tests/test_irail.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import unittest
import pytest
from unittest.mock import patch, MagicMock
from pyrail.irail import iRail

class TestiRailAPI(unittest.TestCase):
@patch('requests.Session.get')
def test_successful_request(mock_get):
# Mock the response to simulate a successful request
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {'data': 'some_data'}
mock_get.return_value = mock_response

@patch('requests.Session.get')
def test_successful_request(self, mock_get):
# Mock the response to simulate a successful request
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {'data': 'some_data'}
mock_get.return_value = mock_response
api = iRail()
response = api.do_request('stations')

irail_instance = iRail()

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

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

# Ensure the response is not None
assert stations is not None, "The response should not be None"

if __name__ == '__main__':
unittest.main()
# Validate that the response is a dictionary
assert isinstance(stations, dict), "Expected response to be a dictionary"

# Validate the presence of key fields
assert 'station' in stations, "Expected the response to contain a 'station' key"

# Validate the structure of station data
station_list = stations.get('station', [])
assert isinstance(station_list, list), "Expected 'station' to be a list"
assert len(station_list) > 0, "Expected at least one station in the response"

0 comments on commit 3fd8422

Please sign in to comment.