Some checks failed
Server (Postgres) / Build & reinstall (setup) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (1) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (2) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (3) (push) Has been cancelled
Server (Postgres) / Python Unit Tests (4) (push) Has been cancelled
Server (Mariadb) / Build & reinstall (setup) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (1) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (2) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (3) (push) Has been cancelled
Server (Mariadb) / Python Unit Tests (4) (push) Has been cancelled
Server (Mariadb) / Coverage Wrap Up (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
Regenerate POT file (translatable strings) / Regenerate POT file (develop) (push) Has been cancelled
Regenerate POT file (translatable strings) / Regenerate POT file (version-16-hotfix) (push) Has been cancelled
Sync translations to hotfix branches / Trigger sync → version-16-hotfix (push) Has been cancelled
Create weekly release pull requests / Release (15) (push) Has been cancelled
Create weekly release pull requests / Release (16) (push) Has been cancelled
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
import frappe
|
|
|
|
from erpnext.templates.utils import get_customer_from_contact_email
|
|
from erpnext.tests.utils import ERPNextTestSuite
|
|
|
|
|
|
class TestTemplateUtils(ERPNextTestSuite):
|
|
def test_contact_email_lookup_is_case_insensitive(self):
|
|
"""send_message resolves the Opportunity party by matching Contact.email_id with `==`.
|
|
Equality is case-SENSITIVE on Postgres (the query-builder ILIKE patch only rewrites LIKE),
|
|
while MariaDB's default collation is case-insensitive. A Contact email stored as
|
|
'Case.Test@Example.com' with a lowercase sender therefore matches on MariaDB but not on
|
|
Postgres -- so the Contact-Us form links a Lead instead of the Customer. The original raw SQL
|
|
used the same `c.email_id = %s`, so MariaDB output is unchanged: this is a Postgres-only break."""
|
|
customer_name = "_Test Contact Case Customer"
|
|
if not frappe.db.exists("Customer", customer_name):
|
|
frappe.get_doc(
|
|
{
|
|
"doctype": "Customer",
|
|
"customer_name": customer_name,
|
|
"customer_group": "_Test Customer Group",
|
|
"territory": "_Test Territory",
|
|
}
|
|
).insert(ignore_permissions=True)
|
|
|
|
frappe.get_doc(
|
|
{
|
|
"doctype": "Contact",
|
|
"first_name": "Case Test Contact",
|
|
"email_ids": [{"email_id": "Case.Test@Example.com", "is_primary": 1}],
|
|
"links": [{"link_doctype": "Customer", "link_name": customer_name}],
|
|
}
|
|
).insert(ignore_permissions=True)
|
|
|
|
# lowercase sender vs the stored mixed-case Contact email
|
|
matched = get_customer_from_contact_email("case.test@example.com")
|
|
self.assertTrue(matched, "Contact email lookup found no Customer for a case-differing sender")
|
|
self.assertEqual(matched[0][0], customer_name)
|