Example #1
0
def create_and_validate_account(token, post_data):
    """
    Create an account and validate that all entries have been correctly made.

    :param str token: authentication token
    :param dict post_data: JSON string of account values
    """
    response = send_request('post', ATSServiceApiUrl.ACCOUNTS, token,
                            post_data)
    assert response.status_code == codes.CREATED
    account_id = response.headers['location'].split('/')[-1]
    response = send_request('get',
                            ATSServiceApiUrl.ACCOUNT % account_id,
                            token, {},
                            verify=False)
    assert response.status_code == codes.OK
    values = response.json()
    assert values['credentials'] == post_data['ats_credentials']

    # Get all ATS - there should only be one - then validate the first (and only) one
    response = send_request('get',
                            ATSServiceApiUrl.ATS,
                            token, {},
                            verify=False)
    assert response.status_code == codes.OK
    values = response.json()
    # This fails occasionally in parallel tests due to a race condition.
    # assert len(values) == 1
    assert values['ats_list'][0]['login_url'] == post_data['ats_login']
    return account_id
Example #2
0
def create_and_validate_candidate(token, account_id, post_data):
    """
    Create a candidate and validate that all entries have been correctly made.

    :param str token: authentication token
    :param int account_id: primary key of the account
    :param dict post_data: JSON string of candidate values
    """
    # Grab a candidate field value to test
    profile_dict = json.loads(post_data['profile_json'])
    # Create an ATS account for the candidate to belong to
    response = send_request('post', ATSServiceApiUrl.CANDIDATES % account_id,
                            token, post_data)
    assert response.status_code == codes.CREATED
    values = response.json()
    candidate_id = values['id']
    # Now fetch all the candidates from the account
    response = send_request('get',
                            ATSServiceApiUrl.CANDIDATES % account_id,
                            token, {},
                            verify=False)
    assert response.status_code == codes.OK
    values = response.json()
    assert len(values['candidate_list']) == 1
    # Extract the returned field
    key = values['candidate_list'][0].keys()[0]
    profile = json.loads(values['candidate_list'][0][key]['profile_json'])
    assert profile['some'] == profile_dict.values()[0]
    return candidate_id
Example #3
0
    def test_unlink_ats_candidate(self, access_token_first, account_post_data,
                                  candidate_post_data, candidate_first):
        """
        POST /v1/ats-candidates/:account_id
        DELETE /v1/ats-candidates/link/:candidate_id/:ats_candidate_id
        GET /v1/ats-candidates/:account_id/:candidate_id

        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        :param dict candidate_post_data: values for creating an ATS account
        """
        account_id, gt_candidate_id, ats_candidate_id = link_candidates(
            access_token_first, account_post_data, candidate_post_data,
            candidate_first)
        response = send_request(
            'delete', ATSServiceApiUrl.CANDIDATE_LINK %
            (gt_candidate_id, ats_candidate_id), access_token_first)
        assert response.status_code == codes.OK
        response = send_request('get',
                                ATSServiceApiUrl.CANDIDATE %
                                (account_id, ats_candidate_id),
                                access_token_first, {},
                                verify=False)
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['gt_candidate_id'] is None
Example #4
0
    def test_update_ats_account(self, access_token_first, account_post_data):
        """
        POST /v1/ats-accounts Test creating an account
        PUT /v1/ats-accounts/:account_id Test updating an account
        GET /v1/ats-accounts/:account_id Test fetching an account

        Update and verify new data of account.

        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        """
        account_id = create_and_validate_account(access_token_first,
                                                 account_post_data)
        key = 'ats_homepage'
        value = 'https://someotherhost.com/authenticate'
        new_data = {key: value}
        response = send_request('put', ATSServiceApiUrl.ACCOUNT % account_id,
                                access_token_first, new_data)
        assert response.status_code == codes.CREATED
        response = send_request('get',
                                ATSServiceApiUrl.ACCOUNT % account_id,
                                access_token_first, {},
                                verify=False)
        assert response.status_code == codes.OK
        # TODO: Normalize service output text between endpoints
        values = json.loads(response.text)
        assert values[key] == value
Example #5
0
    def test_post_account_without_auth(self, account_post_data):
        """
        POST /v1/ats-accounts

        Test authentication failure.
        
        :param dict account_post_data: values for creating an ATS account
        """
        response = send_request('post', ATSServiceApiUrl.ACCOUNTS,
                                'bad_bad_token', account_post_data)
        assert response.status_code == codes.UNAUTHORIZED
Example #6
0
def verify_nonexistant_account(token, account_id):
    """
    Verify that an account does not exist.

    :param str token: authentication token
    :param int account_id: primary key of the account
    """
    response = send_request('get',
                            ATSServiceApiUrl.ACCOUNT % account_id,
                            token, {},
                            verify=False)
    assert response.status_code == codes.NOT_FOUND
Example #7
0
def missing_field_test(data, key, token):
    """
    This function sends a POST request to the ATS account api with data which has one required field missing.
    :param dict data: ATS data
    :param string key: field key
    :param string token: auth token
    """
    del data[key]
    response = send_request('post', ATSServiceApiUrl.ACCOUNTS, token, data)
    assert response.status_code == codes.BAD_REQUEST
    response = response.json()
    error = response['error']
    assert error['missing_fields'] == [key]
Example #8
0
    def test_update_ats_candidate(self, access_token_first, account_post_data,
                                  candidate_post_data):
        """
        POST /v1/ats-candidates/:account_id
        PUT /v1/ats-candidates/:account_id/:candidate_id
        GET /v1/ats-candidates/:account_id/:candidate_id

        Test updating an existing candidate's profile.

        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        :param dict candidate_post_data: values for creating an ATS account
        """
        account_id = create_and_validate_account(access_token_first,
                                                 account_post_data)
        candidate_id = create_and_validate_candidate(access_token_first,
                                                     account_id,
                                                     candidate_post_data)
        response = send_request('get',
                                ATSServiceApiUrl.CANDIDATE %
                                (account_id, candidate_id),
                                access_token_first, {},
                                verify=False)
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        new_value = '{ "some_other" : "json" }'
        values['profile_json'] = new_value
        response = send_request(
            'put', ATSServiceApiUrl.CANDIDATE % (account_id, candidate_id),
            access_token_first, values)
        assert response.status_code == codes.CREATED
        response = send_request('get',
                                ATSServiceApiUrl.CANDIDATE %
                                (account_id, candidate_id),
                                access_token_first, {},
                                verify=False)
        values = json.loads(response.text)
        assert values['profile_json'] == new_value
Example #9
0
def verify_nonexistant_candidate(token, account_id, candidate_id):
    """
    Verify that a candidate does not exist.

    :param str token: authentication token
    :param int account_id: primary key of the account
    :param int candidate_id: primary key of the candidate
    """
    response = send_request('get',
                            ATSServiceApiUrl.CANDIDATE %
                            (account_id, candidate_id),
                            token, {},
                            verify=False)
    assert response.status_code == codes.NOT_FOUND
Example #10
0
    def test_ats_gt_match_empty(self, access_token_first, account_post_data):
        """
        PATCH /v1/ats-candidates/match-link/:account_id/:match-method

        Test that no matches are found.

        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        """
        account_id = create_and_validate_account(access_token_first,
                                                 account_post_data)
        response = send_request(
            'patch', ATSServiceApiUrl.MATCH_AND_LINK % (account_id, u'email'),
            access_token_first, {})
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['matches'] == 0
        response = send_request(
            'patch', ATSServiceApiUrl.MATCH_AND_LINK % (account_id, u'phone'),
            access_token_first, {})
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['matches'] == 0
        response = send_request(
            'patch',
            ATSServiceApiUrl.MATCH_AND_LINK % (account_id, u'email-and-phone'),
            access_token_first, {})
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['matches'] == 0
        response = send_request(
            'patch',
            ATSServiceApiUrl.MATCH_AND_LINK % (account_id, u'email-or-phone'),
            access_token_first, {})
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['matches'] == 0
Example #11
0
def link_candidates(token, account_data, candidate_data, gt_candidate):
    """
    Link a GT candidate to an ATS candidate and validate the link.

    :param str token: authentication token
    :param dict account_data: data to create an account with
    :param dict candidate_data: data to create an ATS candidate
    :param Candidate gt_candidate: candidate object
    """
    account_id = create_and_validate_account(token, account_data)
    candidate_id = create_and_validate_candidate(token, account_id,
                                                 candidate_data)
    url = ATSServiceApiUrl.CANDIDATE_LINK % (gt_candidate.id, candidate_id)
    response = send_request('post', url, token, {})
    assert response.status_code == codes.CREATED
    response = send_request('get',
                            ATSServiceApiUrl.CANDIDATE %
                            (account_id, candidate_id),
                            token, {},
                            verify=False)
    assert response.status_code == codes.OK
    values = response.json()
    assert gt_candidate.id == int(values['gt_candidate_id'])
    return account_id, gt_candidate.id, candidate_id
Example #12
0
    def test_delete_ats_account(self, access_token_first, account_post_data):
        """
        POST /v1/ats-accounts Test creating an account
        DELETE /v1/ats-accounts/:account_id

        Verify deletion of account.
        
        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        """
        account_id = create_and_validate_account(access_token_first,
                                                 account_post_data)
        response = send_request('delete',
                                ATSServiceApiUrl.ACCOUNT % account_id,
                                access_token_first)
        assert response.status_code == codes.OK
        values = json.loads(response.text)
        assert values['delete'] == 'success'
        verify_nonexistant_account(access_token_first, account_id)
Example #13
0
    def test_delete_ats_candidate(self, access_token_first, account_post_data,
                                  candidate_post_data):
        """
        POST /v1/ats-candidates/:account_id
        GET /v1/ats-candidates/:account_id/:candidate_id
        DELETE /v1/ats-candidates/:account_id/:candidate_id

        Create an account, insert a candidate, then delete it and verify that it's gone.

        :param str access_token_first: authentication token
        :param dict account_post_data: values for creating an ATS account
        :param dict candidate_post_data: values for creating an ATS account
        """
        account_id = create_and_validate_account(access_token_first,
                                                 account_post_data)
        candidate_id = create_and_validate_candidate(access_token_first,
                                                     account_id,
                                                     candidate_post_data)
        response = send_request(
            'delete', ATSServiceApiUrl.CANDIDATE % (account_id, candidate_id),
            access_token_first)
        assert response.status_code == codes.OK
        verify_nonexistant_candidate(access_token_first, account_id,
                                     candidate_id)