-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing RTSP Grabber Exception Handling (#36)
* fixing exception handling and adding tests * Automatically reformatting code with black and isort * adjusting readme --------- Co-authored-by: Tim Huff <[email protected]> Co-authored-by: Auto-format Bot <[email protected]>
- Loading branch information
1 parent
62002b7
commit c2b9e9b
Showing
3 changed files
with
58 additions
and
156 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
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 |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
Intended to check basic functionality like cropping, zooming, config validation, etc. | ||
""" | ||
|
||
import os | ||
import unittest | ||
from framegrab.grabber import FrameGrabber | ||
from framegrab.grabber import FrameGrabber, RTSPFrameGrabber | ||
|
||
class TestFrameGrabWithMockCamera(unittest.TestCase): | ||
def test_crop_pixels(self): | ||
|
@@ -174,3 +175,41 @@ def test_attempt_create_grabbers_with_duplicate_names(self): | |
# Should raise an exception because camera1 is duplicated | ||
with self.assertRaises(ValueError): | ||
FrameGrabber.create_grabbers(configs) | ||
|
||
def test_substitute_rtsp_url(self): | ||
"""Test that the RTSP password is substituted correctly. | ||
""" | ||
os.environ['RTSP_PASSWORD_1'] = 'password1' | ||
|
||
config = { | ||
'input_type': 'rtsp', | ||
'id': {'rtsp_url': "rtsp://admin:{{RTSP_PASSWORD_1}}@10.0.0.1"}, | ||
} | ||
|
||
substituted_config = RTSPFrameGrabber._substitute_rtsp_password(config) | ||
substituted_rtsp_url = substituted_config['id']['rtsp_url'] | ||
|
||
assert substituted_rtsp_url == "rtsp://admin:[email protected]" | ||
|
||
def test_substitute_rtsp_url_password_not_set(self): | ||
"""Test that an exception is raised if the user adds a placeholder but neglects to set the environment variable. | ||
""" | ||
config = { | ||
'input_type': 'rtsp', | ||
'id': {'rtsp_url': "rtsp://admin:{{SOME_NONEXISTENT_ENV_VARIABLE}}@10.0.0.1"}, | ||
} | ||
|
||
with self.assertRaises(ValueError): | ||
RTSPFrameGrabber._substitute_rtsp_password(config) | ||
|
||
def test_substitute_rtsp_url_without_placeholder(self): | ||
"""Users should be able to use RTSP urls without a password placeholder. In this case, the config should be returned unchanged. | ||
""" | ||
config = { | ||
'input_type': 'rtsp', | ||
'id': {'rtsp_url': "rtsp://admin:[email protected]"}, | ||
} | ||
|
||
new_config = RTSPFrameGrabber._substitute_rtsp_password(config) | ||
|
||
assert new_config == config |