Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Apr 2, 2024
1 parent 542ea40 commit 9ea49e7
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/integration_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Integration tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: ./uv pip install --system -r requirements.test
- name: Integration tests
run: cd integration_tests && python test_banning_works.py
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml → .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Testing
name: Unit Testing

on:
push:
Expand All @@ -8,7 +8,7 @@ on:
pull_request:

jobs:
build:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ mypy: sync
watch-mypy:
watchmedo auto-restart --directory=./ --pattern="*.py;*.pyi" --no-restart-on-command-exit --recursive -- ${MAKE} mypy

.PHONY: sync venv watch-tests
integration-tests: sync
cd integration_tests && python test_banning_works.py

watch-integration-tests:
watchmedo auto-restart --directory=./ --pattern="*.py;*.pyi;*.yaml.j2" --ignore-patterns "config/custom_components/ban_allowlist/*.py" --no-restart-on-command-exit --recursive -- ${MAKE} integration-tests

.PHONY: sync venv watch-tests mypy watch-mypy integration-tests watch-integration-tests
4 changes: 4 additions & 0 deletions integration_tests/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!configuration.yaml.j2
!.storage/
92 changes: 92 additions & 0 deletions integration_tests/config/.storage/auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"version": 1,
"minor_version": 1,
"key": "auth",
"data": {
"users": [
{
"id": "4586e7a920434634a1f78d239261e310",
"group_ids": [
"system-read-only"
],
"is_owner": false,
"is_active": true,
"name": "Home Assistant Content",
"system_generated": true,
"local_only": false
},
{
"id": "031d3289dc2f49acb7f1adfa07c3a7c3",
"group_ids": [
"system-admin"
],
"is_owner": true,
"is_active": true,
"name": "test",
"system_generated": false,
"local_only": false
}
],
"groups": [
{
"id": "system-admin",
"name": "Administrators"
},
{
"id": "system-users",
"name": "Users"
},
{
"id": "system-read-only",
"name": "Read Only"
}
],
"credentials": [
{
"id": "aa3453291c1942988310fe547ade633f",
"user_id": "031d3289dc2f49acb7f1adfa07c3a7c3",
"auth_provider_type": "homeassistant",
"auth_provider_id": null,
"data": {
"username": "test"
}
}
],
"refresh_tokens": [
{
"id": "6cb333fa12f24327bcdd7e4e51c776f3",
"user_id": "4586e7a920434634a1f78d239261e310",
"client_id": null,
"client_name": null,
"client_icon": null,
"token_type": "system",
"created_at": "2024-04-02T11:15:41.523256+00:00",
"access_token_expiration": 1800.0,
"token": "dcd23c6489cb4eacf3854c8a3d88aa074c3856fd826a0a43db02eadd38d02105694a1bc161618a3590d0f943d413f044b8c6c35d46538cc0cb0b3d95034ca545",
"jwt_key": "46b3b76c9917d9f279b40ef6369f9c0cfdc4dbd2189c70711b090f80833d0461222a43d4e9c7ece8aecb0102f03ab4913301b5d5bb8dd9776f465bc7cbce3c0f",
"last_used_at": null,
"last_used_ip": null,
"expire_at": null,
"credential_id": null,
"version": "2024.3.3"
},
{
"id": "e24a8a9334f043c59054b39c2c5b7ee7",
"user_id": "031d3289dc2f49acb7f1adfa07c3a7c3",
"client_id": "http://localhost:8123/",
"client_name": null,
"client_icon": null,
"token_type": "normal",
"created_at": "2024-04-02T11:21:51.364585+00:00",
"access_token_expiration": 1800.0,
"token": "5787f63f0321875b64653c72d6839cc18ed7543966a0fba206298ed2d68d9b81808c7919fa6896f75b5b1060c4fd5cdb7105141ca4c503a7d334c7924525bd56",
"jwt_key": "9763063ce5b8e8a2f66a50cac764048b8f23623dc0e13f725ef7cf5eda3e4ad0c359f8edc576c4ea8c382ace16c22b4ebca3ea8cb8b126331cc41a1cb3dea001",
"last_used_at": "2024-04-02T11:21:51.364625+00:00",
"last_used_ip": "172.22.0.1",
"expire_at": 1719832911.364625,
"credential_id": "aa3453291c1942988310fe547ade633f",
"version": "2024.3.3"
}
]
}
}
13 changes: 13 additions & 0 deletions integration_tests/config/.storage/auth_provider.homeassistant
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"minor_version": 1,
"key": "auth_provider.homeassistant",
"data": {
"users": [
{
"username": "test",
"password": "JDJiJDEyJExmNEU4SkxtRXJXUk5hQk00RnJGTi55ei41SkJ1OUUxUWYwanZKbjdpWXNWcWI0RnN1TVZ1"
}
]
}
}
10 changes: 10 additions & 0 deletions integration_tests/config/.storage/core.analytics
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"minor_version": 1,
"key": "core.analytics",
"data": {
"onboarded": true,
"preferences": {},
"uuid": null
}
}
36 changes: 36 additions & 0 deletions integration_tests/config/.storage/core.area_registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"version": 1,
"minor_version": 6,
"key": "core.area_registry",
"data": {
"areas": [
{
"aliases": [],
"floor_id": null,
"icon": null,
"id": "living_room",
"labels": [],
"name": "Living Room",
"picture": null
},
{
"aliases": [],
"floor_id": null,
"icon": null,
"id": "kitchen",
"labels": [],
"name": "Kitchen",
"picture": null
},
{
"aliases": [],
"floor_id": null,
"icon": null,
"id": "bedroom",
"labels": [],
"name": "Bedroom",
"picture": null
}
]
}
}
18 changes: 18 additions & 0 deletions integration_tests/config/.storage/core.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"minor_version": 3,
"key": "core.config",
"data": {
"latitude": 52.3731339,
"longitude": 4.8903147,
"elevation": 0,
"unit_system_v2": "metric",
"location_name": "Home",
"time_zone": "Europe/London",
"external_url": null,
"internal_url": null,
"currency": "GBP",
"country": "GB",
"language": "en-GB"
}
}
91 changes: 91 additions & 0 deletions integration_tests/config/.storage/core.entity_registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"version": 1,
"minor_version": 13,
"key": "core.entity_registry",
"data": {
"entities": [
{
"aliases": [],
"area_id": null,
"capabilities": null,
"config_entry_id": null,
"device_class": null,
"device_id": null,
"disabled_by": null,
"entity_category": null,
"entity_id": "person.test",
"hidden_by": null,
"icon": null,
"id": "72693e8b73c047a54626c6b7797eb30c",
"has_entity_name": false,
"labels": [],
"name": null,
"options": {},
"original_device_class": null,
"original_icon": null,
"original_name": "test",
"platform": "person",
"supported_features": 0,
"translation_key": null,
"unique_id": "test",
"previous_unique_id": null,
"unit_of_measurement": null
},
{
"aliases": [],
"area_id": null,
"capabilities": null,
"config_entry_id": "6033774d3d7ab2bb9c27bdfc049abb34",
"device_class": null,
"device_id": null,
"disabled_by": null,
"entity_category": null,
"entity_id": "todo.shopping_list",
"hidden_by": null,
"icon": null,
"id": "78b1ff228befca957379bd98c17259b3",
"has_entity_name": true,
"labels": [],
"name": null,
"options": {},
"original_device_class": null,
"original_icon": "mdi:cart",
"original_name": "Shopping List",
"platform": "shopping_list",
"supported_features": 15,
"translation_key": "shopping_list",
"unique_id": "6033774d3d7ab2bb9c27bdfc049abb34",
"previous_unique_id": null,
"unit_of_measurement": null
},
{
"aliases": [],
"area_id": null,
"capabilities": null,
"config_entry_id": "a113e87b06906e07bc1a1f22c3a70027",
"device_class": null,
"device_id": null,
"disabled_by": null,
"entity_category": null,
"entity_id": "tts.google_en_com",
"hidden_by": null,
"icon": null,
"id": "97787db29494084b9e4709e5f4a7a5af",
"has_entity_name": false,
"labels": [],
"name": null,
"options": {},
"original_device_class": null,
"original_icon": null,
"original_name": "Google en com",
"platform": "google_translate",
"supported_features": 0,
"translation_key": null,
"unique_id": "a113e87b06906e07bc1a1f22c3a70027",
"previous_unique_id": null,
"unit_of_measurement": null
}
],
"deleted_entities": []
}
}
8 changes: 8 additions & 0 deletions integration_tests/config/.storage/http.auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 1,
"minor_version": 1,
"key": "http.auth",
"data": {
"content_user": "4586e7a920434634a1f78d239261e310"
}
}
13 changes: 13 additions & 0 deletions integration_tests/config/.storage/onboarding
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 4,
"minor_version": 1,
"key": "onboarding",
"data": {
"done": [
"user",
"core_config",
"analytics",
"integration"
]
}
}
15 changes: 15 additions & 0 deletions integration_tests/config/.storage/person
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"minor_version": 1,
"key": "person",
"data": {
"items": [
{
"id": "test",
"name": "test",
"user_id": "031d3289dc2f49acb7f1adfa07c3a7c3",
"device_trackers": []
}
]
}
}
6 changes: 6 additions & 0 deletions integration_tests/config/.storage/trace.saved_traces
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 1,
"minor_version": 1,
"key": "trace.saved_traces",
"data": {}
}
11 changes: 11 additions & 0 deletions integration_tests/config/configuration.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ban_allowlist:
ip_addresses: {{ ALLOWLIST }}

http:
ip_ban_enabled: true
login_attempts_threshold: 1

logger:
default: warning
logs:
custom_components.ban_allowlist: debug
Loading

0 comments on commit 9ea49e7

Please sign in to comment.