Save MailRule and MailAccount objects in tests

This fixes the errors in the tests that the new many-to-many
assign_tags property cannot be accessed due to MailRule not having an
id. In one case it it necessary to give additional names to both objects
as several are created.
This commit is contained in:
jonasc 2022-03-11 17:00:27 +01:00
parent 4022284059
commit 37f7ef41f2

View File

@ -308,10 +308,12 @@ class TestMail(DirectoriesMixin, TestCase):
)
account = MailAccount()
account.save()
rule = MailRule(
assign_title_from=MailRule.TitleSource.FROM_FILENAME,
account=account,
)
rule.save()
result = self.mail_account_handler.handle_message(message, rule)
@ -355,10 +357,12 @@ class TestMail(DirectoriesMixin, TestCase):
)
account = MailAccount()
account.save()
rule = MailRule(
assign_title_from=MailRule.TitleSource.FROM_FILENAME,
account=account,
)
rule.save()
result = self.mail_account_handler.handle_message(message, rule)
@ -381,10 +385,12 @@ class TestMail(DirectoriesMixin, TestCase):
)
account = MailAccount()
account.save()
rule = MailRule(
assign_title_from=MailRule.TitleSource.FROM_FILENAME,
account=account,
)
rule.save()
result = self.mail_account_handler.handle_message(message, rule)
@ -406,11 +412,13 @@ class TestMail(DirectoriesMixin, TestCase):
)
account = MailAccount()
account.save()
rule = MailRule(
assign_title_from=MailRule.TitleSource.FROM_FILENAME,
account=account,
attachment_type=MailRule.AttachmentProcessing.EVERYTHING,
)
rule.save()
result = self.mail_account_handler.handle_message(message, rule)
@ -440,12 +448,15 @@ class TestMail(DirectoriesMixin, TestCase):
for (pattern, matches) in tests:
matches.sort()
self.async_task.reset_mock()
account = MailAccount()
account = MailAccount(name=str(uuid.uuid4()))
account.save()
rule = MailRule(
name=str(uuid.uuid4()),
assign_title_from=MailRule.TitleSource.FROM_FILENAME,
account=account,
filter_attachment_filename=pattern,
)
rule.save()
result = self.mail_account_handler.handle_message(message, rule)