[FIX] base: prevent PhantomJS tests to send emails

The emails sending is skipped during the tests.
The mecanism to determine if the server was running tests
was to check if the attribute `testing` was set for the thread.

Unfortunately, this `testing` attribute is removed/set to false after the loading/installation
of the modules is done, and phantomJS tests are ran post-installation,
and therefore the emails that were potentialy sent following an action
performed in a PhantomJS tour were not skipped.

This occurred for instance in the tour `project.tour`,
when the responsible of a task was changed,
the sending of the assignation notification email was not skipped.

In the case the machine on which the tests are ran does
not have an smtp server (or mailcatcher) running on the port 25,
this resulted in a test fail.
This commit is contained in:
Denis Ledoux
2018-02-14 14:26:39 +01:00
parent 91f2209216
commit 0db75089ef
+1 -1
View File
@@ -409,7 +409,7 @@ class IrMailServer(models.Model):
message['To'] = x_forge_to
# Do not actually send emails in testing mode!
if getattr(threading.currentThread(), 'testing', False):
if getattr(threading.currentThread(), 'testing', False) or self.env.registry.in_test_mode():
_test_logger.info("skip sending email in test mode")
return message['Message-Id']