示例#1
0
    def test_rollback(
        self,
        formatted_dnb_company,
        fields,
        expected_fields,
    ):
        """
        Test that rollback_dnb_company_update will roll back all DNB fields.
        """
        with reversion.create_revision():
            company = CompanyFactory(
                duns_number=formatted_dnb_company['duns_number'])

        original_company = Company.objects.get(id=company.id)

        update_company_from_dnb(
            company,
            formatted_dnb_company,
            update_descriptor='foo',
        )

        rollback_dnb_company_update(company, 'foo', fields_to_update=fields)

        company.refresh_from_db()
        for field in expected_fields:
            assert getattr(company, field) == getattr(original_company, field)

        latest_version = Version.objects.get_for_object(company)[0]
        assert latest_version.revision.comment == 'Reverted D&B update from: foo'
    def _process_row(self, row, update_descriptor, simulate=False, **options):
        """Process one single row."""
        pk = parse_uuid(row['id'])
        company = Company.objects.get(pk=pk)

        if simulate:
            return

        rollback_dnb_company_update(company, update_descriptor)
示例#3
0
    def test_rollback_error(
        self,
        formatted_dnb_company,
        update_comment,
        error_message,
    ):
        """
        Test that rollback_dnb_company_update will fail with the given error
        message when there is an issue in finding the version to revert to.
        """
        company = CompanyFactory(duns_number=formatted_dnb_company['duns_number'])

        update_company_from_dnb(
            company,
            formatted_dnb_company,
            update_descriptor='foo',
        )

        with pytest.raises(RevisionNotFoundError) as excinfo:
            rollback_dnb_company_update(company, update_comment)
            assert str(excinfo.value) == error_message