def test_valid_share_series_save(session):
    """Assert that a valid share series can be saved."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_series_1 = ShareSeries(name='Share Series 1',
                                 priority=1,
                                 max_share_flag=True,
                                 max_shares=500,
                                 special_rights_flag=False)
    share_series_2 = ShareSeries(name='Share Series 2',
                                 priority=2,
                                 max_share_flag=True,
                                 max_shares=1000,
                                 special_rights_flag=False)
    share_class.series.append(share_series_1)
    share_class.series.append(share_series_2)
    share_class.save()
    assert share_series_1.id
    assert share_series_2.id
def test_validate_share_quantity_not_exceed_class_value(session):
    """Assert that model validates share series share quantity."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_series_1 = ShareSeries(name='Share Series 1',
                                 priority=1,
                                 max_share_flag=True,
                                 max_shares=1500,
                                 special_rights_flag=False)
    share_class.series.append(share_series_1)

    with pytest.raises(BusinessException) as share_class_error:
        share_class.save()
    session.rollback()

    assert share_class_error
    assert share_class_error.value.status_code == HTTPStatus.BAD_REQUEST
    assert share_class_error.value.error == \
        f'The max share quantity of {share_series_1.name} must be <= that of share class quantity.'
Example #3
0
def test_share_class_json(session):
    """Assert the json format of share class."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_class.save()
    share_class_json = {
        'id': share_class.id,
        'name': share_class.name,
        'priority': share_class.priority,
        'hasMaximumShares': share_class.max_share_flag,
        'maxNumberOfShares': share_class.max_shares,
        'hasParValue': share_class.par_value_flag,
        'parValue': share_class.par_value,
        'currency': share_class.currency,
        'hasRightsOrRestrictions': share_class.special_rights_flag,
        'series': []
    }
    assert share_class_json == share_class.json
Example #4
0
def test_find_by_share_class_id(session):
    """Assert that the method returns correct value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=0.875,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_class.save()

    res = ShareClass.find_by_share_class_id(share_class.id)

    assert res
    assert res.json == share_class.json
Example #5
0
def factory_share_class(business_identifier: str):
    """Create a share class."""
    business = factory_business(business_identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_series_1 = ShareSeries(name='Share Series 1',
                                 priority=1,
                                 max_share_flag=True,
                                 max_shares=500,
                                 special_rights_flag=False)
    share_class.series.append(share_series_1)
    share_class.save()
    return share_class
Example #6
0
def test_invalid_par_value(session):
    """Assert that model validates share class par value."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=True,
                             max_shares=1000,
                             par_value_flag=True,
                             par_value=None,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    with pytest.raises(BusinessException) as share_class_error:
        share_class.save()
    session.rollback()

    assert share_class_error
    assert share_class_error.value.status_code == HTTPStatus.BAD_REQUEST
    assert share_class_error.value.error == f'The share class {share_class.name} must specify par value.'
def test_share_quantity_when_no_max_share_for_parent(session):
    """Assert that model validates share series share quantity."""
    identifier = 'CP1234567'
    business = factory_business(identifier)
    share_class = ShareClass(name='Share Class 1',
                             priority=1,
                             max_share_flag=False,
                             max_shares=None,
                             par_value_flag=True,
                             par_value=0.852,
                             currency='CAD',
                             special_rights_flag=False,
                             business_id=business.id)
    share_series_1 = ShareSeries(name='Share Series 1',
                                 priority=1,
                                 max_share_flag=True,
                                 max_shares=1500,
                                 special_rights_flag=False)
    share_class.series.append(share_series_1)
    share_class.save()
    assert share_series_1.id
    def _get_share_class(business, share_class_id=None):
        # find by ID
        share_class = None
        if share_class_id:
            rv = ShareClass.find_by_share_class_id(share_class_id)
            if rv:
                share_class = {'shareClass': rv.json}

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

        return share_class, None, HTTPStatus.OK
Example #9
0
def create_share_class(share_class_info: dict) -> ShareClass:
    """Create a new share class and associated series."""
    share_class = ShareClass(
        name=share_class_info['name'],
        priority=share_class_info['priority'],
        max_share_flag=share_class_info['hasMaximumShares'],
        max_shares=share_class_info.get('maxNumberOfShares', None),
        par_value_flag=share_class_info['hasParValue'],
        par_value=share_class_info.get('parValue', None),
        currency=share_class_info.get('currency', None),
        special_rights_flag=share_class_info['hasRightsOrRestrictions'])
    share_class.series = []
    for series in share_class_info['series']:
        share_series = ShareSeries(
            name=series['name'],
            priority=series['priority'],
            max_share_flag=series['hasMaximumShares'],
            max_shares=series.get('maxNumberOfShares', None),
            special_rights_flag=series['hasRightsOrRestrictions'])
        share_class.series.append(share_series)

    return share_class
Example #10
0
def test_manage_share_structure__delete_shares(app, session):
    """Assert that the share structures are deleted."""
    from legal_api.models import ShareClass, ShareSeries

    # setup
    business = Business()
    for i in range(5):
        share_class = ShareClass(name=f'share class {i}')
        for j in range(5):
            share_series = ShareSeries(name=f'share series {j}')
            share_class.series.append(share_series)
        business.share_classes.append(share_class)
    business.save()
    business_id = business.id

    # test
    shares.delete_existing_shares(business)
    business.save()

    # check
    check_business = Business.find_by_internal_id(business_id)
    share_classes = check_business.share_classes.all()

    assert not share_classes