Mock util.location by default
This commit is contained in:
parent
2c4166b5f2
commit
a5db23afa4
3 changed files with 20 additions and 23 deletions
|
@ -1,7 +1,10 @@
|
|||
"""
|
||||
homeassistant.util.location
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Module with location helpers.
|
||||
|
||||
detect_location_info and elevation are mocked by default during tests.
|
||||
"""
|
||||
import collections
|
||||
|
||||
|
@ -43,7 +46,6 @@ def distance(lat1, lon1, lat2, lon2):
|
|||
|
||||
def elevation(latitude, longitude):
|
||||
""" Return elevation for given latitude and longitude. """
|
||||
|
||||
req = requests.get(ELEVATION_URL, params={
|
||||
'locations': '{},{}'.format(latitude, longitude),
|
||||
'sensor': 'false',
|
||||
|
|
|
@ -2,10 +2,23 @@ import betamax
|
|||
|
||||
from homeassistant.util import location
|
||||
|
||||
from .common import mock_detect_location_info
|
||||
|
||||
with betamax.Betamax.configure() as config:
|
||||
config.cassette_library_dir = 'tests/cassettes'
|
||||
|
||||
# This hits a 3rd party server. Always mock it.
|
||||
location.detect_location_info = mock_detect_location_info
|
||||
# Automatically called during different setups. Too often forgotten
|
||||
# so mocked by default.
|
||||
location.detect_location_info = lambda: location.LocationInfo(
|
||||
ip='1.1.1.1',
|
||||
country_code='US',
|
||||
country_name='United States',
|
||||
region_code='CA',
|
||||
region_name='California',
|
||||
city='San Diego',
|
||||
zip_code='92122',
|
||||
time_zone='America/Los_Angeles',
|
||||
latitude='2.0',
|
||||
longitude='1.0',
|
||||
use_fahrenheit=True,
|
||||
)
|
||||
|
||||
location.elevation = lambda latitude, longitude: 0
|
||||
|
|
|
@ -9,7 +9,6 @@ from datetime import timedelta
|
|||
from unittest import mock
|
||||
|
||||
from homeassistant import core as ha, loader
|
||||
import homeassistant.util.location as location_util
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
||||
|
@ -44,23 +43,6 @@ def get_test_home_assistant(num_threads=None):
|
|||
return hass
|
||||
|
||||
|
||||
def mock_detect_location_info():
|
||||
""" Mock implementation of util.detect_location_info. """
|
||||
return location_util.LocationInfo(
|
||||
ip='1.1.1.1',
|
||||
country_code='US',
|
||||
country_name='United States',
|
||||
region_code='CA',
|
||||
region_name='California',
|
||||
city='San Diego',
|
||||
zip_code='92122',
|
||||
time_zone='America/Los_Angeles',
|
||||
latitude='2.0',
|
||||
longitude='1.0',
|
||||
use_fahrenheit=True,
|
||||
)
|
||||
|
||||
|
||||
def mock_service(hass, domain, service):
|
||||
"""
|
||||
Sets up a fake service.
|
||||
|
|
Loading…
Add table
Reference in a new issue