Exemplo n.º 1
0
def email_campaign_of_user_first(access_token_first, smartlist_user1_domain1):
    """
    This returns email-campaign for "user_first" scheduled to be sent after some time.
    """
    campaign_data = create_scheduled_email_campaign_data(
        smartlist_user1_domain1['id'])
    return create_and_get_email_campaign(campaign_data, access_token_first)
Exemplo n.º 2
0
def create_email_campaign_with_merge_tags(smartlist_id=None,
                                          access_token=None,
                                          add_preference_url=True,
                                          in_db_only=False,
                                          user_id=None):
    """
    This function creates an email-campaign containing merge tags.
    """
    if in_db_only:
        email_campaign = create_email_campaign_in_db(user_id,
                                                     add_subject=False)
    else:
        campaign_data = create_scheduled_email_campaign_data(
            smartlist_id=smartlist_id)
        email_campaign = create_and_get_email_campaign(campaign_data,
                                                       access_token)
    # Update email-campaign's body text
    starting_string = 'Hello %s %s' % (DEFAULT_FIRST_NAME_MERGETAG,
                                       DEFAULT_LAST_NAME_MERGETAG)
    ending_string = ' Thanks, %s' % DEFAULT_USER_NAME_MERGETAG
    email_campaign.update(subject=starting_string + email_campaign.subject)
    if add_preference_url:
        starting_string += ', Unsubscribe URL is:%s' % DEFAULT_PREFERENCES_URL_MERGETAG
    email_campaign.update(
        body_text=starting_string + email_campaign.body_text + ending_string,
        body_html=starting_string + email_campaign.body_html + ending_string)

    return email_campaign
Exemplo n.º 3
0
def campaign_with_multiple_candidates_email(access_token_first,
                                            talent_pipeline):
    """
    This returns a campaign which has 2 candidates associated and have 2 email address.
    Email should be send to only one address of both candidates
    """
    _emails = [
        # Primary and work label
        [{
            'label': 'work',
            'address': 'work' + fake.safe_email()
        }, {
            'label': 'primary',
            'address': 'primary' + fake.safe_email()
        }],
        # Work and home label
        [{
            'label': 'work',
            'address': 'work' + fake.safe_email()
        }, {
            'label': 'home',
            'address': 'home' + fake.safe_email()
        }],
    ]

    smartlist_id = create_smartlist_with_given_email_candidate(
        access_token_first, talent_pipeline, emails=_emails, count=2)
    campaign_data = create_scheduled_email_campaign_data()
    campaign_data['list_ids'] = [smartlist_id]
    return create_and_get_email_campaign(campaign_data, access_token_first)
Exemplo n.º 4
0
def campaign_to_ten_candidates_not_sent(access_token_first, talent_pipeline):
    """
    This returns a campaign which has ten candidates associated having email addresses.
    """
    campaign_data = create_scheduled_email_campaign_data()
    smartlist_ids, _ = CampaignsTestsHelpers.create_smartlist_with_candidate(
        access_token_first, talent_pipeline, count=10, emails_list=True)
    campaign_data['list_ids'] = [smartlist_ids]
    return create_and_get_email_campaign(campaign_data, access_token_first)
Exemplo n.º 5
0
def campaign_with_archived_candidate(smartlist_with_archived_candidate,
                                     access_token_first):
    """
    This creates an email-campaign associated to smartlist which has one archived candidate in it.
    """
    campaign_data = create_scheduled_email_campaign_data(
        smartlist_id=smartlist_with_archived_candidate['id'])
    response = create_email_campaign_via_api(access_token_first, campaign_data)
    assert response.ok, 'campaign creation failed:%s' % response.text
    return response.json()['campaign']
Exemplo n.º 6
0
def campaign_with_candidate_having_no_email(access_token_first,
                                            talent_pipeline):
    """
    This creates a campaign which has candidates associated having no email
    """
    smartlist_id, _ = CampaignsTestsHelpers.create_smartlist_with_candidate(
        access_token_first, talent_pipeline)
    campaign_data = create_scheduled_email_campaign_data(
        smartlist_id=smartlist_id)
    return create_and_get_email_campaign(campaign_data, access_token_first)
Exemplo n.º 7
0
def campaign_with_same_candidate_in_multiple_smartlists(
        talent_pipeline, access_token_first):
    """
    This fixture creates an email campaign with two smartlists.
    Smartlist 1 will have two candidates and smartlist 2 will have one candidate (which will be
    same as one of the two candidates of smartlist 1).
    """
    smartlist_ids = CampaignsTestsHelpers.get_two_smartlists_with_same_candidate(
        talent_pipeline, access_token_first, email_list=True)
    campaign_data = create_scheduled_email_campaign_data()
    campaign_data['list_ids'] = smartlist_ids
    return create_and_get_email_campaign(campaign_data, access_token_first)
Exemplo n.º 8
0
 def test_campaign_creation_with_invalid_data(self, access_token_first):
     """
     Trying to create a campaign with 1) no data and 2) Non-JSON data. It should result in invalid usage error.
     """
     campaign_data = create_scheduled_email_campaign_data()
     for data in (campaign_data, None):
         CampaignsTestsHelpers.request_with_invalid_input(
             self.HTTP_METHOD,
             self.URL,
             access_token_first,
             data=data,
             is_json=False,
             expected_error_code=INVALID_REQUEST_BODY[1])
Exemplo n.º 9
0
 def test_create_campaign_with_invalid_datetime_format(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     This is a test to schedule a campaign with invalid datetime formats. It should result in invalid usage error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     CampaignsTestsHelpers.invalid_datetime_format(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data.copy(),
         expected_error_code=INVALID_DATETIME_FORMAT[1])
Exemplo n.º 10
0
 def test_create_campaign_with_invalid_frequency_id(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     Trying to schedule a campaign with invalid frequency_id. It should result in bad request error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     CampaignsTestsHelpers.campaign_schedule_or_reschedule_with_invalid_frequency_id(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data,
         expected_error_code=INVALID_INPUT[1])
Exemplo n.º 11
0
 def test_create_email_campaign_without_client_id(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     Here we provide valid data to create an email-campaign without email_client_id.
     It should get OK response.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     response = create_email_campaign_via_api(access_token_first,
                                              campaign_data)
     assert response.status_code == requests.codes.CREATED
     resp_object = response.json()
     assert 'campaign' in resp_object
     assert resp_object['campaign']['id']
Exemplo n.º 12
0
 def test_create_email_campaign_with_smartlist_id_of_other_domain(
         self, access_token_first, smartlist_other_in_db):
     """
     This is a test to create email-campaign with deleted smartlist id. It should result in
     Resource not found error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_other_in_db['id'])
     CampaignsTestsHelpers.request_for_forbidden_error(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data,
         expected_error_code=SMARTLIST_FORBIDDEN[1])
Exemplo n.º 13
0
 def test_create_email_campaign_with_deleted_smartlist_id(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     This is a test to create email-campaign with deleted smartlist id. It should result in
     Resource not found error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     CampaignsTestsHelpers.send_request_with_deleted_smartlist(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data['list_ids'][0],
         expected_error_code=SMARTLIST_NOT_FOUND[1],
         data=campaign_data)
Exemplo n.º 14
0
 def test_create_email_campaign_with_invalid_smartlist_ids(
         self, access_token_first):
     """
     This is a test to create email-campaign with invalid smartlist_ids.
     Invalid smartlist ids include  non-integer id, empty list, duplicate items in list etc.
     Status code should be 400 and campaign should not be created.
     """
     campaign_data = create_scheduled_email_campaign_data()
     CampaignsTestsHelpers.campaign_create_or_update_with_invalid_smartlist(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data,
         field='list_ids',
         expected_error_code=INVALID_INPUT[1])
Exemplo n.º 15
0
 def test_create_email_campaign_with_invalid_format_of_smartlist_ids(
         self, access_token_first):
     """
     Here we try to create an email-campaign with list_ids not in list format. It should
     result in invalid usage error.
     """
     campaign_data = create_scheduled_email_campaign_data()
     campaign_data['list_ids'] = fake.random_number(
     )  # 'list_ids' must be a list
     CampaignsTestsHelpers.request_with_invalid_input(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         data=campaign_data,
         expected_error_code=INVALID_INPUT[1])
Exemplo n.º 16
0
 def test_create_email_campaign_with_invalid_string_values(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     This tries to create an email campaign with invalid string value of fields `name`, `subject` and `body_html`.
     It should result in invalid usage error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_id=smartlist_user1_domain1_in_db['id'])
     for field in ('name', 'subject', 'body_html'):
         CampaignsTestsHelpers.request_with_invalid_string(
             self.HTTP_METHOD,
             self.URL,
             access_token_first,
             campaign_data.copy(),
             field=field,
             expected_error_code=INVALID_INPUT[1])
Exemplo n.º 17
0
 def test_create_periodic_email_campaign_with_past_start_and_end_datetime(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     Here we try to create an email-campaign with frequency DAILY for which start_datetime and end_datetime
     are expected to be in past. It should result in UnprocessableEntity error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     expected_status_code = UnprocessableEntity.http_status_code()
     campaign_data['frequency_id'] = Frequency.DAILY
     CampaignsTestsHelpers.request_with_past_start_and_end_datetime(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data,
         expected_status_code=expected_status_code,
         expected_error_code=INVALID_DATETIME_VALUE[1])
Exemplo n.º 18
0
 def test_create_periodic_email_campaign_with_missing_start_and_end_datetime(
         self, access_token_first, smartlist_user1_domain1_in_db):
     """
     Here we try to create an email-campaign with frequency DAILY for which start_datetime and end_datetime
     will be required fields. But we are not giving those fields. It should result in UnprocessableEntity error.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     expected_status_code = UnprocessableEntity.http_status_code()
     campaign_data['frequency_id'] = Frequency.DAILY
     CampaignsTestsHelpers.missing_fields_in_schedule_data(
         self.HTTP_METHOD,
         self.URL,
         access_token_first,
         campaign_data,
         expected_status_code=expected_status_code,
         expected_error_code=MISSING_FIELD[1])
Exemplo n.º 19
0
 def test_create_email_campaign_with_incoming_email_client(
         self, access_token_first, smartlist_user1_domain1_in_db,
         email_clients, headers):
     """
     Here we provide email-client of type "incoming". email-campaign should not be created.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     # GET email-client-id
     response = requests.get(EmailCampaignApiUrl.EMAIL_CLIENTS +
                             '?type=incoming',
                             headers=headers)
     assert response.ok
     assert response.json()
     email_client_response = response.json()['email_client_credentials']
     assert len(email_client_response) == 2
     campaign_data['email_client_credentials_id'] = email_client_response[
         0]['id']
     response = create_email_campaign_via_api(access_token_first,
                                              campaign_data)
     assert response.status_code == requests.codes.BAD
Exemplo n.º 20
0
def email_campaign_with_outgoing_email_client(access_token_first,
                                              smartlist_user1_domain1, headers,
                                              outgoing_email_client):
    """
    This creates an email-campaign which will be sent via an SMTP server added by user.
    """
    campaign_data = create_scheduled_email_campaign_data(
        smartlist_user1_domain1['id'])
    # GET email-client-id
    response = requests.get(EmailCampaignApiUrl.EMAIL_CLIENTS +
                            '?type=outgoing',
                            headers=headers)
    assert response.ok
    assert response.json()
    email_client_response = response.json()['email_client_credentials']
    assert len(email_client_response) == 1
    campaign_data['email_client_credentials_id'] = email_client_response[0][
        'id']
    response = create_email_campaign_via_api(access_token_first, campaign_data)
    assert response.status_code == requests.codes.CREATED
    resp_object = response.json()
    assert 'campaign' in resp_object and resp_object['campaign']
    db.session.commit()
    return resp_object['campaign']
Exemplo n.º 21
0
 def test_create_email_campaign_with_outgoing_email_client(
         self, access_token_first, smartlist_user1_domain1_in_db,
         outgoing_email_client, headers):
     """
     Here we provide valid data to create an email-campaign with email_client_credentials_id.
     It should get OK response.
     """
     campaign_data = create_scheduled_email_campaign_data(
         smartlist_user1_domain1_in_db['id'])
     # GET email-client-id
     response = requests.get(EmailCampaignApiUrl.EMAIL_CLIENTS +
                             '?type=outgoing',
                             headers=headers)
     assert response.ok
     assert response.json()
     email_client_response = response.json()['email_client_credentials']
     assert len(email_client_response) == 1
     campaign_data['email_client_credentials_id'] = email_client_response[
         0]['id']
     response = create_email_campaign_via_api(access_token_first,
                                              campaign_data)
     assert response.status_code == requests.codes.CREATED
     resp_object = response.json()
     assert 'campaign' in resp_object and resp_object['campaign']