Ejemplo n.º 1
0
def test_view_mfn_schedules_renders_successfully(authenticated_client):
    MFNDocumentFactory(document_type=SCHEDULE)
    MFNDocumentFactory(document_type=CLASSIFICATION)
    uri = reverse('schedule:mfn:manage')
    _assert_view_propoerties(
        authenticated_client,
        uri,
        ['schedule/mfn/manage.html', 'schedule/mfn/document_summary.html'],
        'MFN schedules',
        False
    )
Ejemplo n.º 2
0
 def test_list_view(self, authenticated_client):
     classification_mfn_document = MFNDocumentFactory(
         document_type=CLASSIFICATION)
     schedule_mfn_document = MFNDocumentFactory(
         document_type=SCHEDULE, document_status=DocumentStatus.UNAVAILABLE)
     response = authenticated_client.get(reverse('api:mfn-document-list'))
     assert response.status_code == 200
     actual_response = sort_list_result(response.json(),
                                        key='document_type')
     assert len(actual_response) == 2
     self.assert_mfn_document(classification_mfn_document,
                              actual_response[CLASSIFICATION])
     self.assert_mfn_document(schedule_mfn_document,
                              actual_response[SCHEDULE])
Ejemplo n.º 3
0
 def test_detail_view(self, authenticated_client, document_status):
     schedule_mfn_document = MFNDocumentFactory(document_type=SCHEDULE)
     response = authenticated_client.get(
         reverse('api:mfn-document-detail',
                 kwargs={'document_type': SCHEDULE}))
     assert response.status_code == 200
     actual_response = response.json()
     self.assert_mfn_document(schedule_mfn_document, actual_response)
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def test_regenerate_mfn_document(
    mock_generate_document,
    authenticated_client,
    create_mfn_document,
    document_status,
    document_type,
    expected_document_to_be_generated
):
    mock_generate_document.return_value = None
    if create_mfn_document:
        MFNDocumentFactory(document_status=document_status, document_type=document_type)
    uri = reverse('schedule:mfn:regenerate', kwargs={'document_type': document_type})
    response = authenticated_client.get(uri)
    assert response.status_code == 302
    assert response.get('Location') == reverse('schedule:mfn:manage')
    assert mock_generate_document.called is expected_document_to_be_generated
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def get_object(self):
     return MFNDocumentFactory(document_type=self.document_type)
Ejemplo n.º 10
0
def test_mfn_document_history_model():
    mfn_document = MFNDocumentFactory()
    document_history = MFNDocumentHistoryFactory(mfn_document=mfn_document)
    assert str(document_history) == f'schedule - Doc History - 2019-02-01 02:00:00+00:00'
Ejemplo n.º 11
0
def test_download_mfn_document_when_no_document_exists_for_agreement(authenticated_client):
    MFNDocumentFactory()
    uri = reverse('schedule:mfn:download', kwargs={'document_type': SCHEDULE})
    response = authenticated_client.get(uri)
    assert response.status_code == 302
    assert response.get('Location') == reverse('schedule:mfn:manage')