コード例 #1
0
def test_draft_patch_resend(client, jwt, app):
    """
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    post_response = create_draft_nr(client, input_fields)

    # Assign the payload to new nr var
    draft_nr = json.loads(post_response.data)
    assert draft_nr is not None

    # Take the response and edit it
    nr_data = {}
    patch_response = patch_nr(client, NameRequestActions.RESEND.value,
                              draft_nr.get('id'), nr_data)
    patched_nr = json.loads(patch_response.data)
    assert patched_nr is not None

    print('PATCH Response: \n' + json.dumps(
        patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) + '\n')

    # Check state
    print('Assert that stateCd == DRAFT: ' +
          str(bool(patched_nr.get('stateCd') == 'DRAFT')))
    assert patched_nr.get('stateCd') == draft_nr.get('stateCd')

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')
コード例 #2
0
def test_consumed_and_approved_response_actions(client, jwt, app):
    """
    Test the Name Request's data fields. Excludes associations 'names' and 'applicant' - we have other tests for those.
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    custom_names = [{
        'name': 'BLUE HERON TOURS LTD.',
        'choice': 1,
        'designation': 'LTD.',
        'name_type_cd': 'CO',
        'consent_words': '',
        'conflict1': 'BLUE HERON TOURS LTD.',
        'conflict1_num': '0515211',
        # Custom name has a corp num to make it 'consumed'
        'corpNum': '12345'
    }]

    input_fields['names'] = custom_names

    # Assign the payload to new nr var
    test_nr = create_test_nr(input_fields, State.APPROVED)
    assert test_nr is not None

    # Grab the record using the API
    get_response = get_nr(client, test_nr.get('id'))
    nr = json.loads(get_response.data)
    assert nr is not None

    print('PATCH Response: \n' +
          json.dumps(nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    print('Assert that stateCd == APPROVED: ' +
          str(bool(nr.get('stateCd') == 'APPROVED')))
    assert nr.get('stateCd') == State.APPROVED

    assert_field_is_mapped(test_nr, nr, 'nrNum')

    # Check actions
    actions = nr.get('actions')
    assert_list_contains_exactly(
        actions,
        [
            NameRequestActions.EDIT.value,
            # TODO: Show receipt action ONLY if there is an existing payment!
            # NameRequestActions.RECEIPT.value,
            NameRequestActions.RESEND.value
        ])
コード例 #3
0
def test_draft_patch_reapply_historical(client, jwt, app):
    """
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    post_response = create_draft_nr(client, input_fields)

    # Assign the payload to new nr var
    draft_nr = json.loads(post_response.data)
    assert draft_nr is not None

    # Take the response and edit it
    nr_data = {'request_action_cd': 'REH'}

    patch_response = patch_nr(client, NameRequestActions.REAPPLY.value,
                              draft_nr.get('id'), nr_data)
    patched_nr = json.loads(patch_response.data)
    assert patched_nr is not None

    print('PATCH Response: \n' + json.dumps(
        patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) + '\n')

    # Check state
    assert patched_nr.get('stateCd') == draft_nr.get('stateCd')

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')

    assert_field_is_lt_value(patched_nr, 'submitCount', 4)
    # assert_field_equals_value(patched_nr, 'expirationDate', '')

    # Take the response and edit it
    nr_data = {'request_action_cd': 'REST'}

    patch_response = patch_nr(client, NameRequestActions.REAPPLY.value,
                              draft_nr.get('id'), nr_data)
    patched_nr = json.loads(patch_response.data)
    assert patched_nr is not None

    print('PATCH Response: \n' + json.dumps(
        patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) + '\n')

    # Check state
    assert patched_nr.get('stateCd') == draft_nr.get('stateCd')

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')

    assert_field_is_lt_value(patched_nr, 'submitCount', 4)
コード例 #4
0
def test_draft_patch_reapply(client, jwt, app):
    """
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    post_response = create_draft_nr(client, input_fields)

    # Assign the payload to new nr var
    draft_nr = json.loads(post_response.data)
    assert draft_nr is not None

    def do_reapply():
        # Take the response and edit it
        nr_data = {}
        patch_response = patch_nr(client, NameRequestActions.REAPPLY.value,
                                  draft_nr.get('id'), nr_data)

        updated_nr = None
        if patch_response.status_code == 200:
            updated_nr = json.loads(patch_response.data)
            assert updated_nr is not None

            print('PATCH Response: \n' + json.dumps(
                updated_nr, sort_keys=True, indent=4, separators=(',', ': ')) +
                  '\n')

        return updated_nr, patch_response.status_code

    # Re-apply
    patched_nr, status_code = do_reapply()

    # Check state
    assert patched_nr.get('stateCd') == draft_nr.get('stateCd')

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')

    assert_field_equals_value(patched_nr, 'submitCount', 2)
    # assert_field_equals_value(patched_nr, 'expirationDate', '')

    # Re-apply
    patched_nr, status_code = do_reapply()

    assert_field_equals_value(patched_nr, 'submitCount', 3)

    # Re-apply
    patched_nr, status_code = do_reapply()
    # The submitCount should never be greater than 3, this should now fail with a 500
    assert status_code == 500
コード例 #5
0
def assert_applicant_is_mapped_correctly(req_applicant, res_applicant):
    print('\n-------- Test applicant --------\n')
    print('\nCompare request applicant: \n' + repr(req_applicant) + '\n')
    print('With response applicant: \n' + repr(res_applicant) + '\n')

    if res_applicant and req_applicant.get('partyId', None) is None:
        # It's a new applicant make sure it has an ID set
        assert_applicant_has_id(res_applicant)
    if res_applicant and req_applicant.get('partyId', None) is not None:
        # The applicant existed, make sure the ID has not changed
        assert_field_is_mapped(req_applicant, res_applicant, 'partyId')

    print('\n-------- Test applicant complete --------\n')
コード例 #6
0
def test_draft_response_actions(client, jwt, app):
    """
    Test the Name Request's data fields. Excludes associations 'names' and 'applicant' - we have other tests for those.
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()

    # Assign the payload to new nr var
    test_nr = create_test_nr(input_fields, State.DRAFT)
    assert test_nr is not None

    # Grab the record using the API
    get_response = get_nr(client, test_nr.get('id'))
    nr = json.loads(get_response.data)
    assert nr is not None

    print('PATCH Response: \n' +
          json.dumps(nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    print('Assert that stateCd == DRAFT: ' +
          str(bool(nr.get('stateCd') == 'DRAFT')))
    assert nr.get('stateCd') == State.DRAFT

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(test_nr, nr, 'nrNum')

    # Check actions
    actions = nr.get('actions')
    assert_list_contains_exactly(
        actions,
        [
            NameRequestActions.EDIT.value,
            # TODO: Upgrade only should show up if priorityCd has not already been set to 'Y'
            NameRequestActions.UPGRADE.value,
            # TODO: Spreadsheet conflicts with task
            # TODO: Show refund action ONLY if there is an existing payment!
            # NameRequestActions.REQUEST_REFUND.value,
            # TODO: Show receipt action ONLY if there is an existing payment!
            # NameRequestActions.RECEIPT.value
        ])
コード例 #7
0
def test_conditional_and_expired_response_actions(client, jwt, app):
    """
    Test the Name Request's data fields. Excludes associations 'names' and 'applicant' - we have other tests for those.
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()

    # Set the expirationDate to a previous day, set to less than 5 so we get the REAPPLY option
    input_fields['expirationDate'] = datetime.date.today(
    ) - datetime.timedelta(days=2)

    # Assign the payload to new nr var
    test_nr = create_test_nr(input_fields, State.CONDITIONAL)
    assert test_nr is not None

    # Grab the record using the API
    get_response = get_nr(client, test_nr.get('id'))
    nr = json.loads(get_response.data)
    assert nr is not None

    print('PATCH Response: \n' +
          json.dumps(nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    print('Assert that stateCd == CONDITIONAL: ' +
          str(bool(nr.get('stateCd') == 'CONDITIONAL')))
    assert nr.get('stateCd') == State.CONDITIONAL

    assert_field_is_mapped(test_nr, nr, 'nrNum')

    # Check actions
    actions = nr.get('actions')
    assert_list_contains_exactly(
        actions,
        [
            NameRequestActions.EDIT.value,
            # TODO: Show receipt action ONLY if there is an existing payment!
            # NameRequestActions.RECEIPT.value,
            NameRequestActions.REAPPLY.value,
            NameRequestActions.RESEND.value
        ])
コード例 #8
0
def test_approved_response_actions(client, jwt, app):
    """
    Test the Name Request's data fields. Excludes associations 'names' and 'applicant' - we have other tests for those.
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()

    # Assign the payload to new nr var
    test_nr = create_test_nr(input_fields, State.APPROVED)
    assert test_nr is not None

    # Grab the record using the API
    get_response = get_nr(client, test_nr.get('id'))
    nr = json.loads(get_response.data)
    assert nr is not None

    print('PATCH Response: \n' +
          json.dumps(nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    print('Assert that stateCd == APPROVED: ' +
          str(bool(nr.get('stateCd') == 'APPROVED')))
    assert nr.get('stateCd') == State.APPROVED

    assert_field_is_mapped(test_nr, nr, 'nrNum')

    # Check actions
    actions = nr.get('actions')
    assert_list_contains_exactly(
        actions,
        [
            NameRequestActions.EDIT.value,
            NameRequestActions.CANCEL.value,
            # TODO: Show receipt action ONLY if there is an existing payment!
            # NameRequestActions.RECEIPT.value,
            # TODO: Add logic to test 5 days / expiry
            # NameRequestActions.REAPPLY.value,
            NameRequestActions.RESEND.value
        ])
コード例 #9
0
def test_draft_patch_upgrade(client, jwt, app):
    """
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    post_response = create_draft_nr(client, input_fields)

    # Assign the payload to new nr var
    draft_nr = json.loads(post_response.data)
    assert draft_nr is not None
    assert_field_equals_value(draft_nr, 'priorityCd', 'N')

    # Take the response and edit it
    nr_data = {}
    patch_response = patch_nr(client, NameRequestActions.UPGRADE.value,
                              draft_nr.get('id'), nr_data)

    assert patch_response.status_code == 200
    patched_nr = json.loads(patch_response.data)
    assert patched_nr is not None

    print('PATCH Response: \n' + json.dumps(
        patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) + '\n')

    # Check state
    assert patched_nr.get('stateCd') == State.PENDING_PAYMENT

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')

    # Check actions (write a util for this)

    # assert_field_equals_value(patched_nr, 'payment_token', '')
    assert_field_equals_value(patched_nr, 'priorityCd', 'Y')
コード例 #10
0
def assert_names_are_mapped_correctly(req_names, res_names):
    print('\n-------- Test names --------\n')
    for req_name in req_names:
        res_name = pick_name_from_list(res_names, req_name.get('name'))

        print('\nCompare request name: \n' + repr(req_name) + '\n')
        print('With response name: \n' + repr(res_name) + '\n')

        assert_name_has_name(res_name)

        if res_name and req_name.get('id', None) is None:
            # It's a new name make sure it has an ID set
            assert_name_has_id(res_name)
        if res_name and req_name.get('id', None) is not None:
            # The name existed, make sure the ID has not changed
            assert_field_is_mapped(req_name, res_name, 'id')

        # Make sure the choice is mapped correctly
        assert_field_is_mapped(req_name, res_name, 'choice')
        print('\n......................................\n')

    print('\n-------- Test names complete --------\n')
コード例 #11
0
def test_cancelled_response_actions(client, jwt, app):
    """
    Test the Name Request's data fields. Excludes associations 'names' and 'applicant' - we have other tests for those.
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()

    # Assign the payload to new nr var
    test_nr = create_test_nr(input_fields, State.CANCELLED)
    assert test_nr is not None

    # Grab the record using the API
    get_response = get_nr(client, test_nr.get('id'))
    nr = json.loads(get_response.data)
    assert nr is not None

    print('PATCH Response: \n' +
          json.dumps(nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    print('Assert that stateCd == CANCELLED: ' +
          str(bool(nr.get('stateCd') == 'CANCELLED')))
    assert nr.get('stateCd') == State.CANCELLED

    assert_field_is_mapped(test_nr, nr, 'nrNum')

    # Check actions
    actions = nr.get('actions')

    assert len(actions) is 0
コード例 #12
0
def test_draft_patch_edit_and_repatch(client, jwt, app):
    """
    Setup:
    Test:
    :param client:
    :param jwt:
    :param app:
    :return:
    """
    # Define our data
    input_fields = build_test_input_fields()
    post_response = create_draft_nr(client, input_fields)

    # Assign the payload to new nr var
    draft_nr = json.loads(post_response.data)
    assert draft_nr is not None

    # Take the response and edit it
    # Add another name to the mix
    nr_data = {
        'names': draft_nr.get('names'),
        'applicants': draft_nr.get('applicants')
    }

    added_names = [{
        'name': 'BLUE HERON ADVENTURE TOURS LTD.',
        'choice': 2,
        'designation': 'LTD.',
        'name_type_cd': 'CO',
        'consent_words': '',
        'conflict1': 'BLUE HERON TOURS LTD.',
        'conflict1_num': '0515211'
    }, {
        'name': 'BLUE HERON ISLAND TOURS LTD.',
        'choice': 3,
        'designation': 'LTD.',
        'name_type_cd': 'CO',
        'consent_words': '',
        'conflict1': 'BLUE HERON TOURS LTD.',
        'conflict1_num': '0515211'
    }]

    nr_data['names'].extend(added_names)

    # updated_applicant = {}

    # nr_data['applicant'] = updated_applicant

    patch_response = patch_nr(client, NameRequestActions.EDIT.value,
                              draft_nr.get('id'), nr_data)
    patched_nr = json.loads(patch_response.data)
    assert patched_nr is not None

    print('PATCH Response #1: \n' + json.dumps(
        patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) + '\n')

    # Check state
    assert patched_nr.get('stateCd') == 'PENDING_PAYMENT'

    # TODO: Check applicant(s)

    # Check names
    assert_names_are_mapped_correctly(nr_data.get('names'),
                                      patched_nr.get('names'))

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')

    # Check actions (write a util for this)
    """
    Patch the NR again with the response to make sure everything runs as expected
    """

    patch_response = patch_nr(client, NameRequestActions.EDIT.value,
                              patched_nr.get('id'), patched_nr)
    patched_nr = json.loads(patch_response.data)

    re_patched_nr = json.loads(patch_response.data)
    assert re_patched_nr is not None

    print('PATCH Response #2: \n' + json.dumps(
        re_patched_nr, sort_keys=True, indent=4, separators=(',', ': ')) +
          '\n')

    # Check state
    assert re_patched_nr.get('stateCd') == 'PENDING_PAYMENT'

    # TODO: Check applicant(s)

    # Check names
    assert_names_are_mapped_correctly(patched_nr.get('names'),
                                      re_patched_nr.get('names'))

    # Check NR number is the same because these are PATCH and call change_nr
    assert_field_is_mapped(draft_nr, patched_nr, 'nrNum')