-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from BottlecapDave/develop
New bug fix
- Loading branch information
Showing
8 changed files
with
121 additions
and
4 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
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,2 @@ | ||
node_modules/ | ||
__pycache__/ |
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,2 @@ | ||
nodejs 16.13.0 | ||
nodejs 16.13.0 | ||
python 3.10.1 |
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,38 @@ | ||
|
||
|
||
## asdf | ||
|
||
We use `asdf` to manage plugins. | ||
|
||
```bash | ||
asdf plugin-add nodejs | ||
asdf plugin-add python | ||
sudo apt update & sudo apt upgrade | ||
sudo apt install libffi-dev libncurses5-dev zlib1g zlib1g-dev libssl-dev libreadline-dev libbz2-dev libsqlite3-dev | ||
``` | ||
|
||
## Python | ||
|
||
We use pip to manage dependencies. These are needed in order to run tests | ||
|
||
```bash | ||
pip install -r requirements.test.txt | ||
``` | ||
|
||
## Tests | ||
|
||
### Unit Tests | ||
|
||
Unit tests are written utilising `pytest`. To run them | ||
|
||
```bash | ||
python -m pytest tests/unit | ||
``` | ||
|
||
### Integration Tests | ||
|
||
Integration tests are written utilising `pytest`. To run them | ||
|
||
```bash | ||
python -m pytest tests/integration | ||
``` |
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
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,5 @@ | ||
pytest | ||
pytest-socket | ||
pytest-asyncio | ||
mock | ||
homeassistant>=2021.12.01 |
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,46 @@ | ||
from datetime import datetime | ||
import pytz | ||
import pytest | ||
|
||
from custom_components.first_bus.api_client import FirstBusApiClient | ||
|
||
stops = ["0170SGB20077", "3800C509801", "2200YEA00934"] | ||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize("buses",[ | ||
([]), | ||
(None), | ||
(["19"]), | ||
]) | ||
async def test_when_get_next_bus_is_called_then_next_bus_is_returned(buses): | ||
# Arrange | ||
client = FirstBusApiClient() | ||
|
||
# We need to check a bunch of stops as they won't all have next buses available | ||
passes = 0 | ||
for stop in stops: | ||
try: | ||
# Act | ||
next_bus = await client.async_get_next_bus(stop, buses) | ||
|
||
# Assert | ||
assert next_bus != None | ||
assert "Due" in next_bus | ||
assert next_bus["Due"].replace(tzinfo=pytz.UTC) >= datetime.utcnow().replace(tzinfo=pytz.UTC) | ||
|
||
assert "ServiceNumber" in next_bus | ||
|
||
assert "Destination" in next_bus | ||
|
||
assert "IsFG" in next_bus | ||
assert next_bus["IsFG"] == "Y" or next_bus["IsFG"] == "N" | ||
|
||
assert "IsLive" in next_bus | ||
assert next_bus["IsLive"] == "Y" or next_bus["IsFG"] == "N" | ||
|
||
passes += 1 | ||
except: | ||
# Ignore any thrown exceptions | ||
pass | ||
|
||
assert passes > 0 |