def test_save_configuration_on_existing_file(self): freeboxclient.CONFIG_FILE = self.random_configuration_file() self.creates_configuration_file() conf = config.load_configuration() conf['app_token'] = 'dyNYgfK0Ya' conf['track_id'] = '666' conf['status'] = 'granted' conf['challenge'] = 'Bj6xMqoe+DCHD44Kq' config_file = config.get_configuration_filename() config.save_configuration(conf) self.assertTrue('dyNYgfK0Ya' in open(config_file).read()) self.assertTrue('666' in open(config_file).read()) self.assertTrue('granted' in open(config_file).read()) self.assertTrue('Bj6xMqoe+DCHD44Kq' in open(config_file).read())
def test_freeboxos_login(self): self.freebox_client.track_id = '999' self.freebox_client.app_token = 'dyNYgfK0Ya6FW' freeboxclient.CONFIG_FILE = self.random_configuration_file() self.creates_configuration_file() config_file = config.get_configuration_filename() responses.add(responses.GET, '%s/%s/login' % (self.freebox_os_uri, self.freebox_os_api_version), body="{ \"success\":true, \"result\":{ " "\"logged_in\":false, " "\"challenge\":\"VzhbtpR4r8CLaJle2\" " "} }", status=200, content_type='application/json') response = self.freebox_client.login() self.assertTrue('VzhbtpR4r8CLaJle2' in open(config_file).read())
def test_ask_authorization(self): freeboxclient.CONFIG_FILE = self.random_configuration_file() self.creates_configuration_file() config_file = config.get_configuration_filename() self.assertFalse('999' in open(config_file).read()) self.assertFalse('dyNYgfK0Ya6FW' in open(config_file).read()) responses.add(responses.POST, '%s/%s/login/authorize' % (self.freebox_os_uri, self.freebox_os_api_version), body="{ \"success\":true, \"result\":{ " "\"app_token\":\"dyNYgfK0Ya6FW\", " "\"track_id\":999 " "} }", status=200, content_type='application/json') response = self.freebox_client.ask_authorization() self.assertTrue('999' in open(config_file).read()) self.assertTrue('dyNYgfK0Ya6FW' in open(config_file).read())
def test_configuration_filename(self): filename = "%s/.config/freeboxos.yml" % path.expanduser("~") self.assertEqual(filename, config.get_configuration_filename())