コード例 #1
0
    def create_document(self):
        # Create the document
        my_document = Document(self)

        my_document.check_for_quotas()

        # Create the measures table
        my_document.get_duties("preferences")
        tariff_data = my_document.print_tariffs()

        # Create the quotas table
        my_document.get_duties("quotas")
        my_document.get_quota_order_numbers()
        my_document.get_quota_balances()
        my_document.get_quota_measures()
        my_document.get_quota_definitions()
        quota_data = my_document.print_quotas()

        context_data = {
            'AGREEMENT_NAME': self.agreement.agreement_name,
            'VERSION': self.agreement.version,
            'AGREEMENT_DATE': self.agreement.agreement_date_long,
            'AGREEMENT_DATE_SHORT': self.agreement.agreement_date_short,
            'COUNTRY_NAME': self.agreement.country_name,
            **tariff_data,
            **quota_data,
        }

        # Personalise and write the document
        my_document.create_document(context_data)
        update_document_status(self.agreement, DocumentStatus.AVAILABLE)
コード例 #2
0
def test_create_document(
    mock_render_to_string,
    mock_write,
    context,
    force,
    expected_template,
    expected_document_xml,
    expected_change,
    raise_write_exception,
):
    fake_file_name = 'fake_file.txt'

    mock_write.return_value = fake_file_name
    if raise_write_exception:
        mock_write.side_effect = EndpointConnectionError(endpoint_url='')

    mock_render_to_string.return_value = expected_document_xml
    agreement = AgreementFactory(country_name='Espana',
                                 slug='spain',
                                 country_codes=['1011'])
    application = Application(country_profile='spain',
                              force_document_generation=force)
    document = Document(application)
    document.create_document(context)

    if expected_document_xml:
        mock_render_to_string.assert_called_with(expected_template, context)
        mock_write.asssert_called_with(expected_document_xml)
    else:
        assert mock_render_to_string.called is False
        assert mock_write.called is False

    if expected_change:
        document_history = AgreementDocumentHistory.objects.get(
            agreement=agreement)
        assert document_history.forced is force
        assert document_history.data == context
        assert document_history.change == expected_change
        assert document_history.remote_file_name == fake_file_name
    else:
        assert AgreementDocumentHistory.objects.filter(
            agreement=agreement).exists() is False