diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 00000000..c47a15c6 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,81 @@ +============ +Contributing +============ + +Contributions are welcome and very appreciated!! +Keep in mind that every little contribution helps, don't matter what. + +Types of Contributions +---------------------- + +Report Bugs +~~~~~~~~~~~ + +Report bugs at https://github.com/tchellomello/python-ring-doorbell/issues + +If you are reporting a bug, please include: + +* Ring product and firmware version +* Steps to reproduce the issue +* Anything you judge interesting for the troubleshooting + +Fix Bugs +~~~~~~~~ + +Look through the GitHub issues for bugs. Anything tagged with "bug" +and "help wanted" is open to whoever wants to implement it. + +Implement Features +~~~~~~~~~~~~~~~~~~ + +Look through the GitHub issues for features. Anything tagged with "enhancement" +and "help wanted" is open to whoever wants to implement it. + +Documentation +~~~~~~~~~~~~~ + +Documentation is always good. So please feel free to add any documentation +you think will help our users. + +Request Features +~~~~~~~~~~~~~~~~ + +File an issue at https://github.com/tchellomello/python-ring-doorbell/issues. + +Get Started! +------------ + +Ready to contribute? Here's how to set up `python-ring_doorbell` for local development. + +1. Fork the `python-ring-doorbel` repo on GitHub. +2. Clone your fork locally:: + + $ git clone git@github.com:your_name_here/python-ring-doorbell.git + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: + + $ mkvirtualenv python-ring-doorbell + $ cd python-ring-doorbell/ + $ python setup.py develop + $ pip install -r requirements_tests.txt + +4. Create a branch for local development:: + + $ git checkout -b name-of-your-bugfix-or-feature + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: + + $ tox -r + +6. Commit your changes and push your branch to GitHub:: + + $ git add . + $ git commit -m "Your detailed description of your changes." + $ git push origin name-of-your-bugfix-or-feature + +7. Submit a pull request through the GitHub website. + + +Thank you!! diff --git a/MANIFEST.in b/MANIFEST.in index bb3ec5f0..c07abee0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,7 @@ -include README.md +include CONTRIBUTING.rst +include LICENSE +include README.rst + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] diff --git a/README.rst b/README.rst index 81078485..68457496 100644 --- a/README.rst +++ b/README.rst @@ -27,8 +27,7 @@ Installation .. code-block:: bash # Installing from PyPi - $ pip install ring_doorbell #python 2.7 - $ pip3 install ring_doorbell #python 3.x + $ pip install ring_doorbell # Installing latest development $ pip3 install \ @@ -46,12 +45,8 @@ Initializing your Ring object myring.is_connected True - myring.has_subscription - True - - Listing devices linked to your account ------------------------------------------- +-------------------------------------- .. code-block:: python @@ -69,7 +64,7 @@ Listing devices linked to your account [] Playing with the attributes --------------------------------- +--------------------------- .. code-block:: python for dev in list(myring.chimes + myring.doorbells): @@ -113,7 +108,7 @@ Showing door bell events Downloading the last video triggered by ding -------------------------------------------- +-------------------------------------------- .. code-block:: python doorbell = myring.doorbells[0] @@ -124,12 +119,18 @@ Downloading the last video triggered by ding Displaying the last video capture URL -------------------------------------------- +------------------------------------- .. code-block:: python print(doorbell.recording_url(doorbell.last_recording_id)) 'https://ring-transcoded-videos.s3.amazonaws.com/99999999.mp4?X-Amz-Expires=3600&X-Amz-Date=20170313T232537Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=TOKEN_SECRET/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=secret' + +How to contribute +----------------- +See CONTRIBUTING.rst + + Credits && Thanks ----------------- diff --git a/requirements_tests.txt b/requirements_tests.txt index e07ebba6..f871e407 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -3,4 +3,5 @@ flake8 mock pylint pytest +pytest-cov tox diff --git a/ring_doorbell/utils.py b/ring_doorbell/utils.py index 24797781..0348a771 100644 --- a/ring_doorbell/utils.py +++ b/ring_doorbell/utils.py @@ -59,7 +59,6 @@ def _read_cache(filename): if data.keys() != CACHE_ATTRS.keys(): raise EOFError return data - except EOFError: + + except (EOFError, ValueError): return _clean_cache(filename) - except: - raise diff --git a/setup.py b/setup.py index 98143dd1..4708b7cb 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='ring_doorbell', packages=['ring_doorbell'], - version='0.1.3', + version='0.1.4', description='A Python library to communicate with Ring' + ' Door Bell (https://ring.com/)', author='Marcelo Moreira de Mello', diff --git a/tests/test_ring.py b/tests/test_ring.py index ac2912f3..f3edbb2c 100644 --- a/tests/test_ring.py +++ b/tests/test_ring.py @@ -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): @@ -327,6 +336,15 @@ def test_shared_doorbell_attributes(self, get_mock, post_mock): 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): @@ -344,5 +362,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) diff --git a/tests/test_ring_utils.py b/tests/test_ring_utils.py index 4dfe64d5..10e056ba 100644 --- a/tests/test_ring_utils.py +++ b/tests/test_ring_utils.py @@ -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) @@ -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')) @@ -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) diff --git a/tox.ini b/tox.ini index 32f31eda..3cfc590b 100644 --- a/tox.ini +++ b/tox.ini @@ -8,8 +8,7 @@ setenv = whitelist_externals = /usr/bin/env install_command = /usr/bin/env LANG=C.UTF-8 pip install {opts} {packages} commands = - py.test --verbose --color=auto --duration=0 - coverage run --source=ring_doorbell setup.py test + py.test --basetemp={envtmpdir} --cov --cov-report term-missing deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_tests.txt