Path: blob/trunk/py/test/unit/selenium/webdriver/common/fedcm/dialog_tests.py
1990 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617from unittest.mock import Mock, patch1819import pytest2021from selenium.webdriver.common.fedcm.dialog import Dialog222324@pytest.fixture25def mock_driver():26return Mock()272829@pytest.fixture30def fedcm(mock_driver):31fedcm = Mock()32mock_driver.fedcm = fedcm33return fedcm343536@pytest.fixture37def dialog(mock_driver, fedcm):38return Dialog(mock_driver)394041def test_click_continue(dialog, fedcm):42dialog.accept()43fedcm.accept.assert_called_once()444546def test_cancel(dialog, fedcm):47dialog.dismiss()48fedcm.dismiss.assert_called_once()495051def test_select_account(dialog, fedcm):52dialog.select_account(1)53fedcm.select_account.assert_called_once_with(1)545556def test_type(dialog, fedcm):57fedcm.dialog_type = "AccountChooser"58assert dialog.type == "AccountChooser"596061def test_title(dialog, fedcm):62fedcm.title = "Sign in"63assert dialog.title == "Sign in"646566def test_subtitle(dialog, fedcm):67fedcm.subtitle = {"subtitle": "Choose an account"}68assert dialog.subtitle == "Choose an account"697071def test_get_accounts(dialog, fedcm):72accounts_data = [73{"name": "Account1", "email": "[email protected]"},74{"name": "Account2", "email": "[email protected]"},75]76fedcm.account_list = accounts_data7778with patch("selenium.webdriver.common.fedcm.account.Account") as MockAccount:79MockAccount.return_value = Mock() # Mock the Account instance80accounts = dialog.get_accounts()8182assert len(accounts) == 283assert accounts[0].name == "Account1"84assert accounts[0].email == "[email protected]"85assert accounts[1].name == "Account2"86assert accounts[1].email == "[email protected]"878889