Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

First stab at fixing references to integration_blueprint and constants #4

Merged
merged 9 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .devcontainer/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
default_config:
logger:
default: info
logs:
custom_components.integration_blueprint: debug
# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
# debugpy:
default_config:

logger:
default: info
logs:
custom_components.tplink_ess: debug

# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
# debugpy:
4 changes: 2 additions & 2 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup Python
uses: "actions/setup-python@v1"
with:
python-version: "3.8"
python-version: "3.10"
- name: Install requirements
run: python3 -m pip install -r requirements_test.txt
- name: Run tests
Expand All @@ -49,7 +49,7 @@ jobs:
--timeout=9 \
--durations=10 \
-n auto \
--cov custom_components.integration_blueprint \
--cov custom_components.tplink_ess \
-o console_output_style=count \
-p no:sugar \
tests
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup Python
uses: "actions/setup-python@v1"
with:
python-version: "3.8"
python-version: "3.10"
- name: Install requirements
run: python3 -m pip install -r requirements_test.txt
- name: Run tests
Expand All @@ -52,7 +52,7 @@ jobs:
--timeout=9 \
--durations=10 \
-n auto \
--cov custom_components.integration_blueprint \
--cov custom_components.tplink_ess \
-o console_output_style=count \
-p no:sugar \
tests
2 changes: 1 addition & 1 deletion custom_components/tplink_ess/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def async_step_creds(self, user_input=None):
if valid:
self._data.update(user_input)
return self.async_create_entry(
title=self._switches[self._data[CONF_MAC]], data=self._data
title=self._data[CONF_MAC], data=self._data
)
self._errors["base"] = "auth"
return await self._show_config_form(user_input)
Expand Down
1 change: 0 additions & 1 deletion custom_components/tplink_ess/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Constants for tplink_ess."""

# Base component constants
NAME = "TPLink ESS"
DOMAIN = "tplink_ess"
Expand Down
2 changes: 0 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "TPLink Easy Smart Switch",
"domains": ["binary_sensor", "sensor"],
"iot_class": "Local Polling",
"homeassistant": "2023.1.0",
"render_readme": true
}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ not_skip = __init__.py
force_sort_within_sections = true
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = custom_components.integration_blueprint, tests
known_first_party = custom_components.tplink_ess, tests
combine_as_imports = true
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ This will install `homeassistant`, `pytest`, and `pytest-homeassistant-custom-co
Command | Description
------- | -----------
`pytest tests/` | This will run all tests in `tests/` and tell you how many passed/failed
`pytest --durations=10 --cov-report term-missing --cov=custom_components.integration_blueprint tests` | This tells `pytest` that your target module to test is `custom_components.integration_blueprint` so that it can give you a [code coverage](https://en.wikipedia.org/wiki/Code_coverage) summary, including % of code that was executed and the line numbers of missed executions.
`pytest --durations=10 --cov-report term-missing --cov=custom_components.tplink_ess tests` | This tells `pytest` that your target module to test is `custom_components.tplink_ess` so that it can give you a [code coverage](https://en.wikipedia.org/wiki/Code_coverage) summary, including % of code that was executed and the line numbers of missed executions.
`pytest tests/test_init.py -k test_setup_unload_and_reload_entry` | Runs the `test_setup_unload_and_reload_entry` test function located in `tests/test_init.py`
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Tests for integration_blueprint integration."""
"""Tests for tplink_ess integration."""
45 changes: 10 additions & 35 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
"""Global fixtures for integration_blueprint integration."""
# Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original
# function that you want to see without going through the function's actual logic.
# Fixtures can either be passed into tests as parameters, or if autouse=True, they
# will automatically be used across all tests.
#
# Fixtures that are defined in conftest.py are available across all tests. You can also
# define fixtures within a particular test file to scope them locally.
#
# pytest_homeassistant_custom_component provides some fixtures that are provided by
# Home Assistant core. You can find those fixture definitions here:
# https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/blob/master/pytest_homeassistant_custom_component/common.py
#
# See here for more info: https://docs.pytest.org/en/latest/fixture.html (note that
# pytest includes fixtures OOB which you can use as defined on this page)

from unittest.mock import patch

import pytest

from tests.const import SWITCH_DATA

pytest_plugins = "pytest_homeassistant_custom_component"


Expand All @@ -40,24 +28,11 @@ def skip_notifications_fixture():
yield


# This fixture, when used, will result in calls to async_get_data to return None. To have the call
# return a value, we would add the `return_value=<VALUE_TO_RETURN>` parameter to the patch call.
@pytest.fixture(name="bypass_get_data")
def bypass_get_data_fixture():
"""Skip calls to get data from API."""
@pytest.fixture()
def mock_switch():
"""Mock switch data."""
with patch(
"custom_components.integration_blueprint.IntegrationBlueprintApiClient.async_get_data"
):
yield


# In this fixture, we are forcing calls to async_get_data to raise an Exception. This is useful
# for exception handling.
@pytest.fixture(name="error_on_get_data")
def error_get_data_fixture():
"""Simulate error when retrieving data from API."""
with patch(
"custom_components.integration_blueprint.IntegrationBlueprintApiClient.async_get_data",
side_effect=Exception,
):
yield
"custom_components.tplink_ess.TPLinkESSDataUpdateCoordinator._async_update_data"
) as mock_value:
mock_value.return_value = SWITCH_DATA
yield mock_value
119 changes: 115 additions & 4 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,116 @@
"""Constants for integration_blueprint tests."""
from custom_components.integration_blueprint.const import CONF_PASSWORD, CONF_USERNAME
"""Constants for tplink_ess tests."""

# Mock config data to be used across multiple tests
MOCK_CONFIG = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
SWITCH_NAME = "test_switch"
CONFIG_DATA = {
"mac": "70:4f:57:89:61:6a",
"username": "admin",
"password": "admin",
}

SWITCH_DATA = {
"hostname": {
"type": "TL-SG105E",
"hostname": "switch7",
"mac": "70:4f:57:89:61:6a",
"firmware": "1.0.0 Build 20160715 Rel.38605",
"hardware": "TL-SG105E 3.0",
"dhcp": False,
"ip_addr": "192.168.1.109",
"ip_mask": "255.255.255.0",
"gateway": "192.168.1.4",
},
"num_ports": {"num_ports": 5},
"ports": {
"ports": [
"01:01:00:01:06:00:00",
"02:01:00:01:00:00:00",
"03:01:00:01:06:00:00",
"04:01:00:01:00:00:00",
"05:01:00:01:06:00:00",
]
},
"trunk": {"trunk": "01:00:00:00:00"},
"mtu_vlan": {"mtu_vlan": "00:01"},
"vlan": {
"vlan_enabled": "01",
"vlan": [
{
"VLAN ID": 1,
"Member Ports": "1,2,3,4,5",
"Tagged Ports": "",
"VLAN Name": "Default_VLAN",
},
{
"VLAN ID": 50,
"Member Ports": "1,5",
"Tagged Ports": "",
"VLAN Name": "GAMING",
},
],
"vlan_filler": " ",
},
"pvid": {"pvid": [(1, 50), (2, 1), (3, 1), (4, 1), (5, 1)], "vlan_filler": " "},
"qos1": {"qos1": True},
"qos2": {"qos2": ["01:00", "02:00", "03:00", "04:00", "05:00"]},
"mirror": {"mirror": "00:01:00:00:00:00:00:00:00:00"},
"stats": {
"stats": [
{
"Port": 1,
"Status": "Enabled",
"Status Raw": 1,
"Link Status": "1000Full",
"Link Status Raw": 6,
"TxGoodPkt": 31560514,
"TxBadPkt": 0,
"RxGoodPkt": 1403717,
"RxBadPkt": 0,
},
{
"Port": 2,
"Status": "Enabled",
"Status Raw": 1,
"Link Status": "Link Down",
"Link Status Raw": 0,
"TxGoodPkt": 0,
"TxBadPkt": 0,
"RxGoodPkt": 0,
"RxBadPkt": 0,
},
{
"Port": 3,
"Status": "Enabled",
"Status Raw": 1,
"Link Status": "1000Full",
"Link Status Raw": 6,
"TxGoodPkt": 72797090,
"TxBadPkt": 0,
"RxGoodPkt": 27649623,
"RxBadPkt": 0,
},
{
"Port": 4,
"Status": "Enabled",
"Status Raw": 1,
"Link Status": "Link Down",
"Link Status Raw": 0,
"TxGoodPkt": 0,
"TxBadPkt": 0,
"RxGoodPkt": 0,
"RxBadPkt": 0,
},
{
"Port": 5,
"Status": "Enabled",
"Status Raw": 1,
"Link Status": "1000Full",
"Link Status Raw": 6,
"TxGoodPkt": 30053555,
"TxBadPkt": 0,
"RxGoodPkt": 73937797,
"RxBadPkt": 25,
},
]
},
"loop_prev": {"loop_prev": True},
}
86 changes: 0 additions & 86 deletions tests/test_api.py

This file was deleted.

Loading