Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion legal-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "legal-api"
version = "3.1.14"
version = "3.1.15"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from flask_pydantic import validate as pydantic_validate
from pydantic import BaseModel

from business_account import AccountService
from business_common.utils.legislation_datetime import LegislationDatetime
from business_model.models import Business, Document, UserRoles
from business_model.models import Filing as FilingModel
Expand Down Expand Up @@ -118,7 +119,7 @@ def get_documents(identifier: str, # noqa: PLR0911, PLR0912

if legal_filing_name:
if legal_filing_name.lower().startswith("receipt"):
return _get_receipt(business, filing, jwt.get_token_auth_header())
return _get_receipt(business, filing)

return get_pdf(filing.storage, legal_filing_name)
elif file_key and (document := Document.find_by_file_key(file_key)):
Expand Down Expand Up @@ -206,7 +207,7 @@ def _get_document_list(business: Business, filing: Filing):
return jsonify(document_list), HTTPStatus.OK


def _get_receipt(business: Business, filing: Filing, token):
def _get_receipt(business: Business, filing: Filing):
"""Get the receipt for the filing."""
if filing.status not in (
Filing.Status.COMPLETED,
Expand All @@ -223,8 +224,8 @@ def _get_receipt(business: Business, filing: Filing, token):
filing.filing_type == "noticeOfWithdrawal"
):
effective_date = LegislationDatetime.format_as_report_string(filing.storage.effective_date)

headers = {"Authorization": "Bearer " + token}
service_token = AccountService.get_bearer_token()
headers = {"Authorization": "Bearer " + service_token}
Comment thread
kialj876 marked this conversation as resolved.
add_account_linking_key_header(headers)

corp_name = _get_corp_name(business, filing.storage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,7 @@ def test_temp_document_list_for_various_filing_states(app, mocker, session, clie
assert rv_data == expected


def test_get_receipt(session, client, jwt, requests_mock):
def test_get_receipt(session, client, jwt, requests_mock, mocker):
"""Assert that a receipt is generated."""
from legal_api.resources.v2.business.business_filings.business_documents import _get_receipt

Expand Down Expand Up @@ -1990,15 +1990,17 @@ def test_get_receipt(session, client, jwt, requests_mock):
json={'foo': 'bar'},
status_code=HTTPStatus.CREATED)

token = helper_create_jwt(jwt, roles=[STAFF_ROLE], username='username')
service_token = 'service-token-abc'
mocker.patch('business_account.AccountService.get_bearer_token', return_value=service_token)

content, status_code = _get_receipt(business, filing_core, token)
content, status_code = _get_receipt(business, filing_core)

assert status_code == HTTPStatus.CREATED
assert requests_mock.called_once
assert requests_mock.last_request.headers.get('Authorization') == f'Bearer {service_token}'


def test_get_receipt_request_mock(session, client, jwt, requests_mock):
def test_get_receipt_request_mock(session, client, jwt, requests_mock, mocker):
"""Assert that a receipt is generated."""
from legal_api.resources.v2.business.business_filings.business_documents import _get_receipt

Expand All @@ -2025,6 +2027,9 @@ def test_get_receipt_request_mock(session, client, jwt, requests_mock):
json={'foo': 'bar'},
status_code=HTTPStatus.CREATED)

service_token = 'service-token-abc'
mocker.patch('business_account.AccountService.get_bearer_token', return_value=service_token)

rv = client.get(f'/api/v2/businesses/{identifier}/filings/{filing.id}/documents/receipt',
headers=create_header(jwt,
[STAFF_ROLE],
Expand All @@ -2033,10 +2038,11 @@ def test_get_receipt_request_mock(session, client, jwt, requests_mock):
)

assert rv.status_code == HTTPStatus.CREATED
assert requests_mock.called_once
assert requests_mock.called
assert requests_mock.last_request.headers.get('Authorization') == f'Bearer {service_token}'


def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests_mock):
def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests_mock, mocker):
"""Assert that the receipt call forwards the Account-Linking-Key header when present on the request."""
identifier = 'CP7654321'
business = factory_business(identifier)
Expand All @@ -2060,6 +2066,8 @@ def test_get_receipt_forwards_account_linking_key(session, client, jwt, requests
json={'foo': 'bar'},
status_code=HTTPStatus.CREATED)

mocker.patch('business_account.AccountService.get_bearer_token', return_value='service-token')

rv = client.get(f'/api/v2/businesses/{identifier}/filings/{filing.id}/documents/receipt',
headers=create_header(jwt,
[STAFF_ROLE],
Expand Down