コード例 #1
0
def test_valid_resolution_save(session):
    """Assert that a valid resolution can be saved."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    resolution = Resolution(
        resolution_date='2020-02-02',
        resolution_type='SPECIAL',
        business_id=business.id
    )
    resolution.save()
    assert resolution.id
コード例 #2
0
def test_find_resolution_by_id(session):
    """Assert that the method returns correct value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    resolution = Resolution(
        resolution_date='2020-02-02',
        resolution_type='SPECIAL',
        business_id=business.id
    )
    resolution.save()

    res = Resolution.find_by_id(resolution.id)

    assert res
    assert res.json == resolution.json
コード例 #3
0
    def get(identifier, resolution_id=None):
        """Return a JSON of the resolutions."""
        business = Business.find_by_identifier(identifier)

        if not business:
            return jsonify({'message':
                            f'{identifier} not found'}), HTTPStatus.NOT_FOUND

        # return the matching resolution
        if resolution_id:
            resolution, msg, code = ResolutionResource._get_resolution(
                business, resolution_id)
            return jsonify(resolution or msg), code

        resolution_list = []

        resolution_type = request.args.get('type')
        if resolution_type:
            resolutions = Resolution.find_by_type(business.id,
                                                  resolution_type.upper())
        else:
            resolutions = business.resolutions.all()

        for resolution in resolutions:
            resolution_json = resolution.json
            resolution_list.append(resolution_json)

        return jsonify(resolutions=resolution_list)
コード例 #4
0
ファイル: data_loader.py プロジェクト: severinbeauvais/lear
def add_business_resolutions(business: Business, resolutions_json: dict):
    """Create resolutions and add them to business."""
    for resolution_date in resolutions_json['resolutionDates']:
        resolution = Resolution(
            resolution_date=resolution_date,
            resolution_type=Resolution.ResolutionType.SPECIAL.value)
        business.resolutions.append(resolution)
コード例 #5
0
def test_resolution_json(session):
    """Assert the json format of resolution."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    resolution = Resolution(
        resolution_date='2020-02-02',
        resolution_type='SPECIAL',
        business_id=business.id
    )
    resolution.save()
    resolution_json = {
        'id': resolution.id,
        'type': resolution.resolution_type,
        'date': '2020-02-02'
    }
    assert resolution_json == resolution.json
コード例 #6
0
ファイル: shares.py プロジェクト: vysakh-menon-aot/lear
def update_share_structure(business: Business,
                           share_structure: Dict) -> Optional[List]:
    """Manage the share structure for a business.

    Assumption: The structure has already been validated, upon submission.

    Other errors are recorded and will be managed out of band.
    """
    if not business or not share_structure:
        # if nothing is passed in, we don't care and it's not an error
        return None

    err = []

    if resolution_dates := share_structure.get('resolutionDates'):
        for resolution_dt in resolution_dates:
            try:
                d = Resolution(
                    resolution_date=parse(resolution_dt).date(),
                    resolution_type=Resolution.ResolutionType.SPECIAL.value)
                business.resolutions.append(d)
            except (ValueError, OverflowError):
                err.append({
                    'error_code':
                    'FILER_INVALID_RESOLUTION_DATE',
                    'error_message':
                    f"Filer: invalid resolution date:'{resolution_dt}'"
                })
コード例 #7
0
    def _get_resolution(business, resolution_id=None):
        # find by ID
        resolution = None
        if resolution_id:
            rv = Resolution.find_by_id(resolution_id=resolution_id)
            if rv:
                resolution = {'resolution': rv.json}

        if not resolution:
            return None, {
                'message': f'{business.identifier} resolution not found'
            }, HTTPStatus.NOT_FOUND

        return resolution, None, HTTPStatus.OK
コード例 #8
0
def test_find_resolution_by_business_and_type(session):
    """Assert that the method returns correct value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    resolution_1 = Resolution(
        resolution_date='2020-02-02',
        resolution_type='ORDINARY',
        business_id=business.id
    )
    resolution_2 = Resolution(
        resolution_date='2020-03-03',
        resolution_type='SPECIAL',
        business_id=business.id
    )
    resolution_1.save()
    resolution_2.save()

    res = Resolution.find_by_type(business.id, 'SPECIAL')

    assert res
    assert len(res) == 1
    assert res[0].json == resolution_2.json
コード例 #9
0
def test_get_business_resolution_by_id(session, client, jwt):
    """Assert that business resolution is returned."""
    # setup
    identifier = 'CP7654321'
    business = factory_business(identifier)
    resolution_1 = Resolution(resolution_date='2020-02-02',
                              resolution_type='ORDINARY',
                              business_id=business.id)
    resolution_2 = Resolution(resolution_date='2020-03-03',
                              resolution_type='SPECIAL',
                              business_id=business.id)
    resolution_1.save()
    resolution_2.save()
    # test
    rv = client.get(
        f'/api/v1/businesses/{identifier}/resolutions/{resolution_1.id}',
        headers=create_header(jwt, [STAFF_ROLE], identifier))
    # check
    assert rv.status_code == HTTPStatus.OK
    assert rv.json['resolution']['date'] == '2020-02-02'