summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas ROCHE <nroche@entrouvert.com>2020-03-20 08:37:30 (GMT)
committerNicolas ROCHE <nroche@entrouvert.com>2020-03-20 08:37:59 (GMT)
commit44afd83770a00c8c6cfe0e3ed85d371e76226f09 (patch)
treeab44adbacaeca7b93e7f45befdcc9d6c95cc3c7c
parent126e137998ee02f9aadb9140fdcd02608a04b6c6 (diff)
downloadwelco-44afd83770a00c8c6cfe0e3ed85d371e76226f09.zip
welco-44afd83770a00c8c6cfe0e3ed85d371e76226f09.tar.gz
welco-44afd83770a00c8c6cfe0e3ed85d371e76226f09.tar.bz2
tests: add tests on feed_mail command (#40816)
-rw-r--r--tests/test_mail_command.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_mail_command.py b/tests/test_mail_command.py
new file mode 100644
index 0000000..35aa43e
--- /dev/null
+++ b/tests/test_mail_command.py
@@ -0,0 +1,38 @@
+# welco - multichannel request processing
+# Copyright (C) 2020 Entr'ouvert
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import pytest
+
+from django.core.management import call_command
+from django.core.management.base import CommandError
+
+from welco.sources.mail.models import Mail
+
+
+def test_feed_mail_command(settings, tmpdir, db):
+ settings.MEDIA_ROOT = str(tmpdir)
+ path1 = '%s/mail1.txt' % str(tmpdir)
+ path2 = '%s/mail2.txt' % str(tmpdir)
+ path3 = '%s/mail3.txt' % str(tmpdir)
+ open(path2, 'w').write('not a PDF')
+ open(path3, 'w').write('%PDF- is a PDF')
+
+ call_command('feed_mail', '--category', 'foobar', path1, path2, path3)
+ Mail.objects.count() == 1
+ Mail.objects.all()[0].scanner_category == 'foobar'
+
+ with pytest.raises(CommandError, match='nothing got imported'):
+ call_command('feed_mail', '--category', path1, path2)