From 00835e3543e90adf35eec824626a352f007c6df2 Mon Sep 17 00:00:00 2001 From: Bobrock Date: Sun, 13 Dec 2020 13:38:20 -0600 Subject: [PATCH] Add changes from original examples file, apply find_packages to setup, add tests --- .gitignore | 1 + examples/streaming_video.py | 3 +-- setup.py | 5 +++-- tests/test_camera.py | 40 +++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 tests/test_camera.py diff --git a/.gitignore b/.gitignore index 368d535..2836d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +secrets.cfg # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/examples/streaming_video.py b/examples/streaming_video.py index 90dc2a9..d67b1d0 100644 --- a/examples/streaming_video.py +++ b/examples/streaming_video.py @@ -1,6 +1,5 @@ import cv2 - -from Camera import Camera +from reolink_api.Camera import Camera def non_blocking(): diff --git a/setup.py b/setup.py index da818d1..e89fd5b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import os import re import codecs -from setuptools import setup +from setuptools import setup, find_packages def read(*parts): @@ -52,5 +52,6 @@ setup( author_email=AUTHOR_EMAIL, url=URL, license=LICENSE, - install_requires=INSTALL_REQUIRES + install_requires=INSTALL_REQUIRES, + packages=find_packages(exclude=['examples', 'tests']) ) diff --git a/tests/test_camera.py b/tests/test_camera.py new file mode 100644 index 0000000..2fa5cf2 --- /dev/null +++ b/tests/test_camera.py @@ -0,0 +1,40 @@ +import os +from configparser import RawConfigParser +import unittest +from reolink_api import Camera + + +def read_config(props_path: str) -> dict: + """Reads in a properties file into variables. + + NB! this config file is kept out of commits with .gitignore. The structure of this file is such: + # secrets.cfg + [camera] + ip={ip_address} + username={username} + password={password} + """ + config = RawConfigParser() + assert os.path.exists(props_path), f"Path does not exist: {props_path}" + config.read(props_path) + return config + + +class TestCamera(unittest.TestCase): + + @classmethod + def setUpClass(cls) -> None: + cls.config = read_config('../secrets.cfg') + + def setUp(self) -> None: + self.cam = Camera(self.config.get('camera', 'ip'), self.config.get('camera', 'username'), + self.config.get('camera', 'password')) + + def test_camera(self): + """Test that camera connects and gets a token""" + self.assertTrue(self.cam.ip == self.config.get('camera', 'ip')) + self.assertTrue(self.cam.token != '') + + +if __name__ == '__main__': + unittest.main()