|
| 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