Skip to content
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
2 changes: 0 additions & 2 deletions ring_doorbell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,3 @@ def _read_cache(filename):
return data
except EOFError:
return _clean_cache(filename)
except:
raise
22 changes: 18 additions & 4 deletions tests/test_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ def test_chime_attributes(self, get_mock, post_mock):
class TestRingDoorBell(unittest.TestCase):
"""Test the Ring DoorBell object."""

def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(CACHE):
os.remove(CACHE)

def tearDown(self):
"""Stop everything started."""
self.cleanup()

@mock.patch('requests.Session.get', side_effect=mocked_requests_get)
@mock.patch('requests.Session.post', side_effect=mocked_requests_get)
def test_doorbell_attributes(self, get_mock, post_mock):
Expand Down Expand Up @@ -321,12 +330,19 @@ def test_shared_doorbell_attributes(self, get_mock, post_mock):
self.assertEqual(5, dev.volume)
self.assertEqual('Digital', dev.existing_doorbell_type)

os.remove(CACHE)


class TestRingDoorBellAlerts(unittest.TestCase):
"""Test the Ring DoorBell alerts."""

def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(CACHE):
os.remove(CACHE)

def tearDown(self):
"""Stop everything started."""
self.cleanup()

@mock.patch('requests.Session.get', side_effect=mocked_requests_get)
@mock.patch('requests.Session.post', side_effect=mocked_requests_get)
def test_doorbell_alerts(self, get_mock, post_mock):
Expand All @@ -344,5 +360,3 @@ def test_doorbell_alerts(self, get_mock, post_mock):
self.assertIsInstance(dev.alert_expires_at, datetime)
self.assertTrue(datetime.now() <= dev.alert_expires_at)
self.assertIsNotNone(dev._ring.cache_file)

os.remove(CACHE)
28 changes: 23 additions & 5 deletions tests/test_ring_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The tests utils.py for the Ring platform."""
import os
import sys
import unittest
from ring_doorbell.utils import (
_locator, _clean_cache, _exists_cache, _save_cache, _read_cache)
Expand All @@ -13,6 +14,15 @@
class TestUtils(unittest.TestCase):
"""Test utils.py."""

def cleanup(self):
"""Cleanup any data created from the tests."""
if os.path.isfile(CACHE):
os.remove(CACHE)

def tearDown(self):
"""Stop everything started."""
self.cleanup()

def test_locator(self):
"""Test _locator method."""
self.assertEquals(-1, _locator([DATA], 'key', 'bar'))
Expand All @@ -22,28 +32,36 @@ def test_initiliaze_clean_cache(self):
"""Test _clean_cache method."""
self.assertTrue(_save_cache(DATA, CACHE))
self.assertIsInstance(_clean_cache(CACHE), dict)
os.remove(CACHE)
self.cleanup()

def test_exists_cache(self):
"""Test _exists_cache method."""
self.assertTrue(_save_cache(DATA, CACHE))
self.assertTrue(_exists_cache(CACHE))
os.remove(CACHE)
self.cleanup()

def test_read_cache(self):
"""Test _read_cache method."""
self.assertTrue(_save_cache(DATA, CACHE))
self.assertIsInstance(_read_cache(CACHE), dict)
os.remove(CACHE)
self.cleanup()

def test_read_cache_eoferror(self):
"""Test _read_cache method."""
open(CACHE, 'a').close()
self.assertIsInstance(_read_cache(CACHE), dict)
os.remove(CACHE)
self.cleanup()

def test_read_cache_dict(self):
"""Test _read_cache with expected dict."""
self.assertTrue(_save_cache(CACHE_ATTRS, CACHE))
self.assertIsInstance(_read_cache(CACHE), dict)
os.remove(CACHE)
self.cleanup()

def test_general_exceptions(self):
"""Test exception triggers on utils.py"""
self.assertRaises(TypeError, _clean_cache, True)
if sys.version_info.major == 2:
self.assertRaises(TypeError, _read_cache, True)
else:
self.assertRaises(OSError, _read_cache, True)