Skip to content

Commit 2ff4375

Browse files
committed
main: fix pytest tests not succeeding
1 parent ec3b25a commit 2ff4375

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

main/tests/test_donor_import.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from email.header import Header
44
from email.message import Message
5-
from mailbox import Maildir
5+
from io import StringIO
66

77
import pytest
88

@@ -16,12 +16,8 @@
1616
command = Command()
1717

1818

19-
def gen_parse_subject(data):
20-
return command.parse_subject(data)
21-
22-
23-
def test_parse_subject(self):
24-
assert self.command.parse_subject('garbage') is None
19+
def test_parse_subject():
20+
assert command.parse_subject('garbage') is None
2521

2622
# Valid
2723
valid = 'Receipt [$25.00] By: John Doe [[email protected]]'
@@ -42,41 +38,39 @@ def test_decode_subject():
4238
assert command.decode_subject(subject) == text
4339

4440

45-
def test_invalid_args():
41+
def test_invalid_args(monkeypatch):
42+
monkeypatch.setattr('sys.stdin', StringIO(''))
4643
with pytest.raises(CommandError) as e:
4744
call_command('donor_import')
48-
assert 'Error: the following arguments are required' in str(e.value)
45+
assert 'Failed to read from STDIN' in str(e.value)
4946

5047

5148
def test_invalid_path():
5249
with pytest.raises(CommandError) as e:
5350
call_command('donor_import', '/tmp/non-existant')
54-
assert 'Failed to open maildir' in str(e.value)
55-
51+
assert 'argument input: can\'t open' in str(e.value)
5652

57-
def test_maildir(db, tmp_path):
58-
tmpdir = tmp_path / 'archweb'
59-
tmpdir.mkdir()
60-
mdir = tmpdir / 'maildir'
6153

62-
maildir = Maildir(mdir)
54+
def test_maildir(db, monkeypatch):
6355
msg = Message()
6456
msg['subject'] = 'John Doe'
6557
msg['to'] = 'John Doe <[email protected]>'
66-
maildir.add(msg)
6758

6859
# Invalid
69-
call_command('donor_import', mdir)
60+
monkeypatch.setattr('sys.stdin', StringIO(msg.as_string()))
61+
with pytest.raises(SystemExit):
62+
call_command('donor_import')
7063
assert len(Donor.objects.all()) == 0
7164

72-
# Valid
65+
# # Valid
7366
msg = Message()
7467
msg['subject'] = 'Receipt [$25.00] By: David Doe [[email protected]]'
7568
msg['to'] = 'John Doe <[email protected]>'
76-
maildir.add(msg)
77-
call_command('donor_import', mdir)
69+
monkeypatch.setattr('sys.stdin', StringIO(msg.as_string()))
70+
call_command('donor_import')
7871
assert len(Donor.objects.all()) == 1
7972

80-
# Re-running should result in no new donor
81-
call_command('donor_import', mdir)
73+
# # Re-running should result in no new donor
74+
monkeypatch.setattr('sys.stdin', StringIO(msg.as_string()))
75+
call_command('donor_import')
8276
assert len(Donor.objects.all()) == 1

main/tests/test_templatetags_flags.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from main.templatetags.flags import country_flag
2+
from mirrors.tests.conftest import checklocation # noqa: F401
23

34

4-
def test_country_flag(checklocation):
5+
def test_country_flag(checklocation): # noqa: F811
56
flag = country_flag(checklocation.country)
67
assert checklocation.country.name in flag
78
assert checklocation.country.code.lower() in flag

0 commit comments

Comments
 (0)