-
Notifications
You must be signed in to change notification settings - Fork 448
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: Revoking admin status #181
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||
import unittest | ||||||
from flask import json | ||||||
from flask_restplus import marshal | ||||||
from app.api.models.admin import add_models_to_namespace | ||||||
from app.api.models.user import public_user_api_model | ||||||
from app.database.models.user import UserModel | ||||||
from app.api.dao import admin | ||||||
from app.database.sqlalchemy_extension import db | ||||||
from tests.base_test_case import BaseTestCase | ||||||
from tests.test_utils import get_test_request_header | ||||||
from tests.test_data import user1, user2, test_admin_user | ||||||
|
||||||
|
||||||
class TestListAdminsApi(BaseTestCase): | ||||||
def setUp(self): | ||||||
super(TestListAdminsApi, self).setUp() | ||||||
|
||||||
self.verified_user = UserModel( | ||||||
name=user1['name'], | ||||||
email=user1['email'], | ||||||
username=user1['username'], | ||||||
password=user1['password'], | ||||||
terms_and_conditions_checked=user1['terms_and_conditions_checked'] | ||||||
) | ||||||
self.other_user = UserModel( | ||||||
name=user2['name'], | ||||||
email=user2['email'], | ||||||
username=user2['username'], | ||||||
password=user2['password'], | ||||||
terms_and_conditions_checked=user2['terms_and_conditions_checked'] | ||||||
) | ||||||
|
||||||
self.verified_user.is_email_verified = True | ||||||
db.session.add(self.verified_user) | ||||||
db.session.add(self.other_user) | ||||||
db.session.commit() | ||||||
|
||||||
def test_revoke_admin_admin(self): | ||||||
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.
Suggested change
|
||||||
if (self.verified_user.is_admin and self.other_user.is_admin): | ||||||
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. remove this if statement. you want to test the api, with this values regardless of their values |
||||||
expected_response = {'message': 'User admin status was revoked.'} | ||||||
actual_response = self.client.get('/admin/remove', follow_redirects=True) | ||||||
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. to test api, you have to create header arguments and then use it on the api call. Example: auth_header, otherwise the calls will fail, because the test user isn't authenticated. Do this for the other tests |
||||||
|
||||||
self.assertEqual(200, actual_response.status_code) | ||||||
self.assertEqual(expected_response, json.loads(actual_response.data)) | ||||||
|
||||||
|
||||||
def test_revoke_user(self): | ||||||
if(self.verified_user.is_admin and self.other_user.is_admin == 0): | ||||||
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. remove this if statement |
||||||
expected_response = {'message': 'User is not an Admin.'} | ||||||
actual_response = self.client.post('/admin/remove', follow_redirects=True) | ||||||
|
||||||
self.assertEqual(400, actual_response.status_code) | ||||||
self.assertEqual(expected_response, json.loads(actual_response.data)) | ||||||
|
||||||
|
||||||
# def test_revoke_non_user(self): | ||||||
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. No commented code in PRs please. |
||||||
# if(self.other_user.): | ||||||
# expected_response = {'message': 'User does not exist.'} | ||||||
# actual_response = self.client.get('/admin/remove', follow_redirects=True) | ||||||
# | ||||||
# self.assertEqual(404, actual_response.status_code) | ||||||
# self.assertEqual(expected_response, json.loads(actual_response.data)) | ||||||
|
||||||
def test_revoke_self_admin(self): | ||||||
if(self.verified_user.is_admin and self.verified_user==self.other_user): | ||||||
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. remove this if |
||||||
expected_response = {'message': 'You cannot revoke your admin status.'} | ||||||
actual_response = self.client.get('/admin/remove', follow_redirects=True) | ||||||
|
||||||
self.assertEqual(403, actual_response.status_code) | ||||||
self.assertEqual(expected_response, json.loads(actual_response.data)) | ||||||
|
||||||
# def test_revoke_self_admin(self): | ||||||
# expected_response = {'message': 'You cannot revoke your admin status.'} | ||||||
# actual_response = self.client.get('/admin/remove', follow_redirects=True) | ||||||
|
||||||
# self.assertEqual(403, actual_response.status_code) | ||||||
# self.assertEqual(expected_response, json.loads(actual_response.data)) | ||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
unittest.main() |
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.
space between variables and operator, follow everywhere, complying to PEP8