Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epicadk committed Mar 1, 2021
1 parent b6b5521 commit adb2fea
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/users/test_api_resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import asyncio
from unittest.mock import patch

from flask import json
Expand Down Expand Up @@ -343,6 +344,40 @@ def test_user_registration_with_taken_email(self, send_email_function):
)
self.assertEqual(response.status_code, 409)

@patch("flask_mail._MailMixin.send", side_effect=mail_send_mocked)
def test_race_conditions_on_signup(self, send_email_function):
async def make_request():
user = UserModel.query.first()
email = user.email
response = self.client.post(
"/register",
data=json.dumps(
dict(
name=user1["name"],
username=user1["username"],
password=user1["password"],
email=email,
terms_and_conditions_checked=user1[
"terms_and_conditions_checked"
],
)
),
follow_redirects=True,
content_type="application/json",
)
message = json.loads(response.get_data(as_text=True)).get("message")
users_count = UserModel.query.filter_by(email=email).count()
self.assertEqual(users_count, 1)
self.assertEqual(
message, USER_USES_AN_EMAIL_ID_THAT_ALREADY_EXISTS.get("message")
)
self.assertEqual(response.status_code, 409)

async def make2requests():
await asyncio.gather(make_request(), make_request())

asyncio.run(make2requests())


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

0 comments on commit adb2fea

Please sign in to comment.