Skip to content

Commit

Permalink
Added more details to this test for testing without a saved test file
Browse files Browse the repository at this point in the history
  • Loading branch information
davidusb-geek committed Oct 31, 2024
1 parent 6060035 commit b8f0fee
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/test_retrieve_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@
class TestRetrieveHass(unittest.TestCase):

def setUp(self):
get_data_from_file = True
self.get_data_from_file = True
save_data_to_file = False

# Build params with default secrets (no config)
if emhass_conf['defaults_path'].exists():
if get_data_from_file:
if self.get_data_from_file:
_,secrets = utils.build_secrets(emhass_conf,logger,no_response=True)
params = utils.build_params(emhass_conf,secrets,{},logger)
retrieve_hass_conf, _, _ = get_yaml_parse(params,logger)
else:
emhass_conf['secrets_path'] = root / 'secrets_emhass.yaml'
emhass_conf['config_path'] = root / 'config.json'
#emhass_conf['legacy_path'] = root / 'emhass_config.yaml'
config = utils.build_config(emhass_conf,logger,emhass_conf['defaults_path'])
#config = utils.build_config(emhass_conf,logger,legacy_config_path=emhass_conf['legacy_path'])
_,secrets = utils.build_secrets(emhass_conf,logger,secrets_path=emhass_conf['secrets_path'],no_response=True)
params = utils.build_params(emhass_conf,secrets,config,logger)
retrieve_hass_conf, _, _ = get_yaml_parse(params,logger)
Expand All @@ -64,9 +61,9 @@ def setUp(self):
self.retrieve_hass_conf = retrieve_hass_conf
self.rh = RetrieveHass(self.retrieve_hass_conf['hass_url'], self.retrieve_hass_conf['long_lived_token'],
self.retrieve_hass_conf['optimization_time_step'], self.retrieve_hass_conf['time_zone'],
params, emhass_conf, logger, get_data_from_file=get_data_from_file)
params, emhass_conf, logger, get_data_from_file=self.get_data_from_file)
# Obtain sensor values from saved file
if get_data_from_file:
if self.get_data_from_file:
with open(emhass_conf['data_path'] / 'test_df_final.pkl', 'rb') as inp:
self.rh.df_final, self.days_list, self.var_list = pickle.load(inp)
# Else obtain sensor values from HA
Expand All @@ -86,7 +83,8 @@ def setUp(self):
def test_get_yaml_parse(self):
self.assertIsInstance(self.retrieve_hass_conf, dict)
self.assertTrue('hass_url' in self.retrieve_hass_conf.keys())
self.assertTrue(self.retrieve_hass_conf['hass_url'] == 'https://myhass.duckdns.org/')
if self.get_data_from_file:
self.assertTrue(self.retrieve_hass_conf['hass_url'] == 'https://myhass.duckdns.org/')

# Check yaml parse worked
def test_yaml_parse_web_server(self):
Expand All @@ -107,7 +105,10 @@ def test_get_data_failed(self):
days_list = get_days_list(1)
var_list = [self.retrieve_hass_conf['sensor_power_load_no_var_loads']]
response = self.rh.get_data(days_list, var_list)
self.assertFalse(response)
if self.get_data_from_file:
self.assertFalse(response)
else:
self.assertTrue(response)

# Test with html mock response
def test_get_data_mock(self):
Expand Down

0 comments on commit b8f0fee

Please sign in to comment.