Exemplo n.º 1
0
def test_get_temp_business_filing(session, client, jwt):
    """Assert that the business info cannot be received in a valid JSONSchema format."""
    #
    # setup
    identifier = 'Tb31yQIuBw'
    filing_name = 'incorporationApplication'
    temp_reg = RegistrationBootstrap()
    temp_reg._identifier = identifier
    temp_reg.save()
    json_data = copy.deepcopy(FILING_HEADER)
    json_data['filing']['header']['name'] = filing_name
    json_data['filing'][filing_name] = copy.deepcopy(INCORPORATION)
    filings = factory_pending_filing(None, json_data)
    filings.temp_reg = identifier
    filings.save()

    #
    # test
    rv = client.get(f'/api/v2/businesses/{identifier}/filings',
                    headers=create_header(jwt, [STAFF_ROLE], identifier))

    #
    # validate
    assert rv.status_code == HTTPStatus.OK
    assert rv.json['filing']['header']['name'] == filing_name
    assert rv.json['filing'][filing_name] == INCORPORATION
Exemplo n.º 2
0
def test_create_bootstrap_registrations(session):
    """Assert the service creates registrations."""
    identifier_base = 'Tabc123'

    for i in range(5):
        r = RegistrationBootstrap(identifier=identifier_base + str(i),
                                  account=12)
        r.save()
    assert r.identifier == identifier_base + str(4)
Exemplo n.º 3
0
def test_only_one_registration_bootstrap(session):
    """Assert that the identifier cannot be used more than once."""
    identifier = 'Tabc123'

    r = RegistrationBootstrap(identifier=identifier, account=12)
    r.save()

    with pytest.raises(FlushError):
        p = RegistrationBootstrap(identifier=identifier, account=12)
        p.save()
Exemplo n.º 4
0
    def create_bootstrap(account: int) -> Union[Dict, RegistrationBootstrap]:
        """Return either a new bootstrap registration or an error struct."""
        if not account:
            return {'error': babel('An account number must be provided.')}

        bootstrap = RegistrationBootstrap(account=account)
        allowed_encoded = string.ascii_letters + string.digits

        # try to create a bootstrap registration with a unique ID
        for _ in range(5):
            bootstrap.identifier = 'T' + ''.join(secrets.choice(allowed_encoded) for _ in range(9))
            try:
                bootstrap.save()
                return bootstrap
            except FlushError:
                pass  # we try again
            except Exception:
                break

        return {'error': babel('Unable to create bootstrap registration.')}