コード例 #1
0
ファイル: test_filing.py プロジェクト: severinbeauvais/lear
def test_get_a_businesses_most_recent_filing_of_a_type(session):
    """Assert that the most recent completed filing of a specified type is returned."""
    from legal_api.models import Filing
    from tests.unit.models import factory_completed_filing
    # setup
    identifier = 'CP7654321'
    b = factory_business(identifier)
    ar = copy.deepcopy(ANNUAL_REPORT)
    base_ar_date = datetime.datetime(2001,
                                     8,
                                     5,
                                     7,
                                     7,
                                     58,
                                     272362,
                                     tzinfo=datetime.timezone.utc)
    filings = []
    for i in range(0, 5):
        filing_date = base_ar_date + datedelta.datedelta(years=i)
        ar['filing']['annualReport']['annualGeneralMeetingDate'] = \
            filing_date.date().isoformat()
        filing = factory_completed_filing(b, ar, filing_date)
        filings.append(filing)
    # test
    filing = Filing.get_a_businesses_most_recent_filing_of_a_type(
        b.id, Filing.FILINGS['annualReport']['name'])

    # assert that we get the last filing
    assert filings[4] == filing
コード例 #2
0
def process(email_msg: dict) -> dict:
    """Build the email for Business Number notification."""
    logger.debug('bn notification: %s', email_msg)

    # get template and fill in parts
    template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-BN.html').read_text()
    filled_template = substitute_template_parts(template)

    # get filing and business json
    business = Business.find_by_identifier(email_msg['identifier'])
    filing = (Filing.get_a_businesses_most_recent_filing_of_a_type(business.id, 'incorporationApplication'))

    # render template with vars
    jnja_template = Template(filled_template, autoescape=True)
    html_out = jnja_template.render(
        business=business.json()
    )

    # get recipients
    recipients = get_recipients(email_msg['option'], filing.filing_json)
    return {
        'recipients': recipients,
        'requestBy': '*****@*****.**',
        'content': {
            'subject': f'{business.legal_name} - Business Number Information',
            'body': html_out,
            'attachments': []
        }
    }
コード例 #3
0
def validate(business: Business, annual_report: Dict) -> Error:
    """Validate the annual report JSON."""
    if not business or not annual_report:
        return Error(HTTPStatus.BAD_REQUEST, [{'error': _('A valid business and filing are required.')}])

    last_filing = Filing.get_a_businesses_most_recent_filing_of_a_type(
        business.id, Filing.FILINGS['annualReport']['name'])
    err = validate_ar_year(business=business,
                           previous_annual_report=last_filing,
                           current_annual_report=annual_report)
    if err:
        return err

    if requires_agm(business):
        err = validate_agm_year(business=business,
                                annual_report=annual_report)

    if err:
        return err

    return None