This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Adding sudo args #75
Open
Erf-
wants to merge
1
commit into
rockymeza:master
Choose a base branch
from
Erf-:adding-sudo-args
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
Adding sudo args #75
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from unittest import TestCase | ||
|
||
from wifi.scan import Cell | ||
from wifi import subprocess_compat as subprocess | ||
from mock import patch | ||
from test_parsing import IWLIST_SCAN_WEP, IWLIST_SCAN_WPA2 | ||
|
||
|
||
expected_output = '\n'.join([IWLIST_SCAN_WEP, IWLIST_SCAN_WPA2]) | ||
|
||
class ScanTest(TestCase): | ||
def test_all_calls_check_output_with_good_args(self): | ||
args = ['/sbin/iwlist', 'interface', 'scan'] | ||
kwargs = {'stderr':subprocess.STDOUT} | ||
with patch.object(subprocess, 'check_output', | ||
return_value=expected_output): | ||
Cell.all('interface') | ||
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. why is the indent different? |
||
subprocess.check_output.assert_called_with(args, **kwargs) | ||
args.insert(0, 'sudo') | ||
Cell.all('interface', sudo=True) | ||
subprocess.check_output.assert_called_with(args, **kwargs) | ||
|
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
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 |
---|---|---|
|
@@ -164,13 +164,20 @@ def as_args(self): | |
|
||
return [self.interface + '=' + self.iface] + args | ||
|
||
def activate(self): | ||
def activate(self, sudo=False): | ||
""" | ||
Connects to the network as configured in this scheme. | ||
""" | ||
|
||
subprocess.check_output(['/sbin/ifdown', self.interface], stderr=subprocess.STDOUT) | ||
ifup_output = subprocess.check_output(['/sbin/ifup'] + self.as_args(), stderr=subprocess.STDOUT) | ||
args_ifdown = ['/sbin/ifdown', self.interface] | ||
args_ifup = ['/sbin/ifup'] | ||
if sudo: | ||
args_ifdown.insert(0, 'sudo') | ||
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. down comes first, let's keep it logical everywhere, more readable |
||
args_ifup.insert(0, 'sudo') | ||
subprocess.check_output(args_ifdown, stderr=subprocess.STDOUT) | ||
ifup_output = subprocess.check_output(args_ifup + | ||
self.as_args(), | ||
stderr=subprocess.STDOUT) | ||
ifup_output = ifup_output.decode('utf-8') | ||
|
||
return self.parse_ifup_output(ifup_output) | ||
|
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.
If you do it the other way around, you can set args only once, and then inserting
sudo
for next test.