* fix(query): check standard field definitions Signed-off-by: Akhil Narang <me@akhilnarang.dev> * fix(postgres): fix order_by problem in pg * fix(postgres): fix order_by in get_all for _test_connection_query * fix: add check to a proper numeric fallback in _get_ifnull_fallback * test(postgres): fix pg query used in assertion in test_permission_query * fix(postgres): fix order_by in get_all for possible_link * fix(postgres): fix order_by in get_all for set_modules * fix(postgres): fix pg query count * * fix(postgres): fix order_by in get_all for ask_pass_update * fix(postgres): fix order_by statement in search_widget * fix(postgres): fix order_by in get_list for get_stats * test(postgres): normalize_sql for pg queries in test_arithmetic_operators_in_fields * test(postgres): normalize_sql for pg queries in test_field_alias_in_group_by * test(postgres): normalize_sql for pg queries in test_field_alias_permission_check * test(postgres): fix order_by statement in get_all for test_db_keywords_as_fields * test(postgres): fix order_by statement in get_all for test_prepare_select_args * fix(treeview): use 0 instead of false to check since check field is an integer * fix(postgres): fix order_by in get_all for sync_communication * fix(postgres): fix order_by in get_all for get_references_across_doctypes_by_dynamic_link_field * test(postgres): fix order_by in get_all for test_list_summary * fix(postgres): fix order_by in get_all for email queries * test(postgres): use order_by none and update assertion for postgres * fix(postgres): use ILIKE to support case insensitive search in postgres * test(test_query): update pg specific query assert to use ILIKE * test(test_query): update test_nested_filters to use ilike instead for PG * test(postgres): update pg query in assert to test updated qb query * fix(search): update query to be db-agnostic * test(postgres): normalize query for pg in test_build_match_conditions * fix(postgres): suppress ORDER BY when SELECT DISTINCT in query for postgres specific behavior * fix(postgres): suppress ORDER BY when GROUP BY is explicitly asked for pg specific behavior * test(postgres): fix test behavior for pg ORDER BY drop when used with GROUP BY * refactor: reducing noise in code by formatting code * fix(query): use Star() to handle SQL wildcard character * correctly * fix(postgres): display warning for ORDER BY fields that will be dropped --------- Signed-off-by: Akhil Narang <me@akhilnarang.dev> Co-authored-by: Akhil Narang <me@akhilnarang.dev>
88 lines
2.8 KiB
Python
88 lines
2.8 KiB
Python
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: The MIT License
|
|
|
|
import frappe
|
|
from frappe.email.doctype.email_account.email_account import EmailAccount
|
|
from frappe.email.smtp import SMTPServer
|
|
from frappe.tests import IntegrationTestCase
|
|
|
|
|
|
class TestSMTP(IntegrationTestCase):
|
|
def test_smtp_ssl_session(self):
|
|
for port in [None, 0, 465, "465"]:
|
|
make_server(port, 1, 0)
|
|
|
|
def test_smtp_tls_session(self):
|
|
for port in [None, 0, 587, "587"]:
|
|
make_server(port, 0, 1)
|
|
|
|
def test_get_email_account(self):
|
|
existing_email_accounts = frappe.get_all(
|
|
"Email Account",
|
|
fields=["name", "enable_outgoing", "default_outgoing", "append_to", "use_imap"],
|
|
)
|
|
unset_details = {"enable_outgoing": 0, "default_outgoing": 0, "append_to": None, "use_imap": 0}
|
|
for email_account in existing_email_accounts:
|
|
frappe.db.set_value("Email Account", email_account["name"], unset_details)
|
|
|
|
# remove mail_server config so that test@example.com is not created
|
|
mail_server = frappe.conf.get("mail_server")
|
|
if "mail_server" in frappe.conf:
|
|
del frappe.conf["mail_server"]
|
|
|
|
frappe.local.outgoing_email_account = {}
|
|
|
|
frappe.local.outgoing_email_account = {}
|
|
# lowest preference given to email account with default incoming enabled
|
|
create_email_account(
|
|
email_id="default_outgoing_enabled@gmail.com",
|
|
password="password",
|
|
enable_outgoing=1,
|
|
default_outgoing=1,
|
|
)
|
|
self.assertEqual(EmailAccount.find_outgoing().email_id, "default_outgoing_enabled@gmail.com")
|
|
|
|
frappe.local.outgoing_email_account = {}
|
|
# highest preference given to email account with append_to matching
|
|
create_email_account(
|
|
email_id="append_to@gmail.com",
|
|
password="password",
|
|
enable_outgoing=1,
|
|
default_outgoing=1,
|
|
append_to="ToDo",
|
|
)
|
|
self.assertEqual(EmailAccount.find_outgoing(match_by_doctype="ToDo").email_id, "append_to@gmail.com")
|
|
|
|
# add back the mail_server
|
|
frappe.conf["mail_server"] = mail_server
|
|
for email_account in existing_email_accounts:
|
|
set_details = {
|
|
"enable_outgoing": email_account["enable_outgoing"],
|
|
"default_outgoing": email_account["default_outgoing"],
|
|
"append_to": email_account["append_to"],
|
|
}
|
|
frappe.db.set_value("Email Account", email_account["name"], set_details)
|
|
|
|
|
|
def create_email_account(email_id, password, enable_outgoing, default_outgoing=0, append_to=None):
|
|
email_dict = {
|
|
"email_id": email_id,
|
|
"passsword": password,
|
|
"enable_outgoing": enable_outgoing,
|
|
"default_outgoing": default_outgoing,
|
|
"enable_incoming": 1,
|
|
"append_to": append_to,
|
|
"is_dummy_password": 1,
|
|
"smtp_server": "127.0.0.1",
|
|
"use_imap": 0,
|
|
}
|
|
|
|
email_account = frappe.new_doc("Email Account")
|
|
email_account.update(email_dict)
|
|
email_account.save()
|
|
|
|
|
|
def make_server(port, ssl, tls):
|
|
server = SMTPServer(server="smtp.gmail.com", port=port, use_ssl=ssl, use_tls=tls)
|
|
|
|
server.session
|