示例#1
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
示例#2
0
def test_comment_where_no_user(client, jwt, app):
    from namex.models import Request as RequestDAO, State, Name as NameDAO, Comment as CommentDAO, User

    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()

    # 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
示例#3
0
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
示例#4
0
def save_words_list_name(words_list, queue=False):
    from namex.models import Request as RequestDAO, State, Name as NameDAO
    num = 0
    req = 1460775
    for record in words_list:
        nr_num_label = 'NR 00000'
        num += 1
        req += 1
        nr_num = nr_num_label + str(num)

        nr = RequestDAO()
        nr.nrNum = nr_num
        if queue:
            nr.stateCd = State.DRAFT
            nr.expirationDate = datetime.date.today() + datetime.timedelta(days=1)
        else:
            nr.stateCd = State.APPROVED
        nr.requestId = req
        nr.requestTypeCd = EntityTypes.CORPORATION.value
        nr._source = 'NAMEREQUEST'

        name = NameDAO()
        name.choice = 1
        name.name = record
        name.state = State.APPROVED
        name.corpNum = '0652480'
        nr.names = [name]
        nr.save_to_db()
示例#5
0
def build_draft(data=None, test_names=None, generate_id_seq=None):
    try:
        nr = RequestDAO()

        # Set defaults, if these exist in the provided data they will be overwritten
        nr.stateCd = State.DRAFT
        nr.requestId = 1460775
        nr._source = 'NRO'

        if not data:
            data = {}

        # Map the data, if provided
        for key, value in data.items():
            # Don't set list attrs, they have to be set separately to handle sequences
            if hasattr(nr, key) and not isinstance(data.get(key), list):
                nr.__setattr__(key, value)

        nr.names = []
        for test_name in test_names:
            nr.names.append(build_name(test_name, generate_id_seq))

        return nr
    except Exception as err:
        print(repr(err))
示例#6
0
def build_rejected(data=None, test_names=None, generate_id_seq=None):
    """
    :param data:
    :param test_names:
    :param generate_id_seq:
    :return:
    """
    nr = RequestDAO()

    # Set defaults, if these exist in the provided data they will be overwritten
    nr.stateCd = State.REJECTED
    nr.requestId = 1460775
    nr._source = 'NRO'

    if not data:
        data = {}

    # Map the data, if provided
    for key, value in data.items():
        # Don't set list attrs, they have to be set separately to handle sequences
        if hasattr(nr, key) and not isinstance(data.get(key), list):
            nr.__setattr__(key, value)

    nr.names = []
    for test_name in test_names:
        nr.names.append(build_name(test_name, generate_id_seq))

    return nr
示例#7
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":'
示例#8
0
def create_base_nr():
    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.PENDING_PAYMENT
    nr.requestId = 1460775
    nr._source = ValidSources.NAMEREQUEST.value
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'TEST NAME ONE'
    nr.names = [name1]
    nr.additionalInfo = 'test'
    nr.requestTypeCd = 'CR'
    nr.request_action_cd = 'NEW'
    nr.save_to_db()
    return nr
示例#9
0
def test_remove_name_from_nr(client, jwt, app):

    # add NR to database
    from namex.models import Request as RequestDAO, State, Name as NameDAO
    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.INPROGRESS
    nr.requestId = 1460775
    nr._source = 'NRO'
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'ONE'
    name2 = NameDAO()
    name2.choice = 2
    name2.name = 'TWO'
    nr.names = [name1, name2]
    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['names']) == 2

    for name in data['names']:
        if name['choice'] == 2:
            name['name'] = ''

    # Update with one blank name name (should remove the blank name)
    rv = client.put('/api/v1/requests/NR%200000002',
                    data=json.dumps(data),
                    headers=headers)

    data = json.loads(rv.data)
    assert 200 == rv.status_code
    assert len(data['names']) == 1
示例#10
0
def test_add_new_blank_name_to_nr(client, jwt, app):

    # add NR to database
    from namex.models import Request as RequestDAO, State, Name as NameDAO
    nr = RequestDAO()
    nr.nrNum = 'NR 0000002'
    nr.stateCd = State.INPROGRESS
    nr.requestId = 1460775
    nr._source = 'NRO'
    name1 = NameDAO()
    name1.choice = 1
    name1.name = 'ONE'
    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'
    }

    # 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['names']) == 1

    new_name = data['names'][0].copy()
    new_name['name'] = ''
    new_name['choice'] = 2
    data['names'].append(new_name)

    # Update with a brand new name (this is the test)
    rv = client.put('/api/v1/requests/NR%200000002',
                    data=json.dumps(data),
                    headers=headers)

    data = json.loads(rv.data)
    assert 200 == rv.status_code
    assert len(data['names']) == 1
示例#11
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']