Skip to content

Commit a3f3403

Browse files
committed
devel: port to pytest
1 parent 135dbf0 commit a3f3403

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

devel/tests/test_pgp_import.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from unittest.mock import patch
22

3+
import pytest
4+
35
from django.core.management import call_command
46
from django.core.management.base import CommandError
5-
from django.test import TransactionTestCase
67

78

89
CREATED = 1541685162
@@ -19,28 +20,26 @@
1920
]
2021

2122

22-
class PGPImportTest(TransactionTestCase):
23-
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json']
24-
25-
def test_pgp_import_error(self):
26-
with self.assertRaises(CommandError) as e:
27-
call_command('pgp_import')
28-
self.assertIn('keyring_path', str(e.exception))
29-
30-
@patch('devel.management.commands.pgp_import.call_gpg')
31-
def test_pgp_import_garbage_data(self, mock_call_gpg):
32-
mock_call_gpg.return_value = 'barf'
33-
with patch('devel.management.commands.pgp_import.logger') as logger:
34-
call_command('pgp_import', '/tmp')
35-
logger.info.assert_called()
36-
logger.info.assert_any_call('created %d, updated %d signatures', 0, 0)
37-
logger.info.assert_any_call('created %d, updated %d keys', 0, 0)
38-
39-
@patch('devel.management.commands.pgp_import.call_gpg')
40-
def test_pgp_import(self, mock_call_gpg):
41-
mock_call_gpg.return_value = '\n'.join(SIG_DATA)
42-
with patch('devel.management.commands.pgp_import.logger') as logger:
43-
call_command('pgp_import', '/tmp')
44-
logger.info.assert_called()
45-
logger.info.assert_any_call('created %d, updated %d signatures', 0, 0)
46-
logger.info.assert_any_call('created %d, updated %d keys', 1, 0)
23+
def test_pgp_import_error(arches, repos):
24+
with pytest.raises(CommandError) as e:
25+
call_command('pgp_import')
26+
assert 'keyring_path' in str(e.value)
27+
28+
29+
@patch('devel.management.commands.pgp_import.call_gpg')
30+
def test_pgp_import_garbage_data(mock_call_gpg, arches, repos):
31+
mock_call_gpg.return_value = 'barf'
32+
with patch('devel.management.commands.pgp_import.logger') as logger:
33+
call_command('pgp_import', '/tmp')
34+
logger.info.assert_called()
35+
logger.info.assert_any_call('created %d, updated %d signatures', 0, 0)
36+
logger.info.assert_any_call('created %d, updated %d keys', 0, 0)
37+
38+
@patch('devel.management.commands.pgp_import.call_gpg')
39+
def test_pgp_import(mock_call_gpg, arches, repos):
40+
mock_call_gpg.return_value = '\n'.join(SIG_DATA)
41+
with patch('devel.management.commands.pgp_import.logger') as logger:
42+
call_command('pgp_import', '/tmp')
43+
logger.info.assert_called()
44+
logger.info.assert_any_call('created %d, updated %d signatures', 0, 0)
45+
logger.info.assert_any_call('created %d, updated %d keys', 1, 0)
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
from unittest.mock import patch
22

3-
43
from django.core.management import call_command
5-
from django.test import TransactionTestCase
6-
74

8-
class RematchDeveloperTest(TransactionTestCase):
9-
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json']
105

11-
def test_rematch_developers(self):
12-
with patch('devel.management.commands.rematch_developers.logger') as logger:
13-
call_command('rematch_developers')
14-
logger.info.assert_called()
6+
def test_rematch_developers(arches, repos):
7+
with patch('devel.management.commands.rematch_developers.logger') as logger:
8+
call_command('rematch_developers')
9+
logger.info.assert_called()

devel/tests/test_templatetags.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
from django.contrib.auth.models import User
2-
from django.test import TestCase
3-
41
from devel.templatetags.group import in_group
52

63

7-
class DevelTemplatetagsTest(TestCase):
8-
def test_in_group(self):
9-
user = User.objects.create(username="joeuser", first_name="Joe",
10-
last_name="User", email="[email protected]")
11-
self.assertEqual(in_group(user, 'none'), False)
4+
def test_in_group(admin_user):
5+
assert in_group(admin_user, 'none') == False

0 commit comments

Comments
 (0)