Beispiel #1
0
def test_merge_documents(
    mock_composer,
    mock_document,
    document_type,
    with_toc,
    mock_docx_document_calls,
    expected_call_to_composer,
    expected_documents,
):
    fake_composer = FakeComposer
    fake_composer.documents = []
    mock_document.return_value = None
    mock_document.side_effect = mock_docx_document_calls
    mock_composer.return_value = fake_composer
    if with_toc:
        MFNTableOfContentWithDocumentFactory(
            document_check_sum=toc_checksum,
            document_type=document_type,
        )
    ChapterWithDocumentFactory(id=1)
    ChapterWithDocumentFactory(id=2)
    app = Application(document_type)
    app.merge_documents(f'{document_type}_document', '1.txt')
    mock_composer.assert_called_once_with(expected_call_to_composer)
    assert fake_composer.documents == expected_documents
    assert fake_composer.remote_file_name == '1.txt'
Beispiel #2
0
def test_create_document(mock_create_document, force, add_chapters,
                         expected_result):
    mock_create_document.return_value = None
    if add_chapters:
        ChapterFactory()
    mfn_document = MFNDocumentFactory(document_type=SCHEDULE)
    app = Application(SCHEDULE, force=force)
    app.create_document(mfn_document)
    assert mock_create_document.called is expected_result
Beispiel #3
0
def test_main_updates_document_status_when_mfn_document_does_not_exist(
        mock_create_document, mock_update_status, mock_update_last_checked):
    mock_create_document.return_value = None
    app = Application(SCHEDULE)
    app.main()
    assert mock_create_document.call_count == 1
    assert mock_update_status.call_count == 1
    assert mock_update_last_checked.call_count == 1
    assert mock_update_status.call_args_list[0] == mock.call(
        None, DocumentStatus.AVAILABLE)
Beispiel #4
0
def test_main_updates_document_status(mock_create_document,
                                      mock_update_status):
    mfn_document = MFNDocumentFactory(document_type=SCHEDULE)
    mock_create_document.return_value = None
    app = Application(SCHEDULE)
    app.main()
    assert mock_create_document.call_count == 1
    assert mock_update_status.call_count == 2
    assert mock_update_status.call_args_list[0] == mock.call(
        mfn_document, DocumentStatus.GENERATING)
    assert mock_update_status.call_args_list[1] == mock.call(
        mfn_document, DocumentStatus.AVAILABLE)
Beispiel #5
0
def test_upload_document_when_mfn_document_does_not_exist():
    app = Application(SCHEDULE)
    fake_file_content = b'information'
    with tempfile.NamedTemporaryFile() as f:
        f.write(fake_file_content)
        f.seek(0)
        app.upload_document(None, f.name, '1.docx')

    mfn_document = MFNDocument.objects.get(document_type=SCHEDULE)
    assert mfn_document.document.read() == fake_file_content
    assert mfn_document.document_check_sum == 'bb3ccd5881d651448ded1dac904054ac'
    assert mfn_document.document_created_at == timezone.now()
    assert mfn_document.document_status == DocumentStatus.UNAVAILABLE
Beispiel #6
0
def test_upload_document_when_mfn_document_exists():
    mfn_document = MFNDocumentFactory(
        document_check_sum='hello',
        document_type=SCHEDULE,
        document_status=DocumentStatus.AVAILABLE,
    )
    app = Application(SCHEDULE)
    fake_file_content = b'information'
    with tempfile.NamedTemporaryFile() as f:
        f.write(fake_file_content)
        f.seek(0)
        app.upload_document(mfn_document, f.name, '1.docx')

    mfn_document.refresh_from_db()
    assert mfn_document.document.read() == fake_file_content
    assert mfn_document.document_check_sum == 'bb3ccd5881d651448ded1dac904054ac'
    assert mfn_document.document_created_at == timezone.now()
    assert mfn_document.document_status == DocumentStatus.AVAILABLE
Beispiel #7
0
def test_write_document(mock_upload_document, mock_merge_documents):
    mock_merge_documents.return_value = None
    mock_upload_document.return_value = None
    forced = False
    app = Application(SCHEDULE)
    mfn_document = MFNDocumentFactory(document_type=SCHEDULE)
    mfn_history_log = MFNDocumentHistoryLog(
        mfn_document,
        {},
        forced,
        SCHEDULE,
    )
    app.write_document(mfn_document, mfn_history_log)
    assert mock_upload_document.called is True
    assert mock_merge_documents.called is True
    actual_history = MFNDocumentHistory.objects.get(
        mfn_document=mfn_document, )
    assert actual_history.change == {}
    assert actual_history.remote_file_name == 'schedule.docx'
    assert actual_history.forced == forced
    assert actual_history.document_type == SCHEDULE
Beispiel #8
0
def test_get_change_dict(document_type, with_toc, expected_checksum):
    chapter = ChapterFactory()
    chapter_with_checksum = ChapterFactory(
        id=2,
        schedule_document_check_sum=schedule_checksum,
        classification_document_check_sum=classification_checksum,
    )
    expected_change_dict = {
        chapter.get_document_name(document_type): None,
        chapter_with_checksum.get_document_name(document_type):
        expected_checksum,
    }

    if with_toc:
        MFNTableOfContentFactory(
            document_check_sum=toc_checksum,
            document_type=document_type,
        )
        expected_change_dict['toc'] = toc_checksum
    app = Application(document_type)
    actual_change_dict = app.get_change_dict()
    assert actual_change_dict == expected_change_dict
Beispiel #9
0
def test_initialise_with_force():
    app = Application(CLASSIFICATION, force=True)
    assert app.force is True
    assert app.document_type == CLASSIFICATION
Beispiel #10
0
def test_initialise_without_force():
    app = Application(SCHEDULE)
    assert app.force is False
    assert app.document_type == SCHEDULE
Beispiel #11
0
def generate_mfn_master_document(document_type, force=False):
    if not is_mfn_master_document_being_generated(document_type) or force:
        app = MFNMasterApplication(document_type, force=force)
        app.main()