Esempio n. 1
0
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.'
Esempio n. 2
0
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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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.'
Esempio n. 7
0
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