Skip to content
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

Merged
merged 1 commit into from
Sep 30, 2016

Conversation

khorolets
Copy link
Collaborator

No description provided.

@@ -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
Copy link
Owner

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.

Copy link
Owner

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Owner

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).

Copy link
Owner

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):
Copy link
Owner

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.

@khorolets khorolets force-pushed the options_tests branch 2 times, most recently from c9035e6 to 7ca37ae Compare September 30, 2016 12:29
@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling c9035e6 on khorolets:options_tests into de01c7a on frol:master.

@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling 7ca37ae on khorolets:options_tests into de01c7a on frol:master.

assert response.status_code == status_code
if result:
assert len(
list(set(result) - set(response.headers['Allow'].replace(' ', '').split(',')))
Copy link
Owner

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(', ')))

response = flask_app_client.options(path)

assert response.status_code == 204
assert not (set(result) - set(response.headers['Allow'].split(', ')))
Copy link
Owner

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

Copy link
Collaborator Author

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?

Copy link
Owner

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.

@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling fa80b14 on khorolets:options_tests into de01c7a on frol:master.

response = flask_app_client.options(path)

assert response.status_code == 204
assert not (set(result) - set(response.headers['Allow'].split(', ')))
Copy link
Owner

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.

@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling 966a8b9 on khorolets:options_tests into de01c7a on frol:master.

@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling 539e45a on khorolets:options_tests into de01c7a on frol:master.

response = flask_app_client.options(path)

assert response.status_code == 204
assert expected_allowed_methods == set(response.headers['Allow'].split(', '))
Copy link
Owner

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.

Copy link
Collaborator Author

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 :)

@coveralls
Copy link

coveralls commented Sep 30, 2016

Coverage Status

Coverage remained the same at 91.386% when pulling bc3b520 on khorolets:options_tests into de01c7a on frol:master.

@frol frol merged commit 64bc2ad into frol:master Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants