def test_send_message_none_parameter_raises_value_error(self): """ Test passes when send_message_to_device() raises ValueError """ self.user = FlowUser(username, password) device = self.user.find_device(device_type) with self.assertRaises(ValueError): self.user.send_message_to_device(device, "", 20)
def initialize(self, user_name, password): """ Initializes the system Initializes flow libraries and connects to server Logs in as user and tries to find the controller device, caches if found :param str user_name: flow user name :param str password: flow user password :raises ControllerNotFound, LoginFailed, FlowLibraryError """ flow_url, flow_key, flow_secret = get_server_details() try: flow_initialize(flow_url, flow_key, flow_secret) except FlowException as flow_error: if flow_error.connection_error: self.check_connection_status() LOGGER.exception(flow_error) raise FlowLibraryError("Failed to initialize flow library") try: self.__flow_user = FlowUser(user_name, password) except FlowException as flow_error: if flow_error.connection_error: self.check_connection_status() LOGGER.exception(flow_error) raise LoginFailed() except ValueError as value_error: LOGGER.exception(value_error) raise LoginFailed() try: self.__controller_device = self.__flow_user.find_device( CONTROLLER_DEVICE_TYPE) except FlowException as flow_error: if flow_error.connection_error: self.check_connection_status() LOGGER.exception(flow_error) raise ControllerNotFound() # enable message reception self.__flow_user.enable_message_reception( ClimateControlModel.message_received_callback)
def setUp(self): flow_initialize(flow_server_url, flow_server_key, flow_server_secret) self.user = FlowUser(username, password) self.device = self.user.find_device(device_type)
def test_get_owned_devices_expected(self): """ Test passes when at least one device found """ self.user = FlowUser(username, password) self.assertIsNotNone(self.user.get_owned_devices())
def test_send_message(self): """ Test for sending message to device """ self.user = FlowUser(username, password) device = self.user.find_device(device_type) self.user.send_message_to_device(device, "Hi", 20)
def test_find_device_none_parameter_raises_value_error(self): """ Test passes when find_device() raises ValueError """ self.user = FlowUser(username, password) with self.assertRaises(ValueError): self.user.find_device("")
def test_find_device_wrong_parameter_raises_flow_exception(self): """Test passes when no device of particular type found """ self.user = FlowUser(username, password) with self.assertRaises(FlowException): self.user.find_device("unknown_device")
def test_enable_message_reception_none_parameter__raises_value_error(self): """ Test passes when enable_message_reception() raises ValueError """ self.user = FlowUser(username, password) with self.assertRaises(ValueError): self.user.enable_message_reception("")
def test_find_device_expected(self): """ Test to check find_device() """ self.user = FlowUser(username, password) self.assertIsNotNone(self.user.find_device(device_type))
def test_enable_message_reception(self): """ Test to check enable_message_reception() """ self.user = FlowUser(username, password) self.user.enable_message_reception("callback")
def test_logout(self): """ Test to check logout() """ self.user = FlowUser(username, password) self.user.logout()
def test_login_wrong_parameters_raises_flow_exception(self): """ Test passes when user login raises FlowCoreException """ with self.assertRaises(FlowCoreException): self.user = FlowUser("unknown_user", "123")
def test_login_none_parameter_raises_value_exception(self): """ Test passes when user login raises ValueError """ with self.assertRaises(ValueError): self.user = FlowUser(username, "")
def test_login(self): """ Test passes when user login succeed """ self.user = FlowUser(username, password)