Exemplo n.º 1
0
    def test_add_multiple_is_default_emails_to_candidate(
            self, access_token_first, candidate_first):
        """
        Test: Add multiple emails to candidate's profile with is_default set to True
        Expect: 400
        """
        candidate_id = candidate_first.id

        data = {
            'candidates': [{
                'id':
                candidate_id,
                'emails': [{
                    'address': fake.safe_email(),
                    'is_default': True
                }, {
                    'address': fake.safe_email(),
                    'is_default': True
                }]
            }]
        }

        # Add emails to candidate's profile
        update_resp = send_request('patch', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.BAD
        assert update_resp.json(
        )['error']['code'] == custom_error.INVALID_USAGE
Exemplo n.º 2
0
 def test_add_multiple_default_emails(self, access_token_first,
                                      talent_pool):
     """
     Test: Add multiple emails with "is default" set to true
     """
     data = {
         'candidates': [{
             'talent_pool_ids': {
                 'add': [talent_pool.id]
             },
             'emails': [{
                 'address': fake.safe_email(),
                 'is_default': True
             }, {
                 'address': fake.safe_email(),
                 'is_default': True
             }, {
                 'address': fake.safe_email(),
                 'is_default': True
             }]
         }]
     }
     create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                access_token_first, data)
     print response_info(create_resp)
     assert create_resp.status_code == requests.codes.BAD
     assert create_resp.json(
     )['error']['code'] == custom_error.INVALID_USAGE
Exemplo n.º 3
0
    def test_add_email_with_address_only(self, access_token_first,
                                         talent_pool):
        """
        Test: Add emails without providing is_default and label values
        Expect: 201, only the first email should be the default email and its
          label should be "Primary"; the rest should have "Other" as their label
        """
        data = {
            'candidates': [{
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                },
                'emails': [{
                    'address': fake.safe_email()
                }, {
                    'address': fake.safe_email()
                }, {
                    'address': fake.safe_email()
                }]
            }]
        }

        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.CREATED

        # Retrieve candidate and assert on the integrity of its data
        candidate_id = create_resp.json()['candidates'][0]['id']
        get_resp = send_request('get',
                                CandidateApiUrl.CANDIDATE % candidate_id,
                                access_token_first)
        print response_info(get_resp)
        assert get_resp.status_code == requests.codes.OK

        retrieved_email_data = get_resp.json()['candidate']['emails']
        assert len(retrieved_email_data) == len(
            data['candidates'][0]['emails'])
        assert retrieved_email_data[0]['is_default'] is True
        assert retrieved_email_data[0][
            'label'] == EmailLabel.PRIMARY_DESCRIPTION

        # Only one of the emails should be labeled 'Primary'
        email_labels = [email['label'] for email in retrieved_email_data]
        assert len(
            filter(lambda label: label == EmailLabel.PRIMARY_DESCRIPTION,
                   email_labels)) == 1

        # Only one of the emails should be default email
        assert len(
            filter(None,
                   [email['is_default']
                    for email in retrieved_email_data])) == 1
Exemplo n.º 4
0
    def test_add_duplicate_candidate_with_same_email(self, access_token_first,
                                                     talent_pool):
        """
        Test: Add candidate with an email that is associated with another candidate in the same domain
        """

        email_address = fake.safe_email()
        data = {
            'candidates': [{
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                },
                'emails': [{
                    'label': ' work',
                    'address': email_address
                }]
            }]
        }
        send_request('post', CandidateApiUrl.CANDIDATES, access_token_first,
                     data)
        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.BAD
        assert create_resp.json(
        )['error']['code'] == custom_error.CANDIDATE_ALREADY_EXISTS
Exemplo n.º 5
0
    def test_add_candidate_with_duplicate_emails(self, access_token_first,
                                                 talent_pool):
        """
        Test: Add candidate with two identical emails
        Expect: 201, but only one email should be added to db
        """

        # Create candidate with two identical emails
        email_address = fake.safe_email()
        data = {
            'candidates': [{
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                },
                'emails': [{
                    'label': ' work',
                    'address': email_address
                }, {
                    'label': ' work',
                    'address': email_address
                }]
            }]
        }
        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.CREATED

        # Retrieve candidate's emails and assert that only one email has been added
        candidate_id = create_resp.json()['candidates'][0]['id']
        get_resp = send_request('get',
                                CandidateApiUrl.CANDIDATE % candidate_id,
                                access_token_first)

        assert len(get_resp.json()['candidate']['emails']) == 1
Exemplo n.º 6
0
    def test_add_emails_with_whitespaced_values(self, access_token_first,
                                                talent_pool):
        """
        Test:  Add candidate emails with values containing whitespaces
        Expect:  201; but whitespaces should be stripped
        """
        data = {
            'candidates': [{
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                },
                'emails': [{
                    'label': ' work',
                    'address': fake.safe_email() + '   '
                }, {
                    'label': 'Primary ',
                    'address': ' ' + fake.safe_email()
                }]
            }]
        }

        # Create candidate email
        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.CREATED

        # Retrieve candidate
        candidate_id = create_resp.json()['candidates'][0]['id']
        get_resp = send_request('get',
                                CandidateApiUrl.CANDIDATE % candidate_id,
                                access_token_first)
        print response_info(get_resp)
        emails = get_resp.json()['candidate']['emails']
        assert len(emails) == 2
        assert emails[0]['address'] == data['candidates'][0]['emails'][0][
            'address'].strip()
        assert emails[0]['label'] == data['candidates'][0]['emails'][0][
            'label'].strip().title()
        assert emails[1]['address'] == data['candidates'][0]['emails'][1][
            'address'].strip()
        assert emails[1]['label'] == data['candidates'][0]['emails'][1][
            'label'].strip()
Exemplo n.º 7
0
    def test_create_candidate_without_email_label(self, access_token_first,
                                                  talent_pool):
        """
        Test:   Create a Candidate without providing email's label
        Expect: 201, email's label must be 'Primary'
        """

        # Create Candidate without email-label
        data = {
            'candidates': [{
                'emails': [{
                    'label': None,
                    'is_default': None,
                    'address': fake.safe_email()
                }, {
                    'label': None,
                    'is_default': None,
                    'address': fake.safe_email()
                }],
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                }
            }]
        }
        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)

        # Retrieve Candidate
        candidate_id = create_resp.json()['candidates'][0]['id']
        get_resp = send_request('get',
                                CandidateApiUrl.CANDIDATE % candidate_id,
                                access_token_first)
        print response_info(get_resp)
        candidate_dict = get_resp.json()['candidate']
        assert create_resp.status_code == requests.codes.CREATED
        assert candidate_dict['emails'][0][
            'label'] == EmailLabel.PRIMARY_DESCRIPTION
        assert candidate_dict['emails'][-1][
            'label'] == EmailLabel.OTHER_DESCRIPTION
Exemplo n.º 8
0
    def test_add_forbidden_email_to_candidate(self, access_token_first,
                                              talent_pool):
        """
        Test: Add two candidates. Then add another email to candidate 2 using candidate's 1 email
        """
        # Define email address
        first_candidates_email = fake.safe_email()

        # Create both candidates
        data = {
            'candidates': [{
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                },
                'emails': [{
                    'address': first_candidates_email
                }]
            }, {
                'talent_pool_ids': {
                    'add': [talent_pool.id]
                }
            }]
        }
        create_resp = send_request('post', CandidateApiUrl.CANDIDATES,
                                   access_token_first, data)
        print response_info(create_resp)
        assert create_resp.status_code == requests.codes.CREATED

        # Add a second email to the second candidate using first-candidate's email address
        candidate_2_id = create_resp.json()['candidates'][1]['id']
        update_data = {
            'candidates': [{
                'id': candidate_2_id,
                'emails': [{
                    'address': first_candidates_email
                }]
            }]
        }
        update_resp = send_request('patch', CandidateApiUrl.CANDIDATES,
                                   access_token_first, update_data)
        print response_info(update_resp)
        assert update_resp.status_code == requests.codes.FORBIDDEN
        assert update_resp.json(
        )['error']['code'] == custom_error.EMAIL_FORBIDDEN