-
-
Notifications
You must be signed in to change notification settings - Fork 17
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 #37 from rucarrol-goog/rebase
Add tests for app.py, and add gitignore entry for bazel
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Bazel local cache/files ignore. | ||
bazel-* |
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,28 @@ | ||
"""Unit tests for app.py""" | ||
import unittest | ||
import mock | ||
import app | ||
|
||
|
||
class AppTest(unittest.TestCase): | ||
@mock.patch.object(app.config, "load_config") | ||
@mock.patch.object(app.mqtt, "connect", autospec=True) | ||
def test_main_success(self, connect_mock, config_mock): | ||
"""Ensure we can execute main.""" | ||
connect_mock.return_value = None | ||
config_mock.return_value = dict(domains=["domain.one"]) | ||
app.main() | ||
connect_mock.assert_called_with(["domain.one"]) | ||
|
||
@mock.patch.object(app.config, "load_config") | ||
@mock.patch.object(app.mqtt, "connect", autospec=True) | ||
def test_main_fails_no_domain(self, connect_mock, config_mock): | ||
"""Ensure we fail when domains are not configured.""" | ||
connect_mock.return_value = None | ||
config_mock.return_value = dict(domains=None) | ||
with self.assertRaises(app.DomainsNotInConfig): | ||
app.main() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |