generated from home-assistant/addons-example
-
Notifications
You must be signed in to change notification settings - Fork 2
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
57 additions
and
6 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
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
51 changes: 51 additions & 0 deletions
51
GridboxConnectorAddon-edge/GridboxConnector/import unittest.py
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,51 @@ | ||
import unittest | ||
import logging | ||
from unittest.mock import Mock, patch | ||
from .utils import SensitiveDataFilter, get_bool_env | ||
|
||
# FILE: GridboxConnectorAddon-edge/GridboxConnector/test_utils.py | ||
|
||
|
||
class TestSensitiveDataFilter(unittest.TestCase): | ||
def setUp(self): | ||
self.filter = SensitiveDataFilter() | ||
|
||
def test_filter(self): | ||
record = logging.LogRecord(name="test", level=logging.INFO, pathname="", lineno=0, msg='{"username": "user", "password": "pass"}', args=(), exc_info=None) | ||
self.filter.filter(record) | ||
self.assertIn('"username": "***"', record.msg) | ||
self.assertIn('"password": "***"', record.msg) | ||
|
||
def test_filter_no_sensitive_data(self): | ||
record = logging.LogRecord(name="test", level=logging.INFO, pathname="", lineno=0, msg='{"data": "value"}', args=(), exc_info=None) | ||
self.filter.filter(record) | ||
self.assertIn('"data": "value"', record.msg) | ||
|
||
def test_filter_invalid_json(self): | ||
record = logging.LogRecord(name="test", level=logging.INFO, pathname="", lineno=0, msg='Invalid JSON', args=(), exc_info=None) | ||
self.filter.filter(record) | ||
self.assertEqual(record.msg, 'Invalid JSON') | ||
|
||
class TestGetBoolEnv(unittest.TestCase): | ||
@patch('os.getenv', return_value="true") | ||
def test_get_bool_env_true(self, mock_getenv): | ||
self.assertTrue(get_bool_env("TEST_VAR")) | ||
|
||
@patch('os.getenv', return_value="false") | ||
def test_get_bool_env_false(self, mock_getenv): | ||
self.assertFalse(get_bool_env("TEST_VAR")) | ||
|
||
@patch('os.getenv', return_value=None) | ||
def test_get_bool_env_default(self, mock_getenv): | ||
self.assertFalse(get_bool_env("TEST_VAR")) | ||
|
||
@patch('os.getenv', return_value="1") | ||
def test_get_bool_env_one(self, mock_getenv): | ||
self.assertTrue(get_bool_env("TEST_VAR")) | ||
|
||
@patch('os.getenv', return_value="0") | ||
def test_get_bool_env_zero(self, mock_getenv): | ||
self.assertFalse(get_bool_env("TEST_VAR")) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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