-
Notifications
You must be signed in to change notification settings - Fork 342
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
Add tests for OPTIONS method in users and teams modules #34
Conversation
@@ -24,3 +24,20 @@ def team_for_regular_user(db, regular_user, readonly_user): | |||
db.session.delete(regular_user_team_member) | |||
db.session.delete(team) | |||
db.session.commit() | |||
|
|||
@pytest.yield_fixture() | |||
def team_for_nobody(db): # pylint: disable=invalid-name |
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 suggest we create another tests/.pylincrc
, where we disable these and some other checks.
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.
Where do you use this fixture? O_o
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.
My bad, I've renamed it and then forget to use new name.
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.
About pylint, what do you want me to do? Should I create rcfile or remove this disable
?
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.
Try to copy the existing .pylintrc
to tests
, and disable all unnecessary checks (all that are currently complained about).
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 also wonder if it supports nesting, e.g. if we just put a tests/.pylintrc
with a few lines of config instead of a complete copy...
('/api/v1/teams/', 401), | ||
('/api/v1/users/1', 401), | ||
)) | ||
def test_users_options_unauthorized(path, status_code, flask_app_client): |
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 think it is worth to rename these functions. users
in not an appropriate name in teams
module.
c9035e6
to
7ca37ae
Compare
assert response.status_code == status_code | ||
if result: | ||
assert len( | ||
list(set(result) - set(response.headers['Allow'].replace(' ', '').split(','))) |
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.
Just for your info, there is no point in converting set
to list
since len()
works just fine on sets.
Also, there is no point in doing len(...) == 0
, it is just less pythonic, though I think you know. You may also learn about any
and all
.
Also, split()
can handle a string as a parameter, which it will handle as a list of possible separators (not like one single multicharacter separator), so
>>> 'A, B'.split(', ')
['A', 'B']
Ultimately, I would write this check like this:
assert not (set(result) - set(response.headers['Allow'].split(', ')))
7ca37ae
to
fa80b14
Compare
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == 204 | ||
assert not (set(result) - set(response.headers['Allow'].split(', '))) |
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.
@codacy-bot Are you mad? O_o
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.
@frol They are really unnecessary, no?
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.
Oh, actually, the better way is to compare sets because you don't want the test pass when the expected result is ['OPTIONS']
, and returned value is ['OPTIONS', 'GET']
. So:
assert set(result) == set(response.headers['Allow'].split(', '))
I would also rename result
into expected_allowed_methods
, and define them as sets from the beginning.
fa80b14
to
966a8b9
Compare
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == 204 | ||
assert not (set(result) - set(response.headers['Allow'].split(', '))) |
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.
Oh, actually, the better way is to compare sets because you don't want the test pass when the expected result is ['OPTIONS']
, and returned value is ['OPTIONS', 'GET']
. So:
assert set(result) == set(response.headers['Allow'].split(', '))
I would also rename result
into expected_allowed_methods
, and define them as sets from the beginning.
966a8b9
to
539e45a
Compare
response = flask_app_client.options(path) | ||
|
||
assert response.status_code == 204 | ||
assert expected_allowed_methods == set(response.headers['Allow'].split(', ')) |
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 will drive you crazy, but I want you change this thing once (I hope last) time again. Just like with the line above, you write and expression on the left, and "const" on the right... So I would like to swap the expected_allowed_methods
and the right side.
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.
Ha! I was teaching at school for almost 3 years. You won't drive me crazy so easy :)
539e45a
to
bc3b520
Compare
No description provided.