|
1 | 1 | from unittest.mock import patch
|
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | from django.core.management import call_command
|
4 | 6 | from django.core.management.base import CommandError
|
5 |
| -from django.test import TransactionTestCase |
6 | 7 |
|
7 | 8 |
|
8 | 9 | CREATED = 1541685162
|
|
19 | 20 | ]
|
20 | 21 |
|
21 | 22 |
|
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) |
0 commit comments