-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
test: Start integrating pytest #6827
Conversation
"""To test details in the form of dict""" | ||
error_response = ErrorResponse(source="test source", detail="test detail") | ||
expected_dict = { | ||
'status': error_response.status, |
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.
Black would make changes.
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.
Pre-commit ran black
Codecov Report
@@ Coverage Diff @@
## development #6827 +/- ##
===============================================
- Coverage 66.94% 60.87% -6.08%
===============================================
Files 314 259 -55
Lines 15423 13564 -1859
===============================================
- Hits 10325 8257 -2068
- Misses 5098 5307 +209 Continue to review full report at Codecov.
|
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.
Looks fine to me
@iamareebjamal Can you please take a look at this? |
This will close the issue when it just changes 1 test. Besides, the main tests we want to change are db tests |
Yes, I just wanted to know if I was going in the right direction on this. I am planning to change all the tests in a similar way in this PR itself. |
Just change 1 DB test for now |
|
||
user = create_user(email='[email protected]', password='password') | ||
user.is_admin = False | ||
status = AuthManager.check_auth_admin('[email protected]', 'password') | ||
self.assertEqual(False, status) | ||
assert False == status |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
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.
doesn't apply here.
@@ -42,12 +42,12 @@ def test_check_auth_admin(self): | |||
user = create_user(email='[email protected]', password='password') | |||
user.is_admin = True | |||
status = AuthManager.check_auth_admin('[email protected]', 'password') | |||
self.assertEqual(True, status) | |||
assert True == status |
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.
comparison to True should be 'if cond is True:' or 'if cond:'
@@ -33,7 +33,7 @@ def test_is_accessible(self): | |||
user = create_user(email='[email protected]', password='password') | |||
login_user(user) | |||
logout_user() | |||
self.assertEqual(AuthManager.is_accessible(), False) | |||
assert AuthManager.is_accessible() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
@@ -24,7 +24,7 @@ def test_verified_user(self): | |||
user = create_user(email='[email protected]', password='password') | |||
user.is_verified = False | |||
login_user(user) | |||
self.assertEqual(AuthManager.is_verified_user(), False) | |||
assert AuthManager.is_verified_user() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
@@ -15,7 +15,7 @@ def test_load_user(self): | |||
|
|||
with self.app.test_request_context(): | |||
user = create_user(email='[email protected]', password='password') | |||
self.assertEqual(user, db.session.query(User).get(user.id)) | |||
assert user == db.session.query(User).get(user.id) |
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.
Nope. It is still not pytest test. This is standard unit test
user = create_user(email='[email protected]', password='password') | ||
user.is_admin = False | ||
status = AuthManager.check_auth_admin('[email protected]', 'password') | ||
assert False == status |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
user = create_user(email='[email protected]', password='password') | ||
user.is_admin = True | ||
status = AuthManager.check_auth_admin('[email protected]', 'password') | ||
assert True == status |
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.
comparison to True should be 'if cond is True:' or 'if cond:'
user = create_user(email='[email protected]', password='password') | ||
login_user(user) | ||
logout_user() | ||
assert AuthManager.is_accessible() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
user = create_user(email='[email protected]', password='password') | ||
user.is_verified = False | ||
login_user(user) | ||
assert AuthManager.is_verified_user() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
from tests.all.integration.setup_database import Setup | ||
|
||
|
||
@pytest.fixture(scope='module') |
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.
Black would make changes.
from flask_login import login_user, logout_user | ||
|
||
from flask import Flask, session |
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.
'flask.Flask' imported but unused
'flask.session' imported but unused
redefinition of unused 'Flask' from line 2
@iamareebjamal @mrsaicharan1 can you please take a look at this? |
Yes, I did. And the build is failing |
@iamareebjamal Can you please review this? |
Then change it to correct command |
do I have to add pytest in requirements and change travis yml file ? |
You may |
.travis.yml
Outdated
- nosetests tests/ -v --with-coverage | ||
script: | | ||
nosetests tests/ -v --with-coverage -I tests/all/integration/api/helpers/test_auth.py | ||
pytest tests/all/integration/api/helpers/test_auth.py |
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.
Not cool
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 didn't know another way to do it.
Somehow I have to exclude test_auth from nostests and test it with pytest
.travis.yml
Outdated
@@ -40,3 +41,4 @@ branches: | |||
only: | |||
- master | |||
- development | |||
- pytest |
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.
Not cool
.travis.yml
Outdated
script: | ||
- nosetests tests/ -v --with-coverage | ||
script: | ||
- nosetests tests/ --ignore-files="test_auth\.py" -v --with-coverage |
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.
Nope
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.
sir, nosetests fails for a pytest code. Should I add a pytest script in yml file?
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.
All tests should run with 1 script
user = create_user(email='[email protected]', password='password') | ||
user.is_admin = False | ||
status = AuthManager.check_auth_admin('[email protected]', 'password') | ||
assert False == status |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
user = create_user(email='[email protected]', password='password') | ||
user.is_admin = True | ||
status = AuthManager.check_auth_admin('[email protected]', 'password') | ||
assert True == status |
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.
comparison to True should be 'if cond is True:' or 'if cond:'
user = create_user(email='[email protected]', password='password') | ||
login_user(user) | ||
logout_user() | ||
assert AuthManager.is_accessible() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
user = create_user(email='[email protected]', password='password') | ||
user.is_verified = False | ||
login_user(user) | ||
assert AuthManager.is_verified_user() == False |
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.
comparison to False should be 'if cond is False:' or 'if not cond:'
Here is an overview of what got changed by this pull request: Complexity increasing per file
==============================
- tests/all/integration/api/validation/test_created_at.py 5
- tests/all/unit/api/helpers/test_errors.py 5
- tests/all/integration/api/helpers/test_auth.py 1
See the complete overview on Codacy |
Reference #6503
Short description of what this resolves:
Converts test code to pytest standard
Changes proposed in this pull request:
Change in test code
Checklist
development
branch.