Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/unit/selenium/webdriver/common/fedcm/dialog_tests.py
1990 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
from unittest.mock import Mock, patch
19
20
import pytest
21
22
from selenium.webdriver.common.fedcm.dialog import Dialog
23
24
25
@pytest.fixture
26
def mock_driver():
27
return Mock()
28
29
30
@pytest.fixture
31
def fedcm(mock_driver):
32
fedcm = Mock()
33
mock_driver.fedcm = fedcm
34
return fedcm
35
36
37
@pytest.fixture
38
def dialog(mock_driver, fedcm):
39
return Dialog(mock_driver)
40
41
42
def test_click_continue(dialog, fedcm):
43
dialog.accept()
44
fedcm.accept.assert_called_once()
45
46
47
def test_cancel(dialog, fedcm):
48
dialog.dismiss()
49
fedcm.dismiss.assert_called_once()
50
51
52
def test_select_account(dialog, fedcm):
53
dialog.select_account(1)
54
fedcm.select_account.assert_called_once_with(1)
55
56
57
def test_type(dialog, fedcm):
58
fedcm.dialog_type = "AccountChooser"
59
assert dialog.type == "AccountChooser"
60
61
62
def test_title(dialog, fedcm):
63
fedcm.title = "Sign in"
64
assert dialog.title == "Sign in"
65
66
67
def test_subtitle(dialog, fedcm):
68
fedcm.subtitle = {"subtitle": "Choose an account"}
69
assert dialog.subtitle == "Choose an account"
70
71
72
def test_get_accounts(dialog, fedcm):
73
accounts_data = [
74
{"name": "Account1", "email": "[email protected]"},
75
{"name": "Account2", "email": "[email protected]"},
76
]
77
fedcm.account_list = accounts_data
78
79
with patch("selenium.webdriver.common.fedcm.account.Account") as MockAccount:
80
MockAccount.return_value = Mock() # Mock the Account instance
81
accounts = dialog.get_accounts()
82
83
assert len(accounts) == 2
84
assert accounts[0].name == "Account1"
85
assert accounts[0].email == "[email protected]"
86
assert accounts[1].name == "Account2"
87
assert accounts[1].email == "[email protected]"
88
89