-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added flag to skip sending a registration request and minor fixes #243
Open
silverdrake11
wants to merge
1
commit into
canonical:master
Choose a base branch
from
silverdrake11:skip_registration_plus_minor_fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
from twisted.internet.defer import Deferred | ||
from twisted.internet.defer import fail | ||
from twisted.internet.defer import succeed | ||
from twisted.python.compat import iteritems | ||
|
||
from landscape.client.broker.registration import Identity | ||
from landscape.client.broker.registration import RegistrationError | ||
|
@@ -384,6 +383,56 @@ def test_prompt_landscape_edition( | |
) | ||
self.assertEqual(self.config.account_name, "standalone") | ||
|
||
@mock.patch( | ||
"landscape.client.configuration.input", | ||
return_value="http://landscape.hello.com", | ||
) | ||
@mock.patch( | ||
"landscape.client.configuration.prompt_yes_no", | ||
return_value=True, | ||
) | ||
@mock.patch("landscape.client.configuration.show_help") | ||
def test_prompt_landscape_edition_strip_http( | ||
self, | ||
mock_help, | ||
prompt_yes_no, | ||
mock_input, | ||
): | ||
self.script.query_landscape_edition() | ||
self.assertEqual( | ||
self.config.ping_url, | ||
"http://landscape.hello.com/ping", | ||
) | ||
self.assertEqual( | ||
self.config.url, | ||
"https://landscape.hello.com/message-system", | ||
) | ||
|
||
@mock.patch( | ||
"landscape.client.configuration.input", | ||
return_value="https://landscape.hello.com", | ||
) | ||
@mock.patch( | ||
"landscape.client.configuration.prompt_yes_no", | ||
return_value=True, | ||
) | ||
@mock.patch("landscape.client.configuration.show_help") | ||
def test_prompt_landscape_edition_strip_https( | ||
self, | ||
mock_help, | ||
prompt_yes_no, | ||
mock_input, | ||
): | ||
self.script.query_landscape_edition() | ||
self.assertEqual( | ||
self.config.ping_url, | ||
"http://landscape.hello.com/ping", | ||
) | ||
self.assertEqual( | ||
self.config.url, | ||
"https://landscape.hello.com/message-system", | ||
) | ||
|
||
@mock.patch( | ||
"landscape.client.configuration.input", | ||
return_value="landscape.hello.com", | ||
|
@@ -760,7 +809,9 @@ def get_content(self, config): | |
try: | ||
config.config = config_file | ||
config.write() | ||
return open(config.config).read().strip() + "\n" | ||
with open(config.config) as fh: | ||
text = fh.read().strip() + "\n" | ||
return text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this change. |
||
finally: | ||
config.config = original_config | ||
|
||
|
@@ -788,7 +839,7 @@ def side_effect_input(prompt): | |
"Will you be using your own " | ||
"Self-Hosted Landscape installation? [y/N]": "n", | ||
} | ||
for key, value in iteritems(fixtures): | ||
for key, value in fixtures.items(): | ||
if key in prompt: | ||
return value | ||
raise KeyError(f"Couldn't find answer for {prompt}") | ||
|
@@ -798,7 +849,7 @@ def side_effect_getpass(prompt): | |
"(Optional) Registration Key:": "New Password", | ||
"Please confirm:": "New Password", | ||
} | ||
for key, value in iteritems(fixtures): | ||
for key, value in fixtures.items(): | ||
if key in prompt: | ||
return value | ||
raise KeyError(f"Couldn't find answer for {prompt}") | ||
|
@@ -870,7 +921,7 @@ def side_effect_input(prompt): | |
"Will you be using your own " | ||
"Self-Hosted Landscape installation? [y/N]": "n", | ||
} | ||
for key, value in iteritems(fixtures): | ||
for key, value in fixtures.items(): | ||
if key in prompt: | ||
return value | ||
|
||
|
@@ -879,7 +930,7 @@ def side_effect_getpass(prompt): | |
"(Optional) Registration Key:": "New Password", | ||
"Please confirm:": "New Password", | ||
} | ||
for key, value in iteritems(fixtures): | ||
for key, value in fixtures.items(): | ||
if key in prompt: | ||
return value | ||
|
||
|
@@ -1231,6 +1282,27 @@ def test_main_no_registration(self, mock_setup, mock_register, mock_input): | |
"\nRequest a new registration for this computer now? [Y/n]: ", | ||
) | ||
|
||
@mock.patch("landscape.client.configuration.input") | ||
@mock.patch("landscape.client.configuration.register") | ||
@mock.patch("landscape.client.configuration.setup") | ||
def test_skip_registration(self, mock_setup, mock_register, mock_input): | ||
""" | ||
Registration and input asking user to register is not called | ||
when flag on | ||
""" | ||
main(["-c", self.make_working_config(), "--skip-registration"], | ||
print=noop_print) | ||
mock_register.assert_not_called() | ||
mock_input.assert_not_called() | ||
|
||
@mock.patch("landscape.client.configuration.register") | ||
@mock.patch("landscape.client.configuration.setup") | ||
def test_main_no_registration_silent(self, mock_setup, mock_register): | ||
"""Skip registration works in silent mode""" | ||
main(["-c", self.make_working_config(), "--skip-registration", | ||
"--silent"], print=noop_print) | ||
mock_register.assert_not_called() | ||
|
||
@mock.patch( | ||
"landscape.client.configuration.register", | ||
return_value="success", | ||
|
@@ -2139,7 +2211,8 @@ def test_base64_ssl_public_key_is_exported_to_file( | |
mock_print_text.assert_called_once_with( | ||
f"Writing SSL CA certificate to {key_filename}...", | ||
) | ||
self.assertEqual("Hi there!", open(key_filename).read()) | ||
with open(key_filename) as fh: | ||
self.assertEqual("Hi there!", fh.read()) | ||
|
||
options = ConfigParser() | ||
options.read(config_filename) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice you are using single quotes instead of double quotes like we have elsewhere in the code. Our linters don't catch this, but it would be good to be consistent.