hass-core/tests/components/test_remember_the_milk.py
ChristianKuehnel 80a9539f97 integration with Remember The Milk. (#9803)
* MVP integration with Remember The Milk.

This version offers a service allowing you to create new issues in Remember The Milk.

* fixed pylint issue with import path

* - added files to .coveragerc as the server inerface is hard to test
- added tests for config file handling

* fixed lint error

* added missing docstrings

* removed stray edit

* fixed minor issues reported by @fabaff

* changed naming of the service, so that serveral accounts can be used

* added disclaimer

* moved service description to services.yaml

* fixed blank lines

* fixed structure of configuration

* added comment about httplib2

* renamed internal config file

* improved logging statements

* moved entry in services.yaml into separate folder.

Had to move the component itself as well.

* fixed static analysis findings

* mocked first test case

* fixed bug in config handling, fixed unit tests

* mocked second test case

* fixed line length

* fixed static analysis findings and failing test case

* also renamed file in .coveragerc

* control flow changes as requested by  @balloob
2017-10-31 20:33:47 -07:00

49 lines
1.8 KiB
Python

"""Tests for the Remember The Milk component."""
import logging
import unittest
from unittest.mock import patch, mock_open, Mock
import homeassistant.components.remember_the_milk as rtm
from tests.common import get_test_home_assistant
_LOGGER = logging.getLogger(__name__)
class TestConfiguration(unittest.TestCase):
"""Basic tests for the class RememberTheMilkConfiguration."""
def setUp(self):
"""Set up test home assistant main loop."""
self.hass = get_test_home_assistant()
self.profile = "myprofile"
self.token = "mytoken"
self.json_string = '{"myprofile": {"token": "mytoken"}}'
def tearDown(self):
"""Exit home assistant."""
self.hass.stop()
def test_create_new(self):
"""Test creating a new config file."""
with patch("builtins.open", mock_open()), \
patch("os.path.isfile", Mock(return_value=False)):
config = rtm.RememberTheMilkConfiguration(self.hass)
config.set_token(self.profile, self.token)
self.assertEqual(config.get_token(self.profile), self.token)
def test_load_config(self):
"""Test loading an existing token from the file."""
with patch("builtins.open", mock_open(read_data=self.json_string)), \
patch("os.path.isfile", Mock(return_value=True)):
config = rtm.RememberTheMilkConfiguration(self.hass)
self.assertEqual(config.get_token(self.profile), self.token)
def test_invalid_data(self):
"""Test starts with invalid data and should not raise an exception."""
with patch("builtins.open",
mock_open(read_data='random charachters')),\
patch("os.path.isfile", Mock(return_value=True)):
config = rtm.RememberTheMilkConfiguration(self.hass)
self.assertIsNotNone(config)