Exemplo n.º 1
0
def test_request_add_applicant_existing(app, request, session, applicant1,
                                        applicant2):

    # imports for just this test
    from namex.models import Applicant
    from namex.services.nro.request_utils import add_applicant

    # SETUP
    # create an NR and add an applicant
    nr = Request()
    nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    nr.applicants.append(Applicant(**applicant1))

    session.add(nr)
    session.commit()

    # Test
    # Call add_applicant and then assert the new NR applicant matches our data

    add_applicant(nr, applicant2)

    session.add(nr)
    session.commit()

    appl = nr.applicants.one_or_none()

    nra = dict_to_json_keys(applicant2)
    a = appl.as_dict()
    if a.get('partyId'): a.pop('partyId')

    # check entire dict
    assert nra == a
Exemplo n.º 2
0
def test_add_names_with_changes(app, request, session, previous_names,
                                test_names):

    # imports for just this test
    from namex.services.nro.request_utils import add_names

    # SETUP
    # create an NR
    nr = Request()
    nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    if previous_names:
        add_names(nr, previous_names)

    session.add(nr)
    session.commit()

    # Test
    add_names(nr, test_names)
    session.add(nr)
    session.commit()

    names = nr.names.all()

    assert len(test_names) == len(names)

    for name in names:
        name_found = False
        decision_data_intact = False
        for tn in test_names:
            if tn['name'] == name.name:
                name_found = True
                continue

        assert name_found
Exemplo n.º 3
0
def test_add_nwpta(app, request, session, pns):

    # imports for just this test
    from namex.services.nro.request_utils import add_nwpta

    # SETUP
    # create an NR
    nr = Request()
    nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    session.add(nr)
    session.commit()

    # Test
    add_nwpta(nr, pns)

    session.add(nr)
    session.commit()

    partners = nr.partnerNS.all()

    assert len(pns) == len(partners)

    for partner in partners:
        partner_found = False
        for p in pns:
            if p['partner_jurisdiction_type_cd'] == partner.partnerJurisdictionTypeCd:
                partner_found = True
                continue

        assert partner_found
Exemplo n.º 4
0
def test_datapump_nr_requires_consent_flag(app, mocker, consent_flag,
                                           state_cd):

    # create minimal NR to send to NRO
    nr = Request()
    nr.nrNum = 'NR 0000001'
    nr.stateCd = state_cd
    nr.consentFlag = consent_flag
    nr.lastUpdate = datetime(1970,
                             1,
                             1,
                             00,
                             00,
                             tzinfo=timezone('US/Pacific', ))

    # requires the username
    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    nr.activeUser = user

    # add name(s) to the NR - max 3
    for i in range(1, 4):
        name = Name()
        name.state = Name.APPROVED if i == 1 else Name.NOT_EXAMINED
        name.name = 'sample name {}'.format(i)
        name.choice = i
        name.decision_text = 'All good to go {}'.format(i)
        nr.names.append(name)

    # mock the oracle cursor
    oc = mocker.MagicMock()
    # make the real call
    nro_data_pump_update(nr, ora_cursor=oc, expires_days=60)

    oc.callfunc.assert_called_with(
        'NRO_DATAPUMP_PKG.name_examination_func',  # package.func_name
        str,
        [
            'NR 0000001',  # p_nr_number
            'A',  # p_status
            '19700302',  # p_expiry_date (length=8)
            'Y',  # p_consent_flag
            'bob',  # p_examiner_id (anything length <=7)
            'A****All good to go 1',  # p_choice1
            None,  # p_choice2
            None,  # p_choice3
            None,  # p_exam_comment
            '',  # p_add_info - not used in proc anymore
            None,  # p_confname1A
            None,  # p_confname1B
            None,  # p_confname1C
            None,  # p_confname2A
            None,  # p_confname2B
            None,  # p_confname2C
            None,  # p_confname3A
            None,  # p_confname3B
            None
        ])  # p_confname3C
Exemplo n.º 5
0
def test_datapump(app, mocker, start_date, expected_date):

    # create minimal NR to send to NRO
    nr = Request()
    nr.nrNum = 'NR 0000001'
    nr.stateCd = State.REJECTED
    nr.consentFlag = 'N'
    nr.lastUpdate = start_date

    # requires the username
    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    nr.activeUser = user

    # add name(s) to the NR - max 3
    for i in range(1, 4):
        name = Name()
        name.state = Name.REJECTED
        name.name = 'sample name {}'.format(i)
        name.choice = i
        name.decision_text = 'No Distinctive Term {}'.format(i)
        nr.names.append(name)

    # mock the oracle cursor
    oc = mocker.MagicMock()
    # make the real call
    nro_data_pump_update(nr, ora_cursor=oc, expires_days=56)

    oc.callfunc.assert_called_with(
        'NRO_DATAPUMP_PKG.name_examination_func',  # package.func_name
        str,
        [
            'NR 0000001',  # p_nr_number
            'R',  # p_status
            expected_date.strftime('%Y%m%d'),  # p_expiry_date (length=8)
            'N',  # p_consent_flag
            'bob',  # p_examiner_id (anything length <=7)
            'R****No Distinctive Term 1',  # p_choice1
            'R****No Distinctive Term 2',  # p_choice2
            'R****No Distinctive Term 3',  # p_choice3
            None,  # p_exam_comment
            '',  # p_add_info - not used in proc anymore
            None,  # p_confname1A
            None,  # p_confname1B
            None,  # p_confname1C
            None,  # p_confname2A
            None,  # p_confname2B
            None,  # p_confname2C
            None,  # p_confname3A
            None,  # p_confname3B
            None
        ])  # p_confname3C
Exemplo n.º 6
0
def test_add_names_after_reset(app, request, session, previous_names,
                               test_names, expected_states):

    # imports for just this test
    from namex.services.nro.request_utils import add_names

    # SETUP
    # create an NR
    nr = Request()
    nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    if previous_names:
        add_names(nr, previous_names)

    nr.hasBeenReset = True

    session.add(nr)
    session.commit()

    # Test
    add_names(nr, test_names)
    session.add(nr)
    session.commit()

    names = nr.names.all()

    assert len(test_names) == len(names)

    for name in names:
        name_found = False
        decision_data_intact = False
        for tn in test_names:
            if tn['name'] == name.name:
                name_found = True
                if name.state == expected_states[tn['choice_number'] - 1]:
                    decision_data_intact = True
                continue

        assert name_found
        assert decision_data_intact
Exemplo n.º 7
0
def test_add_comments(app, request, session, test_comments, test_size,
                      should_have_existing_comments):

    # imports for just this test
    from namex.services.nro.request_utils import add_comments

    # SETUP
    # create an NR
    nr = Request()
    nr.activeUser = User('idir/bob', 'bob', 'last', 'idir', 'localhost')

    if should_have_existing_comments:
        add_comments(nr, test_comments)

    session.add(nr)
    session.commit()

    # Test
    add_comments(nr, test_comments)

    session.add(nr)
    session.commit()

    comments = nr.comments.all()

    assert test_size == len(comments)

    for com in comments:
        comment_found = False
        for tc in test_comments:
            if tc['examiner_comment'] == com.comment:
                comment_found = True
                continue

        assert comment_found
        assert EPOCH_DATETIME == com.timestamp.replace(tzinfo=None)