Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61adcc8

Browse files
authored
33840-filer-document-util (#4749)
1 parent cf78416 commit 61adcc8

7 files changed

Lines changed: 154 additions & 40 deletions

File tree

queue_services/business-filer/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "business-filer"
3-
version = "3.0.28"
3+
version = "3.0.29"
44
description = "Business Registry Filer Service"
55
authors = [
66
{name = "thor",email = "[email protected]"}

queue_services/business-filer/src/business_filer/filing_processors/continuation_in.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from business_filer.common.legislation_datetime import LegislationDatetime
2020
from business_filer.exceptions import QueueException
2121
from business_filer.filing_meta import FilingMeta
22-
from business_filer.filing_processors.filing_components import aliases, business_info, filings, shares
22+
from business_filer.filing_processors.filing_components import aliases, business_info, documents, filings, shares
2323
from business_filer.filing_processors.filing_components.offices import update_offices
2424
from business_filer.filing_processors.filing_components.parties import update_parties
2525

@@ -73,18 +73,12 @@ def create_authorization_documents(continuation_in: dict,
7373
filing_meta: FilingMeta):
7474
"""Create authorization documents."""
7575
authorization_files = continuation_in.get("authorization", {}).get("files", [])
76-
files = []
77-
for file in authorization_files:
78-
document = Document()
79-
document.type = DocumentType.AUTHORIZATION_FILE.value
80-
document.file_key = file.get("fileKey")
81-
document.file_name = file.get("fileName")
82-
files.append({
83-
"fileKey": document.file_key,
84-
"fileName": document.file_name
85-
})
86-
document.filing_id = filing.id
87-
business.documents.append(document)
76+
files = documents.create_filing_documents(
77+
authorization_files,
78+
DocumentType.AUTHORIZATION_FILE.value,
79+
business,
80+
filing
81+
)
8882

8983
filing_meta.continuation_in = {
9084
**filing_meta.continuation_in,

queue_services/business-filer/src/business_filer/filing_processors/continuation_out.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
from contextlib import suppress
3636

3737
import dpath
38-
from business_model.models import Business, Comment, Document, DocumentType, Filing
38+
from business_model.models import Business, Comment, DocumentType, Filing
3939

4040
from business_filer.common.legislation_datetime import LegislationDatetime
4141
from business_filer.filing_meta import FilingMeta
42-
from business_filer.filing_processors.filing_components import filings
42+
from business_filer.filing_processors.filing_components import documents, filings
4343

4444
# DocumentType.CONTINUATION_OUT is added to business-registry-model in this change, but the
4545
# filer installs that package from bcgov/lear@main, which won't have it until this lands.
@@ -57,18 +57,12 @@ def create_uploaded_documents(continuation_out: dict,
5757
filing: Filing,
5858
filing_meta: FilingMeta):
5959
"""Create document records for the supporting documents uploaded with the continuation out filing."""
60-
files = []
61-
for file in continuation_out.get("documents", []):
62-
document = Document()
63-
document.type = CONTINUATION_OUT_DOCUMENT_TYPE
64-
document.file_key = file.get("fileKey")
65-
document.file_name = file.get("fileName")
66-
document.filing_id = filing.id
67-
business.documents.append(document)
68-
files.append({
69-
"fileKey": document.file_key,
70-
"fileName": document.file_name
71-
})
60+
files = documents.create_filing_documents(
61+
continuation_out.get("documents", []),
62+
CONTINUATION_OUT_DOCUMENT_TYPE,
63+
business,
64+
filing
65+
)
7266

7367
if files:
7468
filing_meta.continuation_out = {

queue_services/business-filer/src/business_filer/filing_processors/court_order.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from business_model.models import Business, Document, DocumentType, Filing
3636

3737
from business_filer.filing_meta import FilingMeta
38-
from business_filer.filing_processors.filing_components import filings
38+
from business_filer.filing_processors.filing_components import documents, filings
3939

4040

4141
def process(business: Business, court_order_filing: Filing, filing: dict, filing_meta: FilingMeta):
@@ -57,17 +57,12 @@ def process(business: Business, court_order_filing: Filing, filing: dict, filing
5757
"fileName": f'Court Order {court_order_data.get("fileNumber")}.pdf'
5858
})
5959
elif files := court_order_data.get("files", []):
60-
for file in files:
61-
document = Document()
62-
document.type = DocumentType.COURT_ORDER.value
63-
document.file_key = file.get("fileKey")
64-
document.file_name = file.get("fileName")
65-
file_list.append({
66-
"fileKey": document.file_key,
67-
"fileName": document.file_name
68-
})
69-
document.filing_id = court_order_filing.id
70-
business.documents.append(document)
60+
file_list = documents.create_filing_documents(
61+
files,
62+
DocumentType.COURT_ORDER.value,
63+
business,
64+
court_order_filing
65+
)
7166

7267
if file_list:
7368
filing_meta.court_order = {

queue_services/business-filer/src/business_filer/filing_processors/filing_components/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
aliases,
4242
business_info,
4343
business_profile,
44+
documents,
4445
filings,
4546
name_request,
4647
resolutions,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright © 2025 Province of British Columbia
2+
#
3+
# Licensed under the BSD 3 Clause License, (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# The template for the license can be found here
6+
# https://opensource.org/license/bsd-3-clause/
7+
#
8+
# Redistribution and use in source and binary forms,
9+
# with or without modification, are permitted provided that the
10+
# following conditions are met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright notice,
13+
# this list of conditions and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright notice,
16+
# this list of conditions and the following disclaimer in the documentation
17+
# and/or other materials provided with the distribution.
18+
#
19+
# 3. Neither the name of the copyright holder nor the names of its contributors
20+
# may be used to endorse or promote products derived from this software
21+
# without specific prior written permission.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
24+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
# POSSIBILITY OF SUCH DAMAGE.
34+
"""Manages the document records for a filing."""
35+
from business_model.models import Business, Document, Filing
36+
37+
38+
def create_filing_documents(files: list[dict],
39+
document_type: str,
40+
business: Business,
41+
filing: Filing) -> list[dict]:
42+
"""Create a document record for each uploaded file and return the fileKey/fileName meta list."""
43+
file_list = []
44+
for file in files:
45+
document = Document()
46+
document.type = document_type
47+
document.file_key = file.get("fileKey")
48+
document.file_name = file.get("fileName")
49+
document.filing_id = filing.id
50+
business.documents.append(document)
51+
file_list.append({
52+
"fileKey": document.file_key,
53+
"fileName": document.file_name
54+
})
55+
return file_list
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright © 2025 Province of British Columbia
2+
#
3+
# Licensed under the BSD 3 Clause License, (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# The template for the license can be found here
6+
# https://opensource.org/license/bsd-3-clause/
7+
#
8+
# Redistribution and use in source and binary forms,
9+
# with or without modification, are permitted provided that the
10+
# following conditions are met:
11+
#
12+
# 1. Redistributions of source code must retain the above copyright notice,
13+
# this list of conditions and the following disclaimer.
14+
#
15+
# 2. Redistributions in binary form must reproduce the above copyright notice,
16+
# this list of conditions and the following disclaimer in the documentation
17+
# and/or other materials provided with the distribution.
18+
#
19+
# 3. Neither the name of the copyright holder nor the names of its contributors
20+
# may be used to endorse or promote products derived from this software
21+
# without specific prior written permission.
22+
#
23+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
24+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
# POSSIBILITY OF SUCH DAMAGE.
34+
"""The Unit Tests for the documents filing component."""
35+
import copy
36+
import random
37+
38+
import pytest
39+
from business_model.models import DocumentType
40+
from registry_schemas.example_data import ALTERATION_FILING_TEMPLATE
41+
42+
from business_filer.filing_processors.filing_components import documents
43+
from tests.unit import create_business, create_filing
44+
45+
46+
@pytest.mark.parametrize('test_name,files', [
47+
('no files', []),
48+
('one file', [
49+
{'fileKey': 'aaaaaaaa-1111-2222-3333-444444444444', 'fileName': 'document-1.pdf'}
50+
]),
51+
('multiple files', [
52+
{'fileKey': 'aaaaaaaa-1111-2222-3333-444444444444', 'fileName': 'document-1.pdf'},
53+
{'fileKey': 'bbbbbbbb-5555-6666-7777-888888888888', 'fileName': 'document-2.pdf'}
54+
])
55+
])
56+
def test_create_filing_documents(app, session, test_name, files):
57+
"""Assert that a document record is created per file and the meta list mirrors the files."""
58+
identifier = f'BC{random.randint(1000000, 9999999)}'
59+
business = create_business(identifier, legal_type='BC')
60+
json_filing = copy.deepcopy(ALTERATION_FILING_TEMPLATE)
61+
filing = create_filing(token='123', json_filing=json_filing, business_id=business.id)
62+
63+
file_list = documents.create_filing_documents(
64+
files, DocumentType.COURT_ORDER.value, business, filing)
65+
66+
business_documents = business.documents.all()
67+
assert len(business_documents) == len(files)
68+
assert file_list == [
69+
{'fileKey': file['fileKey'], 'fileName': file['fileName']} for file in files
70+
]
71+
for file in files:
72+
document = next(x for x in business_documents if x.file_key == file['fileKey'])
73+
assert document.type == DocumentType.COURT_ORDER.value
74+
assert document.file_name == file['fileName']
75+
assert document.filing_id == filing.id

0 commit comments

Comments
 (0)