Esempio n. 1
0
def test_update_nro_request_state_to_approved(app):
    """
    Code should not allow us to set state to anything except Draft
    """
    con = nro.connection
    cursor = con.cursor()

    eid = _get_event_id(cursor)

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    fake_request = FakeRequest()
    fake_request.requestId = 884047
    fake_request.stateCd = 'APPROVED'
    fake_request.activeUser = user

    _update_nro_request_state(cursor, fake_request, eid,
                              {'is_changed__request_state': True})

    cursor.execute(
        "select state_type_cd from request_state where request_id = {} and start_event_id = {}"
        .format(fake_request.requestId, eid))
    resultset = cursor.fetchone()

    assert resultset is None
def test_update_nro_add_new_name_choice(app):
    """
    Ensure name can be changed, or removed.
    """
    con = nro.connection
    cursor = con.cursor()

    eid = _get_event_id(cursor)

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    fake_request = FakeRequest()
    fake_name1 = FakeName()
    fake_name2 = FakeName()

    fake_name1.choice = 1
    fake_name2.choice = 2
    # Add a second name choice:
    fake_name1.name = "Fake name"
    fake_name2.name = 'Second fake name'
    names = NamesList()
    names.addNames([fake_name1, fake_name2])
    fake_request.names = names

    fake_request.requestId = 884047
    fake_request.stateCd = 'INPROGRESS'
    fake_request.activeUser = user

    change_flags = {
        'is_changed__name1': False,
        'is_changed__name2': True,
        'is_changed__name3': False,
    }

    # Fail if our test data is not still valid:
    cursor.execute("""
        select ni.name
        from name n, name_instance ni
        where  ni.name_id = n.name_id 
        and n.request_id = {} 
        and ni.end_event_id is null """
                   .format(fake_request.requestId))
    result = list(cursor.fetchall())
    assert len(result) == 1

    _update_nro_names(cursor, fake_request, eid, change_flags)

    cursor.execute("""
        select ni.name
        from name n, name_instance ni
        where  ni.name_id = n.name_id 
        and n.request_id = {} 
        and ni.end_event_id is null """
                   .format(fake_request.requestId))
    result = list(cursor.fetchall())

    assert result
    assert len(result) == 2
    assert result[0][0] != 'Fake name'
def test_update_nro_nwpta_sk(app):
    """
    Ensure the changed ab nwpta data is updated in nro
    """
    con = nro.connection
    cursor = con.cursor()

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

   #Set upo request
    cursor.execute("insert into request(request_id, nr_num) values(42, 'NR XXXXXXX')")

    #tds that it is valid
    cursor.execute("select nr_num from request where request_id = 42")
    (nr_num,) = cursor.fetchone()
    assert nr_num == 'NR XXXXXXX'

    eid = _get_event_id(cursor)

    # Setup Base AB record
    cursor.execute("""insert into partner_name_system
                        (partner_name_system_id, request_id, start_event_id,PARTNER_NAME_TYPE_CD, PARTNER_JURISDICTION_TYPE_CD) 
                  values(partner_name_system_seq.nextval, 42, :event, 'CO', 'SK')""",event=eid)

    # test AB
    change_flags = {
        'is_changed__nwpta_ab': False,
        'is_changed__nwpta_sk': True,

    }

    fake_request = FakeRequestNwpta()
    fake_nwpta_sk = FakeNwpta_SK()
    nwpta = PartnerList()
    nwpta.addPartnerNS([fake_nwpta_sk])
    fake_request.partnerNS = nwpta
    _update_nro_partner_name_system(cursor, fake_request, eid, change_flags)

    cursor.execute("""
           select pns.*
           from partner_name_system pns
           where  pns.partner_jurisdiction_type_cd = 'SK' 
           and pns.request_id = {} 
           and pns.partner_name_type_cd = 'AS'
           and pns.end_event_id is null"""
                   .format(fake_request.requestId))

    result = list(cursor.fetchall())

    assert len(result) == 1
    assert result[0][4] == 'AS'
    assert result[0][8] == 'ASSUMED COMPANY NAME-SK'
def test_create_nro_transaction_with_type(app):
    con = nro.connection
    cursor = con.cursor()

    eid = _get_event_id(cursor)

    fake_request = FakeRequest()
    fake_request.requestId = 884047

    _create_nro_transaction(cursor, fake_request, eid, 'CORRT')

    cursor.execute("select event_id, transaction_type_cd from transaction where request_id = {} order by event_id desc".format(fake_request.requestId))
    (value, transaction_type_cd) = cursor.fetchone()

    assert eid == value
    assert transaction_type_cd == 'CORRT'
def test_update_nro_request_state_to_draft(app):
    con = nro.connection
    cursor = con.cursor()

    eid = _get_event_id(cursor)

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    fake_request = FakeRequest()
    fake_request.requestId = 884047
    fake_request.stateCd = 'DRAFT'
    fake_request.activeUser = user

    _update_nro_request_state(cursor, fake_request, eid, {'is_changed__request_state': True})

    cursor.execute("select state_type_cd from request_state where request_id = {} and start_event_id = {}"
                   .format(fake_request.requestId, eid))
    (state_type_cd,) = cursor.fetchone()

    assert state_type_cd == 'D'
Esempio n. 6
0
    def cancel_nr(self, nr, examiner_username):
        """Sets the status of the Request in NRO to "C" (Cancelled)

        :param nr: (obj) NR Object
        :param examiner_username: (str) any valid string will work, but it should be the username from Keycloak
        :return: naked
        :raise: (NROServicesError) with the error information set
        """

        try:
            con = self.connection
            con.begin(
            )  # explicit transaction in case we need to do other things than just call the stored proc
            try:
                cursor = con.cursor()

                event_id = _get_event_id(cursor)
                current_app.logger.debug('got to cancel_nr() for NR:{}'.format(
                    nr.nrNum))
                current_app.logger.debug('event ID for NR:{}'.format(event_id))
                _create_nro_transaction(cursor, nr, event_id, 'CANCL')

                # get request_state record, with all fields
                cursor.execute("""
                SELECT *
                FROM request_state
                WHERE request_id = :request_id
                AND end_event_id IS NULL
                FOR UPDATE
                """,
                               request_id=nr.requestId)
                row = cursor.fetchone()
                req_state_id = int(row[0])

                # set the end event for the existing record
                cursor.execute("""
                UPDATE request_state
                SET end_event_id = :event_id
                WHERE request_state_id = :req_state_id
                """,
                               event_id=event_id,
                               req_state_id=req_state_id)

                # create new request_state record
                cursor.execute(
                    """
                INSERT INTO request_state (request_state_id, request_id, state_type_cd, 
                    start_event_id, end_event_id, examiner_idir, examiner_comment, state_comment, 
                    batch_id)
                VALUES (request_state_seq.nextval, :request_id, :state, :event_id, NULL, 
                          :examiner_id, NULL, NULL, NULL)
                """,
                    request_id=nr.requestId,
                    state='C',
                    event_id=event_id,
                    examiner_id=nro_examiner_name(examiner_username))

                con.commit()

            except cx_Oracle.DatabaseError as exc:
                err, = exc.args
                current_app.logger.error(err)
                if con:
                    con.rollback()
                raise NROServicesError(
                    {
                        "code": "unable_to_set_state",
                        "description":
                        "Unable to set the state of the NR in NRO"
                    }, 500)
            except Exception as err:
                current_app.logger.error(err.with_traceback(None))
                if con:
                    con.rollback()
                raise NROServicesError(
                    {
                        "code": "unable_to_set_state",
                        "description":
                        "Unable to set the state of the NR in NRO"
                    }, 500)

        except Exception as err:
            # something went wrong, roll it all back
            current_app.logger.error(err.with_traceback(None))
            if con:
                con.rollback()
            raise NROServicesError(
                {
                    "code": "unable_to_set_state",
                    "description": "Unable to set the state of the NR in NRO"
                }, 500)

        return None
Esempio n. 7
0
def new_nr(nr, ora_cursor, con):
    """Add the Name Request in NRO
    :raises Exception: what ever error we get, let our caller handle, this is here in case we want to wrap it - future
    """

    nr_num_list = _generate_nr_num(ora_cursor)
    nr_num = nr_num_list.values[0]
    # Set postgres to real NR #
    nr.nrNum = nr_num

    #set the oracle version of the priority code
    priority = None
    if nr.priorityCd == 'Y':
        priority = 'PQ'
    else:
        priority = 'RQ'

    request_id = _create_request(ora_cursor, nr_num)
    nr.requestId = request_id
    current_app.logger.debug('got to new_nr() for NR:{}'.format(nr_num))

    eid = _get_event_id(ora_cursor)
    current_app.logger.debug('event ID for NR:{1}. event id:{0}'.format(
        eid, nr_num))

    nr.requestId = request_id
    _create_nro_transaction(ora_cursor, nr, eid, transaction_type='NRREQ')
    con.commit()
    current_app.logger.debug(
        'Created the transaction for new_nr() for NR:{}'.format(nr_num))

    _create_request_instance(ora_cursor, nr, eid, priority)
    con.commit()
    applicantInfo = nr.applicants.one_or_none()
    if not applicantInfo:
        current_app.logger.error("Error on getting applicant info.")
        return jsonify({"Message": "No applicant info"}), 404

    _create_request_party(ora_cursor, applicantInfo, eid,
                          request_id)  #includes address
    con.commit()
    current_app.logger.debug(
        'Created Request Party and Address in new_nr() for NR:{}'.format(
            nr_num))

    _create_request_state(ora_cursor, 'D', eid, request_id)
    con.commit()

    _create_names(ora_cursor, nr, eid)  #name, name_instace and name state
    con.commit()
    current_app.logger.debug(
        'Created Names in new_nr() for NR:{}'.format(nr_num))

    # for completed NRs waiting for the updater set the state to H so no one can change it in NRO
    # for Name request Rserved and conditionally Reersved NRs.
    if nr.stateCd in [State.RESERVED, State.COND_RESERVE]:
        eid = _get_event_id(ora_cursor)
        set_request_on_hold(ora_cursor, request_id, eid)
        con.commit()
        current_app.logger.debug(
            'Set State to ONHOLD for Updater to Run in new_nr() for NR:{}'.
            format(nr_num))

    current_app.logger.debug(
        'got to the end of new_nr() for NR:{}'.format(nr_num))