-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from pyrail.irail import irail | ||
from pyrail.irail import iRail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |