Tests: Mock get_local_ip by default too

This commit is contained in:
Paulus Schoutsen 2016-02-14 22:01:30 -08:00
parent 09ab3e95c0
commit 8d366a7367
6 changed files with 9 additions and 22 deletions

View file

@ -6,6 +6,7 @@ Tests initialization.
""" """
import betamax import betamax
from homeassistant import util
from homeassistant.util import location from homeassistant.util import location
with betamax.Betamax.configure() as config: with betamax.Betamax.configure() as config:
@ -28,3 +29,4 @@ location.detect_location_info = lambda: location.LocationInfo(
) )
location.elevation = lambda latitude, longitude: 0 location.elevation = lambda latitude, longitude: 0
util.get_local_ip = lambda: '127.0.0.1'

View file

@ -28,9 +28,7 @@ def _url(data={}):
return "{}{}locative?{}".format(HTTP_BASE_URL, const.URL_API, data) return "{}{}locative?{}".format(HTTP_BASE_URL, const.URL_API, data)
@patch('homeassistant.components.http.util.get_local_ip', def setUpModule(): # pylint: disable=invalid-name
return_value='127.0.0.1')
def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server. """ """ Initalizes a Home Assistant server. """
global hass global hass

View file

@ -7,7 +7,6 @@ Tests Home Assistant Alexa component does what it should do.
# pylint: disable=protected-access,too-many-public-methods # pylint: disable=protected-access,too-many-public-methods
import unittest import unittest
import json import json
from unittest.mock import patch
import requests import requests
@ -29,9 +28,7 @@ hass = None
calls = [] calls = []
@patch('homeassistant.components.http.util.get_local_ip', def setUpModule(): # pylint: disable=invalid-name
return_value='127.0.0.1')
def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalize a Home Assistant server for testing this module. """ """ Initalize a Home Assistant server for testing this module. """
global hass global hass

View file

@ -32,9 +32,7 @@ def _url(path=""):
return HTTP_BASE_URL + path return HTTP_BASE_URL + path
@patch('homeassistant.components.http.util.get_local_ip', def setUpModule(): # pylint: disable=invalid-name
return_value='127.0.0.1')
def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initializes a Home Assistant server. """ """ Initializes a Home Assistant server. """
global hass global hass

View file

@ -7,7 +7,6 @@ Tests Home Assistant HTTP component does what it should do.
# pylint: disable=protected-access,too-many-public-methods # pylint: disable=protected-access,too-many-public-methods
import re import re
import unittest import unittest
from unittest.mock import patch
import requests import requests
@ -30,9 +29,7 @@ def _url(path=""):
return HTTP_BASE_URL + path return HTTP_BASE_URL + path
@patch('homeassistant.components.http.util.get_local_ip', def setUpModule(): # pylint: disable=invalid-name
return_value='127.0.0.1')
def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server. """ """ Initalizes a Home Assistant server. """
global hass global hass

View file

@ -6,7 +6,6 @@ Tests Home Assistant remote methods and classes.
""" """
# pylint: disable=protected-access,too-many-public-methods # pylint: disable=protected-access,too-many-public-methods
import unittest import unittest
from unittest.mock import patch
import homeassistant.core as ha import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
@ -24,7 +23,8 @@ HTTP_BASE_URL = "http://127.0.0.1:{}".format(MASTER_PORT)
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD} HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
hass, slave, master_api, broken_api = None, None, None, None broken_api = remote.API('127.0.0.1', BROKEN_PORT)
hass, slave, master_api = None, None, None
def _url(path=""): def _url(path=""):
@ -32,9 +32,7 @@ def _url(path=""):
return HTTP_BASE_URL + path return HTTP_BASE_URL + path
@patch('homeassistant.components.http.util.get_local_ip', def setUpModule(): # pylint: disable=invalid-name
return_value='127.0.0.1')
def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server and Slave instance. """ """ Initalizes a Home Assistant server and Slave instance. """
global hass, slave, master_api, broken_api global hass, slave, master_api, broken_api
@ -63,9 +61,6 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
slave.start() slave.start()
# Setup API pointing at nothing
broken_api = remote.API("127.0.0.1", "", BROKEN_PORT)
def tearDownModule(): # pylint: disable=invalid-name def tearDownModule(): # pylint: disable=invalid-name
""" Stops the Home Assistant server and slave. """ """ Stops the Home Assistant server and slave. """