Cleaning up old notes

This commit is contained in:
Carlos Lopez 2020-06-29 08:38:38 -06:00
parent bb4000ff6d
commit c7b864f9c7
3 changed files with 16 additions and 17 deletions

View File

@ -57,23 +57,11 @@ class Approval(object):
@classmethod
def from_model(cls, model: ApprovalModel):
# TODO: Reduce the code by iterating over model's dict keys
instance = cls()
instance.id = model.id
instance.study_id = model.study_id
instance.workflow_id = model.workflow_id
instance.version = model.version
instance.approver_uid = model.approver_uid
instance.status = model.status
instance.message = model.message
instance.date_created = model.date_created
instance.date_approved = model.date_approved
instance.version = model.version
instance.title = ''
args = dict((k, v) for k, v in model.__dict__.items() if not k.startswith('_'))
instance = cls(**args)
instance.related_approvals = []
instance.title = model.study.title if model.study else ''
if model.study:
instance.title = model.study.title
try:
instance.approver = LdapService.user_info(model.approver_uid)
instance.primary_investigator = LdapService.user_info(model.study.primary_investigator_id)

View File

@ -13,7 +13,7 @@ class EmailService(object):
"""Provides common tools for working with an Email"""
@staticmethod
def add_email(subject, sender, recipients, content, content_html, study_id):
def add_email(subject, sender, recipients, content, content_html, study_id=None):
"""We will receive all data related to an email and store it"""
# Find corresponding study - if any

View File

@ -31,4 +31,15 @@ class TestEmailService(BaseTest):
self.assertEqual(email_model.content_html, content_html)
self.assertEqual(email_model.study, study)
# TODO: Create email model without study
subject = 'Email Subject - Empty study'
EmailService.add_email(subject=subject, sender=sender, recipients=recipients,
content=content, content_html=content_html)
email_model = EmailModel.query.order_by(EmailModel.id.desc()).first()
self.assertEqual(email_model.subject, subject)
self.assertEqual(email_model.sender, sender)
self.assertEqual(email_model.recipients, str(recipients))
self.assertEqual(email_model.content, content)
self.assertEqual(email_model.content_html, content_html)
self.assertEqual(email_model.study, None)