def get_mock_remote( host="1.2.3.4", authorize_error=None, encrypted=False, app_id=None, encryption_key=None, ): """Return a mock remote.""" mock_remote = Mock() mock_remote.type = TV_TYPE_ENCRYPTED if encrypted else TV_TYPE_NONENCRYPTED mock_remote.app_id = app_id mock_remote.enc_key = encryption_key def request_pin_code(name=None): return mock_remote.request_pin_code = request_pin_code def authorize_pin_code(pincode): if pincode == "1234": return if authorize_error is not None: raise authorize_error mock_remote.authorize_pin_code = authorize_pin_code return mock_remote
def _create_installed_app(location_id, app_id): item = Mock(InstalledApp) item.installed_app_id = str(uuid4()) item.installed_app_status = InstalledAppStatus.AUTHORIZED item.installed_app_type = InstalledAppType.WEBHOOK_SMART_APP item.app_id = app_id item.location_id = location_id return item
async def app_fixture(hass, config_file): """Fixture for a single app.""" app = Mock(AppEntity) app.app_name = APP_NAME_PREFIX + str(uuid4()) app.app_id = str(uuid4()) app.app_type = "WEBHOOK_SMART_APP" app.classifications = [CLASSIFICATION_AUTOMATION] app.display_name = "Home Assistant" app.description = f"{hass.config.location_name} at https://test.local" app.single_instance = True app.webhook_target_url = webhook.async_generate_url( hass, hass.data[DOMAIN][CONF_WEBHOOK_ID]) settings = Mock(AppSettings) settings.app_id = app.app_id settings.settings = {SETTINGS_INSTANCE_ID: config_file[CONF_INSTANCE_ID]} app.settings.return_value = settings return app
async def test_smartapp_uninstall(hass, config_entry): """Test the config entry is unloaded when the app is uninstalled.""" config_entry.add_to_hass(hass) app = Mock() app.app_id = config_entry.data["app_id"] request = Mock() request.installed_app_id = config_entry.data["installed_app_id"] with patch.object(hass.config_entries, "async_remove") as remove: await smartapp.smartapp_uninstall(hass, request, None, app) assert remove.call_count == 1
def get_mock_remote( host="1.2.3.4", request_error=None, authorize_error=None, encrypted=False, app_id=None, encryption_key=None, name=DEFAULT_NAME, manufacturer=DEFAULT_MANUFACTURER, model_number=DEFAULT_MODEL_NUMBER, unique_id="mock-unique-id", ): """Return a mock remote.""" mock_remote = Mock() mock_remote.type = TV_TYPE_ENCRYPTED if encrypted else TV_TYPE_NONENCRYPTED mock_remote.app_id = app_id mock_remote.enc_key = encryption_key def request_pin_code(name=None): if request_error is not None: raise request_error mock_remote.request_pin_code = request_pin_code def authorize_pin_code(pincode): if pincode == "1234": return if authorize_error is not None: raise authorize_error mock_remote.authorize_pin_code = authorize_pin_code def get_device_info(): return { ATTR_FRIENDLY_NAME: name, ATTR_MANUFACTURER: manufacturer, ATTR_MODEL_NUMBER: model_number, ATTR_UDN: unique_id, } mock_remote.get_device_info = get_device_info return mock_remote
async def test_smartapp_update_saves_token(hass, smartthings_mock, location, device_factory): """Test update saves token.""" # Arrange entry = MockConfigEntry(domain=DOMAIN, data={ "installed_app_id": str(uuid4()), "app_id": str(uuid4()) }) entry.add_to_hass(hass) app = Mock() app.app_id = entry.data["app_id"] request = Mock() request.installed_app_id = entry.data["installed_app_id"] request.auth_token = str(uuid4()) request.refresh_token = str(uuid4()) request.location_id = location.location_id # Act await smartapp.smartapp_update(hass, request, None, app) # Assert assert entry.data[CONF_REFRESH_TOKEN] == request.refresh_token
def app_settings_fixture(app, config_file): """Fixture for an app settings.""" settings = Mock(AppSettings) settings.app_id = app.app_id settings.settings = {SETTINGS_INSTANCE_ID: config_file[CONF_INSTANCE_ID]} return settings