Example #1
0
 def test_campaign_send_with_merge_tags(self, headers, user_first, email_campaign_with_merge_tags):
     """
     User auth token is valid, campaign has one smartlist associated. Smartlist has one
     candidate associated. We assert that received email has correctly replaced merge tags.
     If candidate's first name is `John` and last name is `Doe`, and email body is like
     'Hello *|FIRSTNAME|* *|LASTNAME|*,', it will become 'Hello John Doe,'
     """
     campaign, candidate = email_campaign_with_merge_tags
     response = requests.post(self.URL % campaign.id, headers=headers)
     candidate_object = Candidate.get_by_id(candidate['id'])
     candidate_address = candidate_object.emails[0].address
     [modified_subject] = do_mergetag_replacements([campaign.subject], user_first,
                                                   requested_object=candidate_object,
                                                   candidate_address=candidate_address,
                                                   )
     campaign.update(subject=modified_subject)
     assert_campaign_send(response, campaign, user_first.id, blast_sends=1, delete_email=False,
                          via_amazon_ses=False)
     msg_ids = retry(assert_and_delete_email, sleeptime=5, attempts=80, sleepscale=1,
                     args=(modified_subject,), kwargs=dict(delete_email=False),
                     retry_exceptions=(AssertionError, imaplib.IMAP4_SSL.error))
     mail_connection = get_mail_connection(app.config[TalentConfigKeys.GT_GMAIL_ID],
                                           app.config[TalentConfigKeys.GT_GMAIL_PASSWORD])
     email_bodies = fetch_emails(mail_connection, msg_ids)
     assert len(email_bodies) == 1
     assert candidate['first_name'] in email_bodies[0]
     assert candidate['last_name'] in email_bodies[0]
     assert str(candidate['id']) in email_bodies[0]  # This will be in unsubscribe URL.
     delete_emails(mail_connection, msg_ids, modified_subject)
Example #2
0
 def test_campaign_send_with_two_smartlists(self, headers, user_first, campaign_with_two_smartlists):
     """
     This function creates two smartlists with 20 candidates each and associates them
     with a campaign. Sends that campaign and tests if emails are sent to all 40 candidates.
     """
     response = requests.post(self.URL % campaign_with_two_smartlists.id, headers=headers)
     assert_campaign_send(response, campaign_with_two_smartlists, user_first.id, 40)
Example #3
0
 def test_campaign_send_with_unsubscribed_candidate(self, headers, user_first, campaign_with_unsubscribed_candidate):
     """
     We try to send campaign to a smartlist which contains 2 candidates. One of the candidate has unsubscribed
     toc campaigns, So, campaign should only be sent to 1 candidate.
     """
     campaign = campaign_with_unsubscribed_candidate
     response = requests.post(self.URL % campaign.id, headers=headers)
     assert_campaign_send(response, campaign, user_first.id, blast_sends=1)
Example #4
0
 def test_campaign_send_with_outgoing_email_client(self, email_campaign_with_outgoing_email_client, headers,
                                                   user_first):
     """
     This sends email-campaign with SMTP server added by user. It should not get any error.
     """
     campaign = email_campaign_with_outgoing_email_client
     response = requests.post(self.URL % campaign['id'], headers=headers)
     assert_campaign_send(response, campaign, user_first.id, via_amazon_ses=False)
Example #5
0
 def test_campaign_send_with_no_href_in_anchor_tag(self, email_campaign_of_user_first, headers, user_first):
     """
     Here we put an empty anchor tag in body_text of email-campaign. It should not result in any error.
     """
     campaign = email_campaign_of_user_first
     campaign.update(body_html='<html><body><a>%s</a></body></html>' % fake.sentence())
     response = requests.post(self.URL % campaign.id, headers=headers)
     assert_campaign_send(response, campaign, user_first.id)
Example #6
0
 def test_campaign_send_with_multiple_emails_of_candidates(self, headers, user_first,
                                                           campaign_with_multiple_candidates_email):
     """
     The test sends email to two candidates each having two emails.
     But email-campaign should be sent to only primary-email-addresses of candidates.
     If primary email is not found then email-campaign will be sent to latest emails added for candidates.
     """
     response = requests.post(self.URL % campaign_with_multiple_candidates_email.id, headers=headers)
     assert_campaign_send(response, campaign_with_multiple_candidates_email, user_first.id)
Example #7
0
 def test_campaign_send_with_two_smartlists_having_same_candidate(
         self, headers, user_first, campaign_with_same_candidate_in_multiple_smartlists):
     """
     This function creates two smartlists with 1 candidate each, candidate is same in both smartlists and
     associates them with a campaign. Sends that campaign and tests if email is sent to the candidate only once.
     """
     campaign = campaign_with_same_candidate_in_multiple_smartlists
     response = requests.post(self.URL % campaign.id, headers=headers)
     assert_campaign_send(response, campaign, user_first.id, blast_sends=1)
Example #8
0
 def test_campaign_send_with_hundred_sends(self, headers, user_first, campaign_to_ten_candidates_not_sent):
     """
     Here we send one campaign to 10 candidates 10 times. Total sends should be 100.
     """
     campaign = campaign_to_ten_candidates_not_sent
     for number in xrange(1, 11):
         response = requests.post(self.URL % campaign.id, headers=headers)
         assert_campaign_send(response, campaign, user_first.id, blasts_count=number,
                              blast_sends=10, total_sends=number * 10)
Example #9
0
 def test_campaign_send_to_two_candidates_with_same_email_address_in_diff_domain(
         self, headers, user_first, campaign_with_candidates_having_same_email_in_diff_domain):
     """
     User auth token is valid, campaign has one smart list associated. Smartlist has two
     candidates associated. One more candidate exists in some other domain with same email
     address. Email Campaign should be sent to 2 candidates only.
     """
     campaign = campaign_with_candidates_having_same_email_in_diff_domain
     response = requests.post(self.URL % campaign.id, headers=headers)
     assert_campaign_send(response, campaign, user_first.id)
Example #10
0
 def test_campaign_send_to_two_candidates_with_unique_email_addresses(self, headers, user_first,
                                                                      email_campaign_of_user_first):
     """
     Tests sending a campaign with one smartlist. That smartlist has, in turn,
     two candidates associated with it. Those candidates have unique email addresses.
     Campaign emails should be sent to 2 candidates so number of sends should be 2.
     """
     campaign = email_campaign_of_user_first
     response = requests.post(self.URL % campaign.id, headers=headers)
     assert_campaign_send(response, campaign, user_first.id)
Example #11
0
 def test_campaign_send_to_two_candidates_with_same_email_address_in_same_domain(self, headers, user_first,
                                                                                 email_campaign_of_user_first):
     """
     User auth token is valid, campaign has one smartlist associated. Smartlist has two
     candidates associated (with same email addresses). Email Campaign should be sent to only
     one candidate.
     """
     same_email = fake.email()
     for candidate in user_first.candidates:
         candidate.emails[0].update(address=same_email)
     response = requests.post(self.URL % email_campaign_of_user_first.id, headers=headers)
     assert_campaign_send(response, email_campaign_of_user_first, user_first.id, blast_sends=1)
     if not email_campaign_of_user_first.email_client_id:
         json_resp = response.json()
         assert str(email_campaign_of_user_first.id) in json_resp['message']
Example #12
0
 def test_campaign_send_in_test_domain(self, headers, domain_first, user_first, email_campaign_of_user_first):
     """
     Here we set user's email address to be test email account used in tests.
     We then set domain of user as test domain and send an email campaign to candidates. It should be
     received in user's inbox.
     """
     user_first.role_id = Role.get_by_name('DOMAIN_ADMIN').id
     db.session.commit()
     data = {'is_test_domain': 1}
     response = requests.patch(url=UserServiceApiUrl.DOMAIN % domain_first.id, headers=headers,
                               data=json.dumps(data))
     assert response.ok, response.text
     user_first.update(email=app.config[TalentConfigKeys.GT_GMAIL_ID])
     response = requests.post(self.URL % email_campaign_of_user_first.id, headers=headers)
     assert_campaign_send(response, email_campaign_of_user_first, user_first.id)
     retry(assert_and_delete_email, sleeptime=5, attempts=50, sleepscale=1,
           args=(email_campaign_of_user_first.subject,),
           retry_exceptions=(AssertionError, imaplib.IMAP4_SSL.error))
Example #13
0
 def test_campaign_send_with_email_client_id_using_merge_tags(self, email_campaign_with_merge_tags, user_first,
                                                              access_token_first):
     """
     This is the test for merge tags. We assert that merge tags has been successfully replaced with
     candidate's info.
     If candidate's first name is `John` and last name is `Doe`, and email body is like
     'Hello *|FIRSTNAME|* *|LASTNAME|*,', it will become 'Hello John Doe,'
     """
     expected_sends = 1
     email_campaign, candidate = email_campaign_with_merge_tags
     send_response = send_campaign_with_client_id(email_campaign, access_token_first)
     response = send_response['response']
     email_campaign_sends = send_response['response'].json()['email_campaign_sends']
     assert len(email_campaign_sends) == 1
     email_campaign_send = email_campaign_sends[0]
     for entity in ('new_text', 'new_html'):
         assert candidate['first_name'] in email_campaign_send[entity]
         assert candidate['last_name'] in email_campaign_send[entity]
         assert str(candidate['id']) in email_campaign_send[entity]  # This will be in unsubscribe URL.
     assert_campaign_send(response, email_campaign, user_first.id, expected_sends, email_client=True)
Example #14
0
 def test_campaign_send_with_email_client_id(self, send_email_campaign_by_client_id_response, user_first):
     """
     Email client can be Outlook Plugin, Browser etc.
     User auth token is valid, campaign has one smart list associated. Smartlist has two
     candidates with email address. Email Campaign should be not be sent to candidate as
     we are providing client_id. Response should be something like
         {
               "email_campaign_sends": [
             {
               "candidate_email_address": "*****@*****.**",
               "email_campaign_id": 1,
               "new_html": "email body text",
               "new_text": "<img src=\"http://127.0.0.1:8014/v1/redirect/10082954\" />\n
               <html>\n <body>\n  <h1>\n   Welcome to email campaign service\n
               </h1>\n </body>\n</html>"
             }
               ]
         }
     """
     response = send_email_campaign_by_client_id_response['response']
     campaign = send_email_campaign_by_client_id_response['campaign']
     assert_campaign_send(response, campaign, user_first.id, email_client=True)