def test_edit_and_delete_email_template(driver, login_seeded_user,
                                        seeded_client):
    test_name = 'edit/delete email template test'
    go_to_templates_page(driver)
    existing_templates = [
        x.text
        for x in driver.find_elements_by_class_name('template-list-item-label')
    ]
    if len(existing_templates) == 0:
        existing_templates = [
            x.text for x in driver.find_elements_by_class_name('message-name')
        ]

    create_email_template(driver, name=test_name, content=None)
    go_to_templates_page(driver)
    current_templates = [
        x.text
        for x in driver.find_elements_by_class_name('template-list-item-label')
    ]
    if len(current_templates) == 0:
        current_templates = [
            x.text for x in driver.find_elements_by_class_name('message-name')
        ]
    assert test_name in current_templates

    delete_template(driver, test_name)
    current_templates = [
        x.text
        for x in driver.find_elements_by_class_name('template-list-item-label')
    ]
    if len(current_templates) == 0:
        current_templates = [
            x.text for x in driver.find_elements_by_class_name('message-name')
        ]
    assert current_templates == existing_templates
def test_send_email_with_placeholders_to_one_recipient(driver, seeded_client,
                                                       login_seeded_user):
    go_to_templates_page(driver)
    template_name = "email with placeholders" + str(uuid.uuid4())
    content = "Hi ((name)), Is ((email address)) your email address? We want to send you some ((things))"
    template_id = create_email_template(driver,
                                        name=template_name,
                                        content=content)

    dashboard_page = DashboardPage(driver)
    dashboard_page.go_to_dashboard_for_service(
        service_id=config['service']['id'])
    dashboard_stats_before = get_dashboard_stats(dashboard_page, 'email',
                                                 template_id)

    placeholders = send_notification_to_one_recipient(
        driver,
        template_name,
        "email",
        test=False,
        recipient_data='*****@*****.**',
        placeholders_number=2)
    assert list(placeholders[0].keys()) == ["name"]
    assert list(placeholders[1].keys()) == ["things"]

    dashboard_page.click_continue()
    notification_id = dashboard_page.get_notification_id()
    one_off_email = seeded_client.get_notification_by_id(notification_id)
    assert one_off_email.get('created_by_name') == 'Preview admin tests user'

    dashboard_page.go_to_dashboard_for_service(
        service_id=config['service']['id'])
    dashboard_stats_after = get_dashboard_stats(dashboard_page, 'email',
                                                template_id)
    assert_dashboard_stats(dashboard_stats_before, dashboard_stats_after)

    placeholders_test = send_notification_to_one_recipient(
        driver, template_name, "email", test=True, placeholders_number=2)
    assert list(placeholders_test[0].keys()) == ["name"]
    assert list(placeholders_test[1].keys()) == ["things"]

    delete_template(driver, template_name)
def test_send_sms_with_placeholders_to_one_recipient(driver, seeded_client,
                                                     login_seeded_user):
    go_to_templates_page(driver)
    template_name = "sms with placeholders" + str(uuid.uuid4())
    content = "Hi ((name)), Is ((phone number)) your mobile number? We want to send you some ((things))"
    template_id = create_sms_template(driver,
                                      name=template_name,
                                      content=content)

    dashboard_page = DashboardPage(driver)
    dashboard_page.go_to_dashboard_for_service(
        service_id=config['service']['id'])
    dashboard_stats_before = get_dashboard_stats(dashboard_page, 'sms',
                                                 template_id)

    placeholders = send_notification_to_one_recipient(
        driver,
        template_name,
        "sms",
        test=False,
        recipient_data='07700900998',
        placeholders_number=2)
    assert list(placeholders[0].keys()) == ["name"]
    assert list(placeholders[1].keys()) == ["things"]

    dashboard_page.click_continue()
    dashboard_page.go_to_dashboard_for_service(
        service_id=config['service']['id'])
    dashboard_stats_after = get_dashboard_stats(dashboard_page, 'sms',
                                                template_id)
    assert_dashboard_stats(dashboard_stats_before, dashboard_stats_after)

    placeholders_test = send_notification_to_one_recipient(
        driver, template_name, "sms", test=True, placeholders_number=2)
    assert list(placeholders_test[0].keys()) == ["name"]
    assert list(placeholders_test[1].keys()) == ["things"]

    delete_template(driver, template_name)