def setUpTestData(cls): # Create a user, handled by UserBasedTest. super(GmailConnectorTests, cls).setUpTestData() # Create an email account for the user. EmailAccountFactory.create(owner=cls.user_obj, tenant=cls.user_obj.tenant)
def test_private_account(self): """ Test if having an email account set to private returns no data for unauthorized users. """ email_account = EmailAccountFactory.create(tenant=self.tenant, privacy=EmailAccount.PRIVATE, owner=self.owner) # Share the email account with a user. config = { 'user': self.users[1], 'email_account': email_account, 'privacy': EmailAccount.PUBLIC, 'tenant': self.tenant, } email_account.sharedemailconfig_set.create(**config) email_messages = EmailMessageFactory.create_batch(account=email_account, size=10) for user in self.users: filtered_messages = [] for email_message in email_messages: filtered_message = get_filtered_message(email_message, email_account, user) if filtered_message: filtered_messages.append(filtered_message) if self._can_view_full_message(email_account, user): self.assertEqual(filtered_messages, email_messages) else: self.assertEqual(filtered_messages, [])
def test_public_account(self): """ Test if having an email account set to public returns all data for everyone. """ email_account = EmailAccountFactory.create(tenant=self.tenant, privacy=EmailAccount.PUBLIC, owner=self.owner) # Share the email account with a user. config = { 'user': self.users[1], 'email_account': email_account, 'privacy': EmailAccount.PUBLIC, 'tenant': self.tenant, } email_account.sharedemailconfig_set.create(**config) email_messages = EmailMessageFactory.create_batch(account=email_account, size=10) for user in self.users: filtered_messages = [] for email_message in email_messages: filtered_message = get_filtered_message(email_message, email_account, user) if filtered_message: filtered_messages.append(filtered_message) self.assertEqual(filtered_messages, email_messages)
def test_metadata_only(self): """ Test if having an email account set to metadata only returns filtered data for unauthorized users. """ email_account = EmailAccountFactory.create( tenant=self.tenant, privacy=EmailAccount.METADATA, owner=self.owner) # Share the email account with a user. config = { 'user': self.users[1], 'email_account': email_account, 'privacy': EmailAccount.PUBLIC, 'tenant': self.tenant, } email_account.sharedemailconfig_set.create(**config) email_messages = EmailMessageFactory.create_batch( account=email_account, size=10) stripped_messages = [] for email_message in email_messages: stripped_messages.append({ 'id': email_message.id, 'sender': email_message.sender, 'received_by': email_message.received_by.all(), 'received_by_cc': email_message.received_by_cc.all(), 'sent_date': email_message.sent_date, 'account': email_message.account, }) for user in self.users: filtered_messages = [] for email_message in email_messages: filtered_message = get_filtered_message( email_message, email_account, user) if filtered_message: filtered_messages.append(filtered_message) if self._can_view_full_message(email_account, user): self.assertEqual(filtered_messages, email_messages) else: # Comparing lists of dicts doesn't seem to work properly. # So loop through all filter and stripped messages and compare them. for i in range(len(filtered_messages)): self.assertItemsEqual(filtered_messages[i], stripped_messages[i])
def get_or_create_draft(self): """ Both _create_object and get_url require an email draft, while some tests make that only one of these functions are called. To simplify, we use this method to return a draft when there isn't one. """ if hasattr(self, 'email_draft'): return self.email_draft user = get_current_user() email_account = EmailAccountFactory.create(owner=user, tenant=user.tenant) self.email_draft = EmailDraftFactory(tenant=user.tenant, send_from=email_account) return self.email_draft
def setUpTestData(cls): # Create a user, handled by UserBasedTest. super(EmailMessageTests, cls).setUpTestData() # Create an email account for the user. cls.email_account = EmailAccountFactory.create( owner=cls.user_obj, tenant=cls.user_obj.tenant) # Create a default recipient recipient = Recipient.objects.create(name='Firstname Lastname', email_address='*****@*****.**') # Create a default email message, initially without any labels. cls.email_message = EmailMessage.objects.create( account=cls.email_account, sent_date=datetime.now(), sender=recipient)
def test_metadata_only(self): """ Test if having an email account set to metadata only returns filtered data for unauthorized users. """ email_account = EmailAccountFactory.create(tenant=self.tenant, privacy=EmailAccount.METADATA, owner=self.owner) # Share the email account with a user. config = { 'user': self.users[1], 'email_account': email_account, 'privacy': EmailAccount.PUBLIC, 'tenant': self.tenant, } email_account.sharedemailconfig_set.create(**config) email_messages = EmailMessageFactory.create_batch(account=email_account, size=10) stripped_messages = [] for email_message in email_messages: stripped_messages.append({ 'id': email_message.id, 'sender': email_message.sender, 'received_by': email_message.received_by.all(), 'received_by_cc': email_message.received_by_cc.all(), 'sent_date': email_message.sent_date, 'account': email_message.account, }) for user in self.users: filtered_messages = [] for email_message in email_messages: filtered_message = get_filtered_message(email_message, email_account, user) if filtered_message: filtered_messages.append(filtered_message) if self._can_view_full_message(email_account, user): self.assertEqual(filtered_messages, email_messages) else: # Comparing lists of dicts doesn't seem to work properly. # So loop through all filter and stripped messages and compare them. for i in range(len(filtered_messages)): self.assertItemsEqual(filtered_messages[i], stripped_messages[i])
def setUpTestData(cls): super(EmailOutboxMessageTests, cls).setUpTestData() # Create an email account for the user. cls.email_account = EmailAccountFactory.create( owner=cls.user_obj, tenant=cls.user_obj.tenant ) cls.body_content = ( 'In hac habitasse platea dictumst. Class ' 'aptent taciti sociosqu ad litora torquent per conubia nostra' ', per inceptos himenaeos. Ut aliquet elit sed augue bibendum ' 'malesuada.' ) to = '*****@*****.**' kwargs = dict( subject='Mauris ex tortor, hendrerit non sem eu, varius purus.', send_from=cls.email_account, to=anyjson.dumps([to]), cc=anyjson.dumps(None), bcc=anyjson.dumps(None), body='<html><body><br/>{}</body></html>'.format(cls.body_content), headers={}, mapped_attachments=0, template_attachment_ids='', original_message_id='', tenant=cls.user_obj.tenant ) cls.email_outbox_message = EmailOutboxMessage.objects.create(**kwargs) # Some fields are different types in EmailDraft kwargs['to'] = [to] kwargs['cc'] = [] kwargs['bcc'] = [] kwargs['send_from'] = cls.email_account cls.email_draft = EmailDraft.objects.create(**kwargs)
def setupEmailMessage(cls): # Create an email account for the user. cls.email_account = EmailAccountFactory.create(owner=cls.user_obj, tenant=cls.user_obj.tenant) # Create a default recipient sender = Recipient.objects.create( name='Firstname Lastname', email_address='*****@*****.**', ) # Create a default email message, initially without any labels. cls.email_message = EmailMessage.objects.create( subject='Simple Subject', account=cls.email_account, sent_date=timezone.now(), sender=sender, ) received_by = Recipient.objects.create( name='Simple Name', email_address='*****@*****.**', ) cls.email_message.received_by.add(received_by)
def setUp(self): email_account = EmailAccountFactory.create(owner=self.user_obj, tenant=self.user_obj.tenant) self.email_draft = EmailDraftFactory(tenant=self.user_obj.tenant, send_from=email_account)
def setUpTestData(cls): # Create a user, handled by UserBasedTest. super(EmailTests, cls).setUpTestData() # Create an email account for the user. cls.email_account = EmailAccountFactory.create(owner=cls.user_obj, tenant=cls.user_obj.tenant)