-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(STATE): use a monostate for user config
- Loading branch information
1 parent
32c9c84
commit f5ef26c
Showing
24 changed files
with
169 additions
and
94 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,6 +0,0 @@ | ||
"""Pi Portal Raspberry Pi door logger.""" | ||
|
||
from pi_portal.modules import config_file | ||
|
||
configuration = config_file.UserConfiguration() | ||
user_config = configuration.load() | ||
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,3 +1,3 @@ | ||
"""Modules for the pi_portal cli.""" | ||
|
||
from . import installer, logger, monitor, slack | ||
from . import installer, logger, monitor, slack, state |
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
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,22 @@ | ||
"""Borg monostate of the current running configuration.""" | ||
|
||
from typing import Any, Dict | ||
|
||
from pi_portal.modules import config_file | ||
|
||
|
||
class State: | ||
"""Borg monostate of the current running configuration.""" | ||
|
||
__shared_state: Dict[str, Any] = {} | ||
|
||
def __init__(self): | ||
self.__dict__ = self.__shared_state | ||
if not self.__shared_state: | ||
self.user_config = {} | ||
|
||
def load(self): | ||
"""Load the user configuration file into the monostate.""" | ||
|
||
configuration = config_file.UserConfiguration() | ||
self.user_config = configuration.load() |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Fixtures for mocking required environment variables.""" | ||
|
||
from unittest import mock | ||
|
||
from pi_portal.modules import state | ||
|
||
MOCK_TOKEN = "secretValue" | ||
MOCK_CHANNEL = "mockChannel" | ||
MOCK_CHANNEL_ID = "CHHH111" | ||
MOCK_S3_BUCKET_NAME = 'MOCK_S3_BUCKET_NAME' | ||
MOCK_LOGZ_IO_CODE = "secretCode" | ||
|
||
|
||
def patch(func): | ||
|
||
def patched_function(*args, **kwargs): | ||
|
||
with mock.patch(state.__name__ + ".State") as mock_state: | ||
|
||
mock_state.return_value.user_config = { | ||
"SLACK_BOT_TOKEN": MOCK_TOKEN, | ||
"SLACK_CHANNEL": MOCK_CHANNEL, | ||
"SLACK_CHANNEL_ID": MOCK_CHANNEL_ID, | ||
"S3_BUCKET_NAME": MOCK_S3_BUCKET_NAME, | ||
"LOGZ_IO_CODE": MOCK_LOGZ_IO_CODE | ||
} | ||
|
||
func(*args, **kwargs) | ||
|
||
return patched_function |
Empty file.
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,16 @@ | ||
"""Test Slack ClientConfiguration class.""" | ||
|
||
from unittest import TestCase | ||
|
||
from pi_portal.modules import slack | ||
from pi_portal.modules.logger import LOG_UUID | ||
|
||
|
||
class TestSlackClient(TestCase): | ||
"""Test the ClientConfiguration class.""" | ||
|
||
def test_initialize(self): | ||
configuration = slack.ClientConfiguration() | ||
self.assertEqual(configuration.log_uuid, LOG_UUID) | ||
self.assertEqual(configuration.interval, 1) | ||
self.assertEqual(configuration.upload_file_title, "Motion Upload") |
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
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
Oops, something went wrong.