tests: add tests on feed_mail command (#40816)
This commit is contained in:
parent
126e137998
commit
44afd83770
|
@ -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)
|
Loading…
Reference in New Issue