Projet

Général

Profil

0004-tests-add-tests-on-feed_mail-command-40816.patch

Nicolas Roche, 20 mars 2020 09:43

Télécharger (2,04 ko)

Voir les différences:

Subject: [PATCH 4/4] tests: add tests on feed_mail command (#40816)

 tests/test_mail_command.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 tests/test_mail_command.py
tests/test_mail_command.py
1
# welco - multichannel request processing
2
# Copyright (C) 2020  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
import pytest
18

  
19
from django.core.management import call_command
20
from django.core.management.base import CommandError
21

  
22
from welco.sources.mail.models import Mail
23

  
24

  
25
def test_feed_mail_command(settings, tmpdir, db):
26
    settings.MEDIA_ROOT = str(tmpdir)
27
    path1 = '%s/mail1.txt' % str(tmpdir)
28
    path2 = '%s/mail2.txt' % str(tmpdir)
29
    path3 = '%s/mail3.txt' % str(tmpdir)
30
    open(path2, 'w').write('not a PDF')
31
    open(path3, 'w').write('%PDF- is a PDF')
32

  
33
    call_command('feed_mail', '--category', 'foobar', path1, path2, path3)
34
    Mail.objects.count() == 1
35
    Mail.objects.all()[0].scanner_category == 'foobar'
36

  
37
    with pytest.raises(CommandError, match='nothing got imported'):
38
        call_command('feed_mail', '--category', path1, path2)
0
-