Skip to content

Commit

Permalink
Additional tests / push to version 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ol-iver committed Mar 22, 2020
1 parent f227a35 commit 65e03b1
Show file tree
Hide file tree
Showing 14 changed files with 6,606 additions and 65 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: python
matrix:
fast_finish: true
include:
- python: "3.4"
env: TOXENV=py34
- python: "3.5"
env: TOXENV=py35
- python: "3.6"
Expand Down
2 changes: 1 addition & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DATA
__title__ = 'denonavr'

VERSION
0.8.0
0.8.1

====================================================================================

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# denonavr
[![Build Status](https://travis-ci.org/scarface-4711/denonavr.svg?branch=master)](https://travis-ci.org/scarface-4711/denonavr)

Automation Library for Denon AVR receivers - current version 0.8.0
Automation Library for Denon AVR receivers - current version 0.8.1

## Installation

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ denonavr

|Build Status|

Automation Library for Denon AVR receivers - current version 0.8.0
Automation Library for Denon AVR receivers - current version 0.8.1

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion denonavr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logging.getLogger(__name__).addHandler(logging.NullHandler())

__title__ = "denonavr"
__version__ = "0.8.0"
__version__ = "0.8.1"


def discover():
Expand Down
31 changes: 19 additions & 12 deletions denonavr/denonavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,16 @@ def exec_appcommand_post(self, attribute_list):
# Buffered XML not needed anymore: close
body.close()

try:
# Return XML ElementTree
root = ET.fromstring(res)
except (ET.ParseError, TypeError):
_LOGGER.error(
"End point %s on host %s returned malformed XML.",
self._urls.appcommand, self._host)
else:
return root
if res is not None:
try:
# Return XML ElementTree
root = ET.fromstring(res)
except (ET.ParseError, TypeError):
_LOGGER.error(
"End point %s on host %s returned malformed XML.",
self._urls.appcommand, self._host)
else:
return root

def get_status_xml(self, command, suppress_errors=False):
"""Get status XML via HTTP and return it as XML ElementTree."""
Expand Down Expand Up @@ -417,7 +418,6 @@ def send_post_command(self, command, body):
_LOGGER.error((
"Host %s returned HTTP status code %s to POST command at "
"end point %s"), self._host, res.status_code, command)
return False

def create_zones(self, add_zones):
"""Create instances of additional zones for the receiver."""
Expand Down Expand Up @@ -1036,8 +1036,12 @@ def _get_receiver_sources(self):
self._favorite_func_list.append(func_name)
receiver_sources[func_name] = child.find("Name").text
for xml_zonecapa in root.findall("DeviceZoneCapabilities"):
# Currently only Main Zone (No=0) supported
if xml_zonecapa.find("./Zone/No").text == "0":
zone_no = "0"
if self._zone == "Zone2":
zone_no = "1"
elif self._zone == "Zone3":
zone_no = "2"
if xml_zonecapa.find("./Zone/No").text == zone_no:
# Get list of all input sources of receiver
xml_list = xml_zonecapa.find("./InputSource/List")
for xml_source in xml_list.findall("Source"):
Expand All @@ -1046,6 +1050,9 @@ def _get_receiver_sources(self):
"FuncName").text] = xml_source.find(
"DefaultName").text

# Invalid source "SOURCE" needs to be deleted
receiver_sources.pop("SOURCE", None)

return receiver_sources

def _get_own_zone(self):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import find_packages, setup

setup(name='denonavr',
version='0.8.0',
version='0.8.1',
description='Automation Library for Denon AVR receivers',
long_description='Automation Library for Denon AVR receivers',
url='https://github.com/scarface-4711/denonavr',
Expand All @@ -23,7 +23,8 @@
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries",
"Topic :: Home Automation",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
])
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pytest-cov
pytest-timeout
flake8-docstrings
flake8
requests_mock
requests-mock
testtools
119 changes: 76 additions & 43 deletions tests/test_denonavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:license: MIT, see LICENSE for more details.
"""

from urllib.parse import urlparse
import testtools
import requests
import requests_mock
Expand All @@ -25,7 +26,8 @@
"AVR-X2000": ZONE2_ZONE3, "AVR-X2000-2": NO_ZONES,
"SR5008": NO_ZONES, "M-CR603": NO_ZONES,
"NR1604": ZONE2_ZONE3, "AVR-4810": NO_ZONES,
"AVR-3312": NO_ZONES}
"AVR-3312": NO_ZONES, "NR1609": ZONE2,
"AVC-8500H": ZONE2_ZONE3}

APPCOMMAND_URL = "/goform/AppCommand.xml"
STATUS_URL = "/goform/formMainZone_MainZoneXmlStatus.xml"
Expand Down Expand Up @@ -62,50 +64,63 @@ def setUp(self, mocker):

def custom_matcher(self, request):
"""Match URLs to sample files."""
if request.path_url == STATUS_URL:
content = get_sample_content(
"{receiver}-formMainZone_MainZoneXmlStatus.xml".format(
receiver=self._testing_receiver))
elif request.path_url == STATUS_Z2_URL:
content = get_sample_content(
"{receiver}-formZone2_Zone2XmlStatus.xml".format(
receiver=self._testing_receiver))
elif request.path_url == STATUS_Z3_URL:
content = get_sample_content(
"{receiver}-formZone3_Zone3XmlStatus.xml".format(
receiver=self._testing_receiver))
elif request.path_url == MAINZONE_URL:
content = get_sample_content(
"{receiver}-formMainZone_MainZoneXml.xml".format(
receiver=self._testing_receiver))
elif request.path_url == DEVICEINFO_URL:
content = get_sample_content(
"{receiver}-Deviceinfo.xml".format(
receiver=self._testing_receiver))
elif request.path_url == NETAUDIOSTATUS_URL:
content = get_sample_content(
"{receiver}-formNetAudio_StatusXml.xml".format(
receiver=self._testing_receiver))
elif request.path_url == TUNERSTATUS_URL:
content = get_sample_content(
"{receiver}-formTuner_TunerXml.xml".format(
receiver=self._testing_receiver))
elif request.path_url == HDTUNERSTATUS_URL:
content = get_sample_content(
"{receiver}-formTuner_HdXml.xml".format(
receiver=self._testing_receiver))
elif request.path_url == APPCOMMAND_URL:
content = get_sample_content(
"{receiver}-AppCommand.xml".format(
receiver=self._testing_receiver))
else:
content = "DATA"
port_suffix = ""

if urlparse(request.url).port == 8080:
port_suffix = "-8080"

resp = requests.Response()
resp.encoding = "utf-8"
# pylint: disable=protected-access
resp._content = content.encode()
resp.status_code = 200

try:
if request.path_url == STATUS_URL:
content = get_sample_content(
"{receiver}-formMainZone_MainZoneXmlStatus{port}"
".xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == STATUS_Z2_URL:
content = get_sample_content(
"{receiver}-formZone2_Zone2XmlStatus{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == STATUS_Z3_URL:
content = get_sample_content(
"{receiver}-formZone3_Zone3XmlStatus{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == MAINZONE_URL:
content = get_sample_content(
"{receiver}-formMainZone_MainZoneXml{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == DEVICEINFO_URL:
content = get_sample_content(
"{receiver}-Deviceinfo{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == NETAUDIOSTATUS_URL:
content = get_sample_content(
"{receiver}-formNetAudio_StatusXml{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == TUNERSTATUS_URL:
content = get_sample_content(
"{receiver}-formTuner_TunerXml{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == HDTUNERSTATUS_URL:
content = get_sample_content(
"{receiver}-formTuner_HdXml{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
elif request.path_url == APPCOMMAND_URL:
content = get_sample_content(
"{receiver}-AppCommand{port}.xml".format(
receiver=self._testing_receiver, port=port_suffix))
else:
content = "DATA"
except FileNotFoundError:
resp = requests.Response()
content = "Error 403: Forbidden\nAccess Forbidden"
resp.status_code = 403
else:
resp.status_code = 200

resp._content = content.encode() # pylint: disable=protected-access

return resp

@requests_mock.mock()
Expand All @@ -118,9 +133,27 @@ def test_input_func_switch(self, mock):
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
# Switch through all functions and check if successful
for zone in self.denon.zones.values():
if receiver == 'AVC-8500H':
print(receiver, zone.input_func_list)
for input_func in zone.input_func_list:
self.denon.set_input_func(input_func)
self.assertEqual(
input_func, self.denon.input_func,
("Input function change to {func} "
"not successful").format(func=input_func))
"not successful for {receiver}").format(
func=input_func, receiver=receiver))

@requests_mock.mock()
def test_attributes_not_none(self, mock):
"""Check that certain attributes are not None."""
mock.add_matcher(self.custom_matcher)
for receiver, zones in TESTING_RECEIVERS.items():
# Switch receiver and update to load new sample files
self._testing_receiver = receiver
self.denon = denonavr.DenonAVR(FAKE_IP, add_zones=zones)
self.assertIsNotNone(
self.denon.power,
"Power status is None for receiver {}".format(receiver))
self.assertIsNotNone(
self.denon.state,
"State is None for receiver {}".format(receiver))
Loading

0 comments on commit 65e03b1

Please sign in to comment.