def test_match_user_by_secret_in_body_plus_whitespaces(self): """ secret is placed in the message body. SECRET{ ... } Notice that between secret message and curly bracket there can be whitespaces; however between keyword SECRET and immediately following opening curly bracket - there is no space. """ email_message = _create_email( # notice that secret is in the message body body=""" Lieber Freund, Blah, blah, blah und es gib ein White Space da! SECRET{ this-is-elizabet-secret } PS: no space is allowed between keyword SECRET and immediately following curly bracket. """) # Both margaret AND elizabeth have mail_by_secret # attribute set to True. _set_email_routing_pref(self.margaret, 'by_secret', True) _set_email_routing_pref(self.elizabet, 'by_secret', True) user = get_matching_user(email_message, by_secret=True) self.assertNotEqual(user, self.margaret) self.assertEqual(user, self.elizabet)
def test_extract_user_by_secret_not_allowed_user(self): email_message = _create_email( subject='SECRET{this-is-margaret-secret}') user = get_matching_user(email_message, by_secret=True) self.assertIsNone(user)
def test_extract_user_by_secret_allowed_settings(self): email_message = _create_email( subject='SECRET{this-is-elizabet-secret}') _set_email_routing_pref(self.elizabet, 'by_secret', True) user = get_matching_user(email_message) self.assertIsNone(user)
def test_extract_user_by_mail_address_allowed_settings(self): email_message = _create_email(from_field=self.elizabet.email) self.elizabet.mail_by_user = True self.elizabet.save() user = get_matching_user(email_message) self.assertIsNone(user)
def test_pdf_imap_importer(self): file_path = os.path.join(BASE_DIR, "data", "berlin.pdf") email_message = _create_email( attachment=file_path, maintype='application', subtype='pdf', ) user = get_matching_user(email_message) self.assertIsNone(user) trigger_document_pipeline(email_message, user, skip_ocr=True) self.assertEqual(Document.objects.count(), 1)
def test_match_user_by_from_field_address_with_pref_set(self): """ Will match user by "from_field" ONLY if that user has 'email_routing__by_user' pref set to True. """ email_message = _create_email(from_field=self.elizabet.email) _set_email_routing_pref(self.elizabet, "by_user", True) user = get_matching_user(email_message, by_user=True) self.assertNotEqual(user, self.margaret) self.assertEqual(user, self.elizabet)
def test_match_user_by_from_field_address_without_pref_set(self): """ Will match user by "from_field" ONLY if that user has 'email_routing__by_user' pref set to True. """ email_message = _create_email(from_field=self.margaret.email) # explicitely set email_routing__by_user to False _set_email_routing_pref(self.margaret, "by_user", False) user = get_matching_user(email_message, by_user=True) # won't match because of the pref self.assertIsNone(user)
def test_match_user_by_secret_in_subject_1(self): """ Email secret can be placed in email subject """ email_message = _create_email( # notice that secret is in message subject subject='SECRET{this-is-elizabet-secret}') _set_email_routing_pref(self.elizabet, 'by_secret', True) user = get_matching_user(email_message, by_secret=True) self.assertNotEqual(user, self.margaret) self.assertEqual(user, self.elizabet)
def test_match_user_by_secret_in_body_2(self): """ If email secret is detected in email body BUT relevant user do not have user.mail_by_secret set to True, then ``get_matching_user`` should return None """ email_message = _create_email( # notice that secret is in message body body='SECRET{this-is-margaret-secret}') # Both margaret AND elizabeth have mail_by_secret # attribute set to False (!) _set_email_routing_pref(self.margaret, 'by_secret', False) _set_email_routing_pref(self.elizabet, 'by_secret', False) user = get_matching_user(email_message) self.assertIsNone(user, self.margaret)
def test_match_user_by_secret_in_body_1(self): """ If email secret is detected in email body AND user.mail_by_secret == True, then ``get_matching_user`` should return correct user. """ email_message = _create_email( # notice that secret is in the message body body='hello ! SECRET{this-is-elizabet-secret} Bye bye!') # Both margaret AND elizabeth have mail_by_secret # attribute set to True. _set_email_routing_pref(self.margaret, 'by_secret', True) _set_email_routing_pref(self.elizabet, 'by_secret', True) user = get_matching_user(email_message, by_secret=True) self.assertNotEqual(user, self.margaret) self.assertEqual(user, self.elizabet)
def test_match_user_by_secret_in_subject_2(self): """ Email secret can be placed in email subject AND there can be white spaces AROUND the secret """ email_message = _create_email( # notice that secret is in message subject # and is there are white spaces around the # secret message. However, there are # no spaces between word SECRET and immediately following # it opening curly bracket subject='SECRET{ this-is-elizabet-secret }') _set_email_routing_pref(self.elizabet, 'by_secret', True) user = get_matching_user(email_message, by_secret=True) self.assertNotEqual(user, self.margaret) self.assertEqual(user, self.elizabet)
def test_extract_user_by_mail_address_not_allowed_settings(self): email_message = _create_email(from_field=self.margaret.email) user = get_matching_user(email_message) self.assertIsNone(user)