Browse Source

updating coverage tests

tags/v2.1
btotharye 2 years ago
parent
commit
cb21daa4f0
2 changed files with 19 additions and 7 deletions
  1. +1
    -1
      .travis.yml
  2. +18
    -6
      unittests/test_haclient.py

+ 1
- 1
.travis.yml View File

@@ -7,6 +7,6 @@ python:
- "3.6"
script:
- pep8 __init__.py
- py.test -s --cov ha_client -v
- pytest --rootdir=unittests --cov unittests/
after_success:
codecov --token=4984c911-ce8f-4767-a446-7339a16ad840

+ 18
- 6
unittests/test_haclient.py View File

@@ -1,9 +1,10 @@
from unittest import TestCase
import sys
sys.path.append('../')
from ha_client import HomeAssistantClient
import unittest
from unittest import mock
from urllib3 import exceptions
from requests.exceptions import SSLError


kitchen_light = {'state': 'off', 'id': '1', 'dev_name': 'kitchen'}

@@ -38,11 +39,23 @@ class TestHaClient(TestCase):
self.assertTrue(ssl, True)
self.assertTrue(mock_request.return_value.status_code, 200)

def test_mock_ssl_no_port(self):
with mock.patch('requests.get') as mock_request:
portnum = None
ssl = True
url = 'https://192.168.0.1'

mock_request.return_value.status_code = 200
self.assertTrue(url, 'https://192.168.0.1')
self.assertEqual(portnum, None)
self.assertTrue(ssl, True)
self.assertTrue(mock_request.return_value.status_code, 200)

def test_broke_entity(self):
portnum = None
ssl = False
ha = HomeAssistantClient(host='167.99.144.205', password='password', portnum=portnum, ssl=ssl)
self.assertRaises(KeyError, ha.find_entity('b', 'cover'))
self.assertRaises(TypeError, ha)

def test_light_nossl(self):
portnum = None
@@ -63,7 +76,6 @@ class TestHaClient(TestCase):
self.assertEqual(ha.portnum, 8123)
convo = ha.engage_conversation('turn off kitchen light')
self.assertEqual(convo, {'extra_data': None, 'speech': 'Turned Kitchen Lights off'})
print(convo)
ha_data = {'entity_id': entity['id']}
if light_attr['state'] == 'on':
r = ha.execute_service("homeassistant", "turn_off",
@@ -75,7 +87,7 @@ class TestHaClient(TestCase):
self.assertEqual(entity,
{'id': 'light.kitchen_lights', 'dev_name': 'Kitchen Lights', 'state': 'off',
'best_score': 100})
self.assertEqual(light_attr['unit_measure'], 180)
self.assertEqual(light_attr['unit_measure'], 53)
if entity['best_score'] >= 50:
self.assertTrue(True)
else:
@@ -88,7 +100,7 @@ class TestHaClient(TestCase):
self.assertEqual(entity,
{'id': 'light.kitchen_lights', 'dev_name': 'Kitchen Lights', 'state': 'on',
'best_score': 100})
self.assertEqual(light_attr['unit_measure'], 180)
self.assertEqual(light_attr['unit_measure'], 53)





Loading…
Cancel
Save