def create_data_for_campaign_creation_with_all_parameters( smartlist_id, subject, campaign_name=fake.name()): """ This function returns the all data to create an email campaign :param smartlist_id: Id of smartlist :param subject: Subject of campaign :param campaign_name: Name of campaign """ email_from = '*****@*****.**' reply_to = fake.safe_email() body_text = fake.sentence() description = fake.paragraph() body_html = "<html><body><h1>%s</h1></body></html>" % body_text start_datetime = DatetimeUtils.to_utc_str(datetime.utcnow() + timedelta(minutes=20)) end_datetime = DatetimeUtils.to_utc_str(datetime.utcnow() + timedelta(minutes=40)) return { 'name': campaign_name, 'from': email_from, 'reply_to': reply_to, 'description': description, 'body_text': body_text, 'subject': subject, 'body_html': body_html, 'frequency_id': Frequency.ONCE, 'list_ids': [smartlist_id], 'start_datetime': start_datetime, 'end_datetime': end_datetime }
def test_creation_with_non_existing_folder_id( self, access_token_other_for_email_templates): """ This tries to create an email template with non-existing template_folder_id. It should result in resource not found error. """ non_existing_folder_id = CampaignsTestsHelpers.get_non_existing_id( EmailTemplateFolder) template_data = dict(name=fake.name(), body_html=EMAIL_TEMPLATE_BODY, template_folder_id=non_existing_folder_id) CampaignsTestsHelpers.request_for_resource_not_found_error( self.HTTP_METHOD, self.URL, access_token_other_for_email_templates, template_data, expected_error_code=TEMPLATE_FOLDER_NOT_FOUND[1])
def test_creation_without_required_fields( self, access_token_first_for_email_templates): """ Test for creating email template without passing required fields. The response should be Bad Request - 400 because we are requesting to create an email template without passing the appropriate value for template name. """ data = dict(name=fake.name(), body_html=EMAIL_TEMPLATE_BODY) for key, value in data.iteritems(): missing_data = data.copy() del missing_data[key] response = CampaignsTestsHelpers.request_with_invalid_input( self.HTTP_METHOD, self.URL, access_token_first_for_email_templates, missing_data, expected_error_code=MISSING_FIELD[1]) assert key in response.json()['error']['message']
def create_email_campaign_in_db(user_id, add_subject=True): """ This creates an email campaign for given user """ email_campaign = EmailCampaign( name=fake.name(), user_id=user_id, is_hidden=0, subject='{}-{}'.format('Test campaign created in db', fake.uuid4()[0:8]) if add_subject else '', description=fake.paragraph(), _from=TEST_EMAIL_ID, reply_to=TEST_EMAIL_ID, body_text=fake.sentence(), body_html="<html><body><a href=%s>Email campaign test</a></body></html>" % fake.url(), ) EmailCampaign.save(email_campaign) return email_campaign
def test_creation_with_invalid_data_types( self, access_token_first_for_email_templates): """ This tries to create an email template with invalid string value of fields `name` and `body_html`, invalid boolean value for `is_immutable` and invalid integer value for `template_folder_id`. It should result in invalid usage error. """ data = dict(name=fake.name(), body_html=EMAIL_TEMPLATE_BODY, template_folder_id=fake.random_int(), is_immutable=0) for field in ('name', 'body_html'): CampaignsTestsHelpers.request_with_invalid_string( self.HTTP_METHOD, self.URL, access_token_first_for_email_templates, data, field=field, expected_error_code=INVALID_INPUT[1]) CampaignsTestsHelpers.request_with_invalid_integer( self.HTTP_METHOD, self.URL, access_token_first_for_email_templates, data, field='template_folder_id', expected_error_code=INVALID_INPUT[1]) del data['template_folder_id'] CampaignsTestsHelpers.request_with_invalid_boolean( self.HTTP_METHOD, self.URL, access_token_first_for_email_templates, data.copy(), field='is_immutable', expected_error_code=INVALID_INPUT[1])
def test_creation_invalid_values_of_optional_fields( self, access_token_first_for_email_templates): template_data = dict(name=fake.name(), body_html=EMAIL_TEMPLATE_BODY)
'from': fake.safe_email(), 'reply_to': fake.safe_email(), 'body_text': fake.sentence(), 'start_datetime': DatetimeUtils.to_utc_str(datetime.utcnow() + timedelta(minutes=20)), 'end_datetime': DatetimeUtils.to_utc_str(datetime.utcnow() + timedelta(minutes=40)) }] SPECIAL_CHARACTERS = '!@#$%^&*()_+' TEST_MAIL_DATA = { "subject": "Test Email-%s-%s" % (fake.uuid4()[0:8], SPECIAL_CHARACTERS), "from": fake.name(), "body_html": "<html><body><h1>Welcome to email campaign service " "<a href=https://www.github.com>Github</a></h1></body></html>", "body_text": fake.sentence() + fake.uuid4() + SPECIAL_CHARACTERS, "email_address_list": [app.config[TalentConfigKeys.GT_GMAIL_ID]], "reply_to": fake.safe_email() } class EmailCampaignTypes(object): """ This defines 2 types of email-campaigns """ WITH_CLIENT = 'with_client' WITHOUT_CLIENT = 'without_client'