Exemplo n.º 1
0
def test_business_find_by_legal_name_not_exist(session):
    """Assert that the business isn't found for a non-existent name."""
    identifier = 'CP1234567'
    legal_name = 'legal name'
    b = services.Business()
    b.identifier = identifier
    b.legal_name = legal_name
    b.founding_date = datetime.utcfromtimestamp(0)
    b.save()

    b = services.Business().find_by_legal_name('not found')
    assert b is None
Exemplo n.º 2
0
def test_business_find_by_legal_name_pass(session):
    """Assert that the business can be found by name."""
    identifier = 'CP1234567'
    legal_name = 'legal name'
    b = services.Business()
    b.identifier = identifier
    b.legal_name = legal_name
    b.founding_date = datetime.utcfromtimestamp(0)
    b.save()

    b = services.Business().find_by_legal_name(legal_name)
    assert b is not None
Exemplo n.º 3
0
def test_business_identifier_valid():
    """Assert that the identifier is valid."""
    identifier = 'CP1234567'
    business = services.Business()
    business.identifier = identifier

    assert identifier == business.identifier
Exemplo n.º 4
0
def test_business_identifier_invalid():
    """Assert that an invalid identifier throws a BusinessException."""
    from legal_api.exceptions import BusinessException
    identifier = 'invalid'
    business = services.Business()

    with pytest.raises(BusinessException) as excinfo:
        business.identifier = identifier

    assert excinfo.value.status_code == 406
    assert excinfo.value.error == 'invalid-identifier-format'
Exemplo n.º 5
0
def test_business_saved_from_new(session):
    """Assert that the business is saved to the cache."""
    identifier = 'CP1234567'
    b = services.Business()
    b.identifier = identifier
    b.legal_name = 'legal name'
    b.founding_date = datetime.utcfromtimestamp(0)
    b.save()

    business = services.Business.find_by_identifier(identifier)

    assert business is not None
Exemplo n.º 6
0
def test_business_cant_find_disolved_business(session):
    """Assert that the business can not be found, once it is disolved."""
    identifier = 'CP1234567'
    b = services.Business()
    b.legal_name = 'legal name'
    b.founding_date = datetime.utcfromtimestamp(0)
    b.dissolution_date = datetime.utcfromtimestamp(0)
    b.identifier = identifier
    b.save()

    # business is disolved, it should not be found by name search
    b = services.Business.find_by_identifier(identifier)
    assert b is None
Exemplo n.º 7
0
def test_business_find_by_legal_name_missing(session):
    """Assert that the business can be found by name."""
    identifier = 'CP1234567'
    b = services.Business()
    b.legal_name = 'legal name'
    b.founding_date = datetime.utcfromtimestamp(0)
    b.dissolution_date = None
    b.identifier = identifier
    b.tax_id = '123456789'
    b.fiscal_year_end_date = datetime(2001, 8, 5, 7, 7, 58, 272362)
    b.save()

    business = services.Business.find_by_legal_name()
    assert business is None
Exemplo n.º 8
0
def test_as_dict():
    """Assert that the Business is rendered correctly as a dict."""
    business = services.Business()
    business.legal_name = 'legal_name'
    business.identifier = 'CP1234567'
    business.founding_date = datetime.utcfromtimestamp(0)

    assert business.asdict() == {
        'legal_name': 'legal_name',
        'identifier': 'CP1234567',
        'founding_date': datetime.utcfromtimestamp(0).isoformat()
    }

    business.dissolution_date = datetime.utcfromtimestamp(0)
    assert business.asdict() == {
        'legal_name': 'legal_name',
        'identifier': 'CP1234567',
        'founding_date': datetime.utcfromtimestamp(0).isoformat(),
        'dissolution_date': datetime.utcfromtimestamp(0).isoformat()
    }
    business.dissolution_date = None

    business.fiscal_year_end_date = datetime.utcfromtimestamp(0)
    assert business.asdict() == {
        'legal_name': 'legal_name',
        'identifier': 'CP1234567',
        'founding_date': datetime.utcfromtimestamp(0).isoformat(),
        'fiscal_year_end_date': datetime.utcfromtimestamp(0).isoformat()
    }
    business.fiscal_year_end_date = None

    business.tax_id = '12345'
    assert business.asdict() == {
        'legal_name': 'legal_name',
        'identifier': 'CP1234567',
        'founding_date': datetime.utcfromtimestamp(0).isoformat(),
        'tax_id': '12345'
    }
    business.tax_id = None