コード例 #1
0
def test_get_staff_comment_event_history(client, jwt, app):
    from namex.models import Comment, Event, State, User
    from namex.services import EventRecorder
    from namex.utils.common import convert_to_ascii

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.DRAFT
    nr.save_to_db()
    EventRecorder.record(user, Event.POST + ' [payment completed] CREATE', nr,
                         nr.json())

    comment_instance = Comment()
    comment_instance.examinerId = user.id
    comment_instance.nrId = nr.id
    comment_instance.comment = convert_to_ascii('test staff comment')
    comment_instance.save_to_db()

    EventRecorder.record(user, Event.POST, nr,
                         {'comment': 'test staff comment'})

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Staff Comment"' in rv.data
    assert b'"comment": "test staff comment"' in rv.data
コード例 #2
0
def test_get_next_event_history(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.DRAFT
    nr.save_to_db()
    EventRecorder.record(user, Event.POST + ' [payment completed] CREATE', nr,
                         nr.json())

    nr.stateCd = State.INPROGRESS
    nr.save_to_db()
    EventRecorder.record(user, Event.GET, nr, {})

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Get Next NR"' in rv.data
コード例 #3
0
def test_get_queued_oldest_multirow(client, app):

    # add NR to database
    from namex.models import Request as RequestDAO, State, User
    nr_first = RequestDAO()
    nr_first.nrNum = 'NR 0000001'
    nr_first.stateCd = State.DRAFT
    nr_first.save_to_db()

    for i in range(2, 12):
        nr = RequestDAO()
        nr.nrNum = 'NR {0:07d}'.format(i)
        nr.stateCd = State.DRAFT
        nr.save_to_db()

    user = User(username='******',
                firstname='first',
                lastname='last',
                sub='idir/funcmunk',
                iss='keycloak')
    user.save_to_db()

    nr_oldest, new_req = RequestDAO.get_queued_oldest(user)

    # Tests ####
    assert nr_first.nrNum == nr_oldest.nrNum
    assert nr_oldest.json()
コード例 #4
0
ファイル: test_events.py プロジェクト: stevenc987/namex
def test_get_inprogress_event_history(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    token = jwt.create_jwt(claims, token_header)
    headers = {
        'Authorization': 'Bearer ' + token,
        'content-type': 'application/json'
    }

    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.INPROGRESS
    nr.requestId = 1460775
    nr._source = 'NRO'
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'TEST NAME ONE'
    nr.names = [name1]
    nr.save_to_db()

    EventRecorder.record(user, Event.PATCH, nr, {})

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Load NR"' in rv.data
コード例 #5
0
ファイル: common.py プロジェクト: stevenc987/namex
def save_auto_approved_names(approved_number_records):
    from namex.models import Event as EventDAO, Request as RequestDAO, User as UserDAO, State
    num = 0
    global num_records

    username = '******'
    usr = UserDAO(username, '', '', '', '')
    usr.id = 86

    usr.save_to_db()
    while approved_number_records > num:
        nr_num_label = 'NR 00'
        num_records += 1
        num += 1
        nr_num = nr_num_label + str(num_records)

        nr = RequestDAO()
        nr.nrNum = nr_num
        nr.stateCd = State.APPROVED
        nr._source = 'NAMEREQUEST'

        event = EventDAO()
        event.action = EventAction.PUT.value
        event.userId = EventUserId.SERVICE_ACCOUNT.value
        event.stateCd = State.APPROVED
        event.eventDate = datetime.date.today()
        nr.events = [event]
        nr.save_to_db()
コード例 #6
0
def test_reopen_event_history(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    headers = create_header(jwt, [User.EDITOR])

    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.REJECTED
    nr.requestId = 1460775
    nr._source = 'NRO'
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'TEST NAME ONE'
    nr.names = [name1]
    nr.save_to_db()

    EventRecorder.record(user, Event.PATCH, nr, {})

    nr.stateCd = State.INPROGRESS
    EventRecorder.record(user, Event.PUT, nr, {
        "additional": "additional",
        "furnished": "N"
    })

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Re-Open"' in rv.data
コード例 #7
0
def add_test_user_to_db():
    user = User(username='******',
                firstname='Test',
                lastname='User',
                sub='idir/name_request_service_account',
                iss='keycloak')
    user.save_to_db()

    return user
コード例 #8
0
ファイル: test_user.py プロジェクト: lekshmimallika-aot/namex
def test_get_service_account_user(session, client):
    """Assert service account user."""
    # add a user for the comment
    user = User('nro_service_account', '', '', '8ca7d47a-024e-4c85-a367-57c9c93de1cd',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    service_account = User.get_service_account_user()

    assert service_account.username == user.username
コード例 #9
0
def test_add_new_comment_to_nr(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, Comment as CommentDAO, User, \
    Event as EventDAO
    from sqlalchemy import desc

    #add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.INPROGRESS
    nr.requestId = 1460775
    nr._source = 'NRO'
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'TEST NAME ONE'
    nr.names = [name1]
    nr.save_to_db()

    comment1 = CommentDAO()
    comment1.comment = 'This is the first Comment'
    comment1.nr_id = nr.id
    comment1.examinerId = nr.userId
    nr.comments = [comment1]
    nr.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    token = jwt.create_jwt(claims, token_header)
    headers = {
        'Authorization': 'Bearer ' + token,
        'content-type': 'application/json'
    }

    # get the resource so we have a template for the request:
    rv = client.get('/api/v1/requests/NR%200000002', headers=headers)
    assert rv.status_code == 200
    # assert we're starting with just one name:
    data = json.loads(rv.data)
    assert len(data['comments']) == 1

    new_comment = {"comment": "The 13th comment entered by the user."}

    rv = client.post('/api/v1/requests/NR%200000002/comments',
                     data=json.dumps(new_comment),
                     headers=headers)

    assert b'"comment": "The 13th comment entered by the user."' in rv.data
    assert 200 == rv.status_code

    event_results = EventDAO.query.filter_by(nrId=nr.id).order_by(
        EventDAO.eventDate.desc()).first_or_404()
    assert event_results.action == 'post'
    assert event_results.eventJson[0:11] == '{"comment":'
コード例 #10
0
def test_fetch_nro_request_and_copy_to_namex_request_with_nr(app, session, nr_num, expected_nr_num):

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    user.save_to_db()
    nr = Request()
    nr.nrNum = nr_num
    nr.userId = user.id
    nr.save_to_db()

    nr = nro.fetch_nro_request_and_copy_to_namex_request(user, nr_number=12, name_request=nr)

    assert expected_nr_num == None if (expected_nr_num is None) else nr.nrNum
コード例 #11
0
def test_get_queued_empty_queue(client, app):

    # SETUP #####
    # add NR to database
    from namex.models import Request as RequestDAO, User
    from namex.exceptions import BusinessException

    user = User(username='******', firstname='first', lastname='last', sub='idir/funcmunk', iss='keycloak')
    user.save_to_db()

    with pytest.raises(BusinessException) as e_info:
        nr_oldest, new_req = RequestDAO.get_queued_oldest(user)
コード例 #12
0
def test_event_create_nrl(client, jwt, app):

    #add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'url')
    user.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()

    before_record_date = datetime.utcnow()
    EventRecorder.record(user, Event.POST, nr, nr.json())

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200
    assert rv.data
    response = json.loads(rv.data)
    assert response['transactions']
    assert len(response['transactions']) == 1
    assert response['transactions'][0]['additionalInfo'] == 'test'
    assert response['transactions'][0]['consent_dt'] == None
    assert response['transactions'][0]['consentFlag'] == None
    assert response['transactions'][0][
        'eventDate'] > before_record_date.isoformat()
    assert response['transactions'][0]['expirationDate'] == None
    assert response['transactions'][0]['names'] == [{
        'choice': 1,
        'comment': None,
        'conflict1': '',
        'conflict1_num': '',
        'conflict2': '',
        'conflict2_num': '',
        'conflict3': '',
        'conflict3_num': '',
        'consumptionDate': None,
        'corpNum': None,
        'decision_text': '',
        'designation': None,
        'id': 1,
        'name': 'TEST NAME ONE',
        'name_type_cd': None,
        'state': 'NE'
    }]
    assert response['transactions'][0]['priorityCd'] == None
    assert response['transactions'][0]['requestTypeCd'] == 'CR'
    assert response['transactions'][0]['request_action_cd'] == 'NEW'
    assert response['transactions'][0]['stateCd'] == State.PENDING_PAYMENT
    assert response['transactions'][0]['user_action'] == 'Created NRL'
    assert response['transactions'][0]['user_name'] == 'test-user'
コード例 #13
0
ファイル: test_job.py プロジェクト: vysakh-menon-aot/namex
def helper_create_requests(row_data):

    user = User('automation', 'automation', 'automation', 'internal',
                'localhost')
    user.save_to_db()

    for row in row_data:
        if row['nr_num']:
            nr = Request()
            nr.nrNum = row['nr_num']
            nr.stateCd = row['state']
            nr.userId = user.id
            nr.save_to_db()
コード例 #14
0
def test_move_control_of_existing_request_from_nro_missing_nr(app, session):

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    user.save_to_db()
    nr = Request()
    nr.nrNum = 'NR 9999999'
    nr.stateCd = State.INPROGRESS
    nr.nroLastUpdate = EPOCH_DATETIME
    nr.userId = user.id
    nr.save_to_db()

    warnings = nro.move_control_of_request_from_nro(nr, user)

    assert warnings is not None
コード例 #15
0
def test_comment_where_no_nr(client, jwt, app):
    from namex.models import User
    #add a user for the comment
    user = User('test-user','','','43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc','https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    token = jwt.create_jwt(claims, token_header)
    headers = {'Authorization': 'Bearer ' + token, 'content-type': 'application/json'}

    new_comment = {"comment": "The 13th comment entered by the user."}

    rv = client.post('/api/v1/requests/NR%200000002/comments', data=json.dumps(new_comment), headers=headers)
    assert 404 == rv.status_code
コード例 #16
0
def test_move_control_of_request_from_nro(app, session, nr_num, expected_nr_num):

    user = User('idir/bob', 'bob', 'last', 'idir', 'localhost')
    user.save_to_db()
    nr = Request()
    nr.nrNum = nr_num
    nr.stateCd = State.INPROGRESS
    nr.nroLastUpdate = EPOCH_DATETIME
    nr.userId = user.id
    nr.save_to_db()

    warnings = nro.move_control_of_request_from_nro(nr, user)

    assert expected_nr_num == None if (expected_nr_num is None) else nr.nrNum
    assert warnings is None
コード例 #17
0
def helper_create_requests(row_data):

    user = User('automation', 'automation', 'automation', 'internal',
                'localhost')
    user.save_to_db()

    for row in row_data:
        print('inserting nr:{}'.format(row['nr_num']))
        if row['nr_num']:
            nr = Request()
            nr.nrNum = row['nr_num']
            nr.stateCd = row['state']
            nr.lastUpdate = row['last_update']
            nr.userId = user.id
            nr.save_to_db()
コード例 #18
0
def test_get_queued_oldest(client, app):

    # SETUP #####
    # add NR to database
    from namex.models import Request as RequestDAO, State, User
    nr = RequestDAO()
    nr.nrNum='NR 0000001'
    nr.stateCd = State.DRAFT
    nr.save_to_db()

    user = User(username='******', firstname='first', lastname='last', sub='idir/funcmunk', iss='keycloak')
    user.save_to_db()

    nr_oldest, new_req = RequestDAO.get_queued_oldest(user)

    # Tests ####
    assert nr.nrNum == nr_oldest.nrNum
コード例 #19
0
def test_add_clean_name_to_nr(client, jwt, app):
    # add NR to database
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event as EventDAO
    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    user_id = user.id

    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.INPROGRESS
    nr.requestId = 1460775
    nr.userId = user_id
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'B,S&J ENTERPRISES LTD.'
    name1.state = State.APPROVED
    nr.names = [name1]
    nr.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    token = jwt.create_jwt(claims, token_header)
    headers = {
        'Authorization': 'Bearer ' + token,
        'content-type': 'application/json'
    }

    rv = client.put('/api/v1/requests/NR%200000002/names/1',
                    data=json.dumps(name1.as_dict()),
                    headers=headers)
    assert rv.status_code == 200

    event_results = EventDAO.query.filter_by(nrId=nr.id).order_by(
        EventDAO.eventDate.desc()).first_or_404()
    assert event_results.action == 'put'

    test_string = event_results.eventJson
    test_dict = json.loads(test_string)

    assert 'BSJ ENTERPRISES' == test_dict['clean_name']
コード例 #20
0
def test_get_existing_user_settings(client, jwt, app):
    """Test getting user settings for an existing user."""
    user = User(
        username='******',
        sub='43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',  # this needs to match the sub in create_header
        firstname='',
        lastname='',
        iss=''
    )
    user.searchColumns = 'Status'
    user.save_to_db()

    # check it gets the existing settings stored in the db
    existing_user_settings = client.get(f'api/v1/usersettings', headers=create_header(jwt, [User.EDITOR], 'test-settings'))
    data = existing_user_settings.data
    assert data
    resp = json.loads(data.decode('utf-8'))

    assert resp.get('searchColumns')
    assert resp.get('searchColumns') == ['Status']
コード例 #21
0
def test_update_user_settings(client, jwt, app):
    """Test updating user settings for an existing user."""
    # create user with settings
    user = User(
        username='******',
        sub='43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',  # this needs to match the sub in create_header
        firstname='',
        lastname='',
        iss=''
    )
    user.searchColumns = 'Status'
    user.save_to_db()
    # update user with put endpoint
    update_user_settings = client.put(
        f'api/v1/usersettings',
        json={ 'searchColumns': ['Status','LastModifiedBy'] },
        headers=create_header(jwt, [User.EDITOR], 'test-settings')
    )
    # assert user was successfully updated
    assert update_user_settings.status_code == 204
    assert user.searchColumns == 'Status,LastModifiedBy'
コード例 #22
0
def test_get_inprogress_event_history(client, jwt, app):

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc', 'url')
    user.save_to_db()

    # create JWT & setup header with a Bearer Token using the JWT
    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.DRAFT
    nr.save_to_db()
    EventRecorder.record(user, Event.POST + ' [payment completed] CREATE', nr, nr.json())

    nr.stateCd = State.INPROGRESS
    nr.save_to_db()
    EventRecorder.record(user, Event.PATCH, nr, { 'state': 'INPROGRESS' })
    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Load NR"' in rv.data
コード例 #23
0
def test_decision_event_history(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.REJECTED
    nr.save_to_db()

    EventRecorder.record(user, Event.PATCH, nr, {'state': 'REJECTED'})

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Decision"' in rv.data
コード例 #24
0
def test_consumed_event_history(client, jwt, app):
    from namex.models import State, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('nro_service_account', '', '',
                '8ca7d47a-024e-4c85-a367-57c9c93de1cd',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.CONSUMED
    nr.save_to_db()

    EventRecorder.record_as_system(Event.UPDATE_FROM_NRO, nr, nr.json())

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Get NR Details from NRO"' in rv.data
コード例 #25
0
def test_edit_event_history(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, User, Event
    from namex.services import EventRecorder

    # add a user for the comment
    user = User('test-user', '', '', '43e6a245-0bf7-4ccf-9bd0-e7fb85fd18cc',
                'https://sso-dev.pathfinder.gov.bc.ca/auth/realms/sbc')
    user.save_to_db()

    headers = create_header(jwt, [User.EDITOR])

    nr = create_base_nr()
    nr.stateCd = State.INPROGRESS
    nr.additionalInfo = 'additional'
    nr.save_to_db()

    EventRecorder.record(user, Event.PUT, nr, nr.json())

    # get the resource (this is the test)
    rv = client.get('/api/v1/events/NR%200000002', headers=headers)
    assert rv.status_code == 200

    assert b'"user_action": "Edit NR Details (NameX)"' in rv.data