Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/all/integration/api/helpers/test_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import unittest
from app import current_app as app
from tests.all.integration.auth_helper import create_user
from app.api.helpers.user import modify_email_for_user_to_be_deleted, \
modify_email_for_user_to_be_restored
from app.api.helpers.db import save_to_db
from app.api.helpers.exceptions import ForbiddenException

from tests.all.integration.utils import OpenEventTestCase
from tests.all.integration.setup_database import Setup


class TestUserUtilitiesHelper(OpenEventTestCase):
def setUp(self):
self.app = Setup.create_app()

def test_modify_email_for_user_to_be_deleted(self):
"""Method to test modification of email for user to be deleted"""

with app.test_request_context():
user = create_user(email="[email protected]", password="testpass")
save_to_db(user)
modified_user = modify_email_for_user_to_be_deleted(user)
self.assertEqual("[email protected]", modified_user.email)

def test_modify_email_for_user_to_be_restored(self):
"""Method to test modification of email for user to be restored"""

with app.test_request_context():
user = create_user(email="[email protected]", password="testpass")
save_to_db(user)
modified_user = modify_email_for_user_to_be_restored(user)
self.assertEqual("[email protected]", modified_user.email)

user1 = create_user(email="[email protected]", password="testpass")
save_to_db(user1)
user2 = create_user(email="[email protected]", password="testpass")
save_to_db(user2)
self.assertRaises(ForbiddenException, modify_email_for_user_to_be_restored, user2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests LGTM 👍
@mrsaicharan1 just a query - Is the user2 passed to the function modify_email_for_user_to_be_restored by this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreyanshdwivedi yes, that's how assertRaises works!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Approving



if __name__ == '__main__':
unittest.main()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'unittest'