-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
Change optparse for argparse. #238
Merged
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f0b903f
Change optparse for argparse.
de42a87
Fix imports order.
041d689
Fix flake8 issues.
00ca237
Add test for cli
0449e53
Fix linter errors.
a5a6202
Fix tox errors:
5675713
Revert test_require pytest to pytest==2.7.3
f96a98a
Fixed tests.
79dbfad
Change optparse for argparse.
33fd8b8
Fix imports order.
80fa761
Fix flake8 issues.
f758fc0
Add test for cli
b6221ee
Fix linter errors.
096c800
Fix tox errors:
3f7cde4
Fixed tests.
f6612a7
Address PR comments.
c326ef3
Added new test cases to test_main_run
b614247
Removed unnecessary try...catch clauses.
238d9a8
Refactor and cleanup
3878ff1
Remove commented import that is not in use
a31bfe0
- Eliminated __name__ == '__main__"
e34f447
Remove sys.exit.
4466782
Reaise code cov
ce4d420
Fixed flake8 errors
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ omit = | |
.tox/* | ||
setup.py | ||
*.egg/* | ||
*/__main__.py | ||
|
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,60 @@ | ||
|
||
froi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from __future__ import unicode_literals | ||
|
||
import jwt | ||
from jwt.__main__ import build_argparser, decode_payload, encode_payload, main | ||
|
||
import pytest | ||
|
||
|
||
class TestCli: | ||
|
||
def test_build_argparse(self): | ||
args = ['--key', '1234', 'encode', 'name=Vader'] | ||
parser = build_argparser() | ||
parsed_args = parser.parse_args(args) | ||
|
||
assert parsed_args.key == '1234' | ||
|
||
def test_encode_payload_raises_value_error_key_is_required(self): | ||
encode_args = ['encode', 'name=Vader', 'job=Sith'] | ||
parser = build_argparser() | ||
|
||
args = parser.parse_args(encode_args) | ||
|
||
with pytest.raises(ValueError) as excinfo: | ||
encode_payload(args) | ||
|
||
assert 'Key is required when encoding' in str(excinfo.value) | ||
|
||
def test_decode_payload_raises_decoded_error(self): | ||
decode_args = ['--key', '1234', 'decode', 'wrong-token'] | ||
parser = build_argparser() | ||
|
||
args = parser.parse_args(decode_args) | ||
|
||
with pytest.raises(jwt.DecodeError) as excinfo: | ||
decode_payload(args) | ||
|
||
assert 'There was an error decoding the token' in str(excinfo.value) | ||
|
||
@pytest.mark.parametrize('key,name,job', [ | ||
('1234', 'Vader', 'Sith'), | ||
('4567', 'Anakin', 'Jedi'), | ||
]) | ||
def test_main_run(self, key, name, job): | ||
args = [ | ||
froi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'--key', key, | ||
'encode', | ||
'name={0}'.format(name), | ||
'job={0}'.format(job) | ||
] | ||
|
||
token = main(args) | ||
actual = jwt.decode(token, key) | ||
expected = { | ||
'job': job, | ||
'name': name, | ||
} | ||
|
||
assert actual == expected |
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.
@froi Noticed another thing missing.
python setup.py install
pyjwt
It'll fail with something like this:
Since we're using the
console_scripts
entry point on oursetup.py
I think we should be able to drop just drop theif __name__ == '__main__': ...
and have themain()
method optionally set args tosys.argv[1:]
. Let me know if this makes sense.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.
That'll work but it'll also make
main()
harder to test I think. I'll take a look at it.