Created
November 8, 2017 20:09
-
-
Save cnk/4b9f26334bb84b8c4b4f3d24f1d83e51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from ...jobs import CampusAnnouncementImporter | |
class Command(BaseCommand): | |
help = "Imports Campus Announcements." | |
def handle(self, **options): | |
importer = CampusAnnouncementImporter() | |
print(type(CampusAnnouncementImporter)) | |
importer.import_campus_announcement_sections() | |
importer.import_campus_announcements() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@multitenant multitenant]# ./test-runner.sh sites.tests.test_campus_announcement_importer.TestCampusAnnouncementImporter.test_management_command | |
Using existing test database for alias 'default'... | |
System check identified no issues (3 silenced). | |
['__class__', | |
'__delattr__', | |
'__dict__', | |
'__dir__', | |
'__doc__', | |
'__eq__', | |
'__format__', | |
'__ge__', | |
'__getattribute__', | |
'__gt__', | |
'__hash__', | |
'__init__', | |
'__le__', | |
'__lt__', | |
'__module__', | |
'__ne__', | |
'__new__', | |
'__reduce__', | |
'__reduce_ex__', | |
'__repr__', | |
'__setattr__', | |
'__sizeof__', | |
'__str__', | |
'__subclasshook__', | |
'__weakref__', | |
'assert_any_call', | |
'assert_called_once_with', | |
'assert_called_with', | |
'assert_has_calls', | |
'attach_mock', | |
'call_args', | |
'call_args_list', | |
'call_count', | |
'called', | |
'configure_mock', | |
'import_campus_announcement_sections', | |
'import_campus_announcements', | |
'method_calls', | |
'mock_add_spec', | |
'mock_calls', | |
'reset_mock', | |
'return_value', | |
'side_effect'] | |
<class 'unittest.mock.NonCallableMagicMock'> | |
F | |
====================================================================== | |
FAIL: test_management_command (sites.tests.test_campus_announcement_importer.TestCampusAnnouncementImporter) | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/multitenant/sites/tests/test_campus_announcement_importer.py", line 98, in test_management_command | |
self.assertEqual(announcement_importer.import_campus_announcement_sections.call_count, 1) | |
AssertionError: 0 != 1 | |
---------------------------------------------------------------------- | |
Ran 1 test in 0.024s | |
FAILED (failures=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import mock | |
from django.test import TestCase | |
from pprint import pprint | |
class TestCampusAnnouncementImporter(TestCase): | |
def test_management_command(self): | |
with mock.patch('sites.jobs.CampusAnnouncementImporter', autospec=True) as announcement_importer: | |
pprint(dir(importer_mock)) | |
# Test the arg-less command. | |
management.call_command('import_campus_announcements') | |
self.assertEqual(announcement_importer.call_count, 1) | |
self.assertEqual(announcement_importer.import_campus_announcement_sections.call_count, 1) | |
self.assertEqual(announcement_importer.import_campus_announcements.call_count, 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment