Skip to content

Commit

Permalink
Rename uvcclient.py to nvr.py for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
kk7ds committed Nov 20, 2015
1 parent f74acb3 commit 750530d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import mock

from uvcclient import uvcclient
from uvcclient import nvr


class TestCliUtils(unittest.TestCase):
Expand All @@ -19,7 +19,7 @@ class TestCliUtils(unittest.TestCase):
@mock.patch('os.getenv')
def test_get_auth_combined(self, mock_getenv):
mock_getenv.side_effect = self.FAKE_ENV1.get
host, port, key, path = uvcclient.get_auth_from_env()
host, port, key, path = nvr.get_auth_from_env()
self.assertEqual('192.168.1.1', host)
self.assertEqual(7080, port)
self.assertEqual('foo', key)
Expand All @@ -28,7 +28,7 @@ def test_get_auth_combined(self, mock_getenv):
@mock.patch('os.getenv')
def test_get_separate(self, mock_getenv):
mock_getenv.side_effect = self.FAKE_ENV2.get
host, port, key, path = uvcclient.get_auth_from_env()
host, port, key, path = nvr.get_auth_from_env()
self.assertEqual('192.168.1.2', host)
self.assertEqual(7443, port)
self.assertEqual('myKey', key)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import mock

from uvcclient import uvcclient
from uvcclient import nvr


class TestClientLowLevel(unittest.TestCase):
Expand All @@ -29,7 +29,7 @@ def cleanUp(self):
i.stop()

def test_uvc_request_get(self):
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
conn = httplib.HTTPConnection.return_value
resp = conn.getresponse.return_value
resp.status = 200
Expand All @@ -44,7 +44,7 @@ def test_uvc_request_get(self):
None, headers)

def test_uvc_request_put(self):
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
conn = httplib.HTTPConnection.return_value
resp = conn.getresponse.return_value
resp.status = 200
Expand All @@ -61,15 +61,15 @@ def test_uvc_request_put(self):
'foobar', headers)

def test_uvc_request_failed(self):
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
conn = httplib.HTTPConnection.return_value
resp = conn.getresponse.return_value
resp.status = 404
result = client._uvc_request('/bar', method='PUT', data='foobar')
self.assertEqual(None, result)

def test_uvc_request_deflated(self):
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
conn = httplib.HTTPConnection.return_value
resp = conn.getresponse.return_value
resp.status = 200
Expand Down Expand Up @@ -104,7 +104,7 @@ def fake_req(path, method='GET', data=None):
self.assertEqual(json.dumps(fake_resp2['data'][0]), data)
return fake_resp2

client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
with mock.patch.object(client, '_uvc_request') as mock_r:
mock_r.side_effect = fake_req
client.set_recordmode('uuid', 'full', chan='medium')
Expand All @@ -123,7 +123,7 @@ def fake_req(path, method='GET', data=None):
def test_get_picture_settings(self):
fake_resp = {'data': [{'ispSettings': {'settingA': 1,
'settingB': 'foo'}}]}
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
with mock.patch.object(client, '_uvc_request') as mock_r:
mock_r.return_value = fake_resp
self.assertEqual({'settingA': 1, 'settingB': 'foo'},
Expand All @@ -132,7 +132,7 @@ def test_get_picture_settings(self):
def test_set_picture_settings(self):
fake_resp = {'data': [{'ispSettings': {'settingA': 1,
'settingB': 'foo'}}]}
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
newvals = {'settingA': 2, 'settingB': 'foo'}
with mock.patch.object(client, '_uvc_request') as mock_r:
mock_r.return_value = fake_resp
Expand All @@ -146,7 +146,7 @@ def test_set_picture_settings_coerces(self):
'settingB': 'foo',
'settingC': False,
}}]}
client = uvcclient.UVCRemote('foo', 7080, 'key')
client = nvr.UVCRemote('foo', 7080, 'key')
newvals = {'settingA': '2', 'settingB': False, 'settingC': 'foo'}
newvals_expected = {'settingA': 2, 'settingB':
'False', 'settingC': True}
Expand Down
1 change: 0 additions & 1 deletion uvcclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from uvcclient import *
6 changes: 3 additions & 3 deletions uvcclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import logging
import optparse

import uvcclient
from uvcclient import nvr


def main():
host, port, apikey, path = uvcclient.get_auth_from_env()
host, port, apikey, path = nvr.get_auth_from_env()

parser = optparse.OptionParser()
parser.add_option('-H', '--host', default=host,
Expand Down Expand Up @@ -58,7 +58,7 @@ def main():
level = logging.WARNING
logging.basicConfig(level=level)

client = uvcclient.UVCRemote(opts.host, opts.port, opts.apikey)
client = nvr.UVCRemote(opts.host, opts.port, opts.apikey)

if opts.name:
opts.uuid = client.name_to_uuid(opts.name)
Expand Down
3 changes: 3 additions & 0 deletions uvcclient/uvcclient.py → uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def name_to_uuid(self, name):
cams_by_name = {x['name']: x['uuid'] for x in cameras}
return cams_by_name.get(name)

def get_camera(self, uuid):
return self._uvc_request('/api/2.0/camera/%s' % uuid)['data'][0]


def get_auth_from_env():
"""Attempt to get UVC NVR connection information from the environment.
Expand Down

0 comments on commit 750530d

Please sign in to comment.