GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — code42cli/tests/test_password.py at main · ceciliastevens/code42cli

Expand file tree

/

test_password.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
104 lines (78 loc) · 3.07 KB
/

test_password.py

Copy path

File metadata and controls

104 lines (78 loc) · 3.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pytest
import code42cli.password as password
_USERNAME = "test.username"
@pytest.fixture
def keyring_password_getter(mocker):
return mocker.patch("keyring.get_password")
@pytest.fixture(autouse=True)
def keyring_password_setter(mocker):
return mocker.patch("keyring.set_password")
@pytest.fixture(autouse=True)
def get_keyring(mocker):
mock = mocker.patch("keyring.get_keyring")
mock.return_value.priority = 10
return mock
@pytest.fixture
def getpass_function(mocker):
return mocker.patch("code42cli.password.getpass")
@pytest.fixture
def user_agreement(mocker):
mock = mocker.patch("code42cli.password.does_user_agree")
mock.return_value = True
return mocker
@pytest.fixture
def user_disagreement(mocker):
mock = mocker.patch("code42cli.password.does_user_agree")
mock.return_value = False
return mocker
def test_get_stored_password_when_given_profile_name_gets_profile_for_that_name(
profile, keyring_password_getter
):
profile.name = "foo"
profile.username = "bar"
service_name = f"code42cli::{profile.name}"
password.get_stored_password(profile)
keyring_password_getter.assert_called_once_with(service_name, profile.username)
def test_get_stored_password_returns_expected_password(
profile, keyring_password_getter, keyring_password_setter
):
keyring_password_getter.return_value = "already stored password 123"
assert password.get_stored_password(profile) == "already stored password 123"
def test_set_password_uses_expected_service_name_username_and_password(
profile, keyring_password_setter, keyring_password_getter
):
keyring_password_getter.return_value = "test_password"
profile.name = "profile_name"
profile.username = "test.username"
password.set_password(profile, "test_password")
expected_service_name = "code42cli::profile_name"
keyring_password_setter.assert_called_once_with(
expected_service_name, profile.username, "test_password"
)
def test_set_password_when_using_file_fallback_and_user_accepts_saves_password(
profile,
keyring_password_setter,
keyring_password_getter,
get_keyring,
user_agreement,
):
keyring_password_getter.return_value = "test_password"
profile.name = "profile_name"
profile.username = "test.username"
password.set_password(profile, "test_password")
expected_service_name = "code42cli::profile_name"
keyring_password_setter.assert_called_once_with(
expected_service_name, profile.username, "test_password"
)
def test_set_password_when_using_file_fallback_and_user_rejects_does_not_saves_password(
profile, keyring_password_setter, get_keyring, user_disagreement
):
get_keyring.return_value.priority = 0.5
keyring_password_getter.return_value = "test_password"
profile.name = "profile_name"
profile.username = "test.username"
password.set_password(profile, "test_password")
assert not keyring_password_setter.call_count
def test_prompt_for_password_calls_getpass(getpass_function):
password.get_password_from_prompt()
assert getpass_function.call_count
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.