Skip to content

test: Check if email is sent for new mentorship relation requests #536

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions app/api/email_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ def send_email_new_request(user_sender, user_recipient, notes, sender_role):
)
subject = "Mentorship System - You have got new relation request"
send_email(user_recipient.email, subject, html)

Copy link
Member

Choose a reason for hiding this comment

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

can you undo these changes? just to keep the changes to test module?

Copy link
Member

Choose a reason for hiding this comment

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

can you remove these changes? I can merge them but if you could take these off as well. This seems like style format changes, that can be done in another PR


2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ itsdangerous==0.24
Jinja2==2.10
jmespath==0.9.3
jsonschema==2.6.0
MarkupSafe==1.0
MarkupSafe==1.1.1
mccabe==0.6.1
paramiko==2.7.1
pathspec==0.5.5
Expand Down
54 changes: 54 additions & 0 deletions tests/mentorship_relation/test_api_create_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import unittest
from datetime import datetime, timedelta
from app.api.mail_extension import mail
from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase
from tests.test_utils import get_test_request_header

class TestCreateMentorshipRequestApi(MentorshipRelationBaseTestCase):

# Setup consists of adding 2 users into the database
# User 1 is the mentorship relation requester = action user
# User 2 is the receiver
def setUp(self):
super(TestCreateMentorshipRequestApi, self).setUp()

self.notes_example = 'description of a good mentorship relation'
self.now_datetime = datetime.now()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

mail.init_app(self.app)

def test_create_mentorship_request(self):
with mail.record_messages() as outbox:
with self.client:
response = self.client.post('/mentorship_relation/send_request',
headers=get_test_request_header(self.first_user.id),
json={
"mentor_id": self.first_user.id,
"mentee_id": self.second_user.id,
"end_date": self.end_date_example.timestamp(),
"notes": self.notes_example
})

self.assertEqual(200, response.status_code)
self.assertEqual(1, len(outbox))
self.assertEqual([self.second_user.email], outbox[0].recipients)

def test_create_invalid_mentorship_request(self):
with mail.record_messages() as outbox:
with self.client:
# receiver's id and action user's id are equal
response = self.client.post('/mentorship_relation/send_request',
headers=get_test_request_header(self.first_user.id),
json={
"mentor_id": self.first_user.id,
"mentee_id": self.first_user.id,
"end_date": self.end_date_example.timestamp(),
"notes": self.notes_example
})
self.assertNotEqual(200, response.status_code)
self.assertEqual(0, len(outbox))


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