Пример #1
0
def test_delete_bad_id(session):
    """Assert that delete by invalid document ID works as expected."""
    with pytest.raises(BusinessException) as not_found_err:
        Draft.delete('X12345X')

    # check
    assert not_found_err
    assert not_found_err.value.status_code == HTTPStatus.NOT_FOUND
Пример #2
0
    def delete(document_id):
        """Delete a draft statement by document ID."""
        try:
            if document_id is None:
                return path_param_error_response('document ID')

            # Quick check: must be staff or provide an account ID.
            account_id = get_account_id(request)
            if not is_staff(jwt) and account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            # Try to fetch draft statement by document ID
            Draft.delete(document_id)

            return '', HTTPStatus.NO_CONTENT

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Пример #3
0
def test_save_then_delete(session):
    """Assert that a save then delete draft statement returns the expected result."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)

    new_draft = Draft.create_from_json(json_data, 'PS12345')
    new_draft.save()
    draft = new_draft.json
    assert draft
    assert draft['changeStatement']
    assert draft['type'] == 'CHANGE_STATEMENT'
    assert draft['createDateTime']
    assert draft['changeStatement']['registeringParty']
    assert draft['changeStatement']['baseRegistrationNumber']
    assert draft['changeStatement']['changeType']
    assert draft['changeStatement']['documentId']

    # Now test delete draft
    document_id = draft['changeStatement']['documentId']
    delete_draft = Draft.delete(document_id)
    assert delete_draft