|
@@ -161,6 +161,44 @@ class DocumentTests(unittest.TestCase):
|
|
|
MockAdapter().search("1", document_no="R1")
|
|
MockAdapter().search("1", document_no="R1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ def test_database_email_sources_enable_recipients_and_address_drafts(self):
|
|
|
|
|
+ self.prepare()
|
|
|
|
|
+ from app.documents import identity
|
|
|
|
|
+
|
|
|
|
|
+ self.db.connection.executescript("""
|
|
|
|
|
+ ALTER TABLE dbo.Benutzer_Rolle ADD Benutzer_Email TEXT;
|
|
|
|
|
+ UPDATE dbo.Benutzer_Rolle SET Benutzer_Email=' me@example.com ' WHERE Benutzer_ID='tester';
|
|
|
|
|
+ INSERT INTO dbo.Benutzer_Rolle (Benutzer_ID, Benutzer_Email) VALUES ('tester', 'me@example.com');
|
|
|
|
|
+ INSERT INTO dbo.Benutzer_Rolle (Benutzer_ID, Benutzer_Email) VALUES ('other', 'wrong-user@example.com');
|
|
|
|
|
+ CREATE TABLE dbo.Forderungen_Liste (Client_DB TEXT, Beleg_Nr TEXT, Verursacher_Email TEXT);
|
|
|
|
|
+ INSERT INTO dbo.Forderungen_Liste VALUES ('1', 'R1', 'assignee@example.com');
|
|
|
|
|
+ INSERT INTO dbo.Forderungen_Liste VALUES ('2', 'R1', 'wrong-tenant@example.com');
|
|
|
|
|
+ """)
|
|
|
|
|
+ execute = self.db.execute
|
|
|
|
|
+
|
|
|
|
|
+ def details_and_queries(statement, values=None):
|
|
|
|
|
+ if 'AS [Kunde_offen_gesamt]' in str(statement):
|
|
|
|
|
+ result = Mock()
|
|
|
|
|
+ result.mappings.return_value.first.return_value = dict(
|
|
|
|
|
+ Verursacher_Aktuell_Benutzer_ID='assignee', Kunde_Email='', Vers_Email='')
|
|
|
|
|
+ return result
|
|
|
|
|
+ return execute(statement, values)
|
|
|
|
|
+
|
|
|
|
|
+ token = identity('dw', 'sample', '1')
|
|
|
|
|
+ with patch.object(self.db, 'execute', side_effect=details_and_queries), patch('app.documents.lookup_directory_user') as lookup:
|
|
|
|
|
+ response = self.client.get(self.base + '/recipients/' + token)
|
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
|
+ self.assertIn('An mich: me@example.com', response.text)
|
|
|
|
|
+ self.assertIn('Verursacher: assignee@example.com', response.text)
|
|
|
|
|
+ for target, expected in [('self', 'me@example.com'), ('colleague', 'assignee@example.com')]:
|
|
|
|
|
+ response = self.client.get(self.base + '/draft/' + token, params={'recipient': target})
|
|
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
|
|
+ message = BytesParser(policy=policy.default).parsebytes(response.content)
|
|
|
|
|
+ self.assertEqual(message['To'], expected)
|
|
|
|
|
+ self.assertEqual(len(list(message.iter_attachments())), 1)
|
|
|
|
|
+ lookup.assert_not_called()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class AdapterTests(unittest.TestCase):
|
|
class AdapterTests(unittest.TestCase):
|
|
|
def test_live_exact_search_missing_fields_download_and_full_iteration(self):
|
|
def test_live_exact_search_missing_fields_download_and_full_iteration(self):
|
|
|
document = SimpleNamespace(id=1, title="Test", fields=[SimpleNamespace(name="Belegnummer", value="R1")])
|
|
document = SimpleNamespace(id=1, title="Test", fields=[SimpleNamespace(name="Belegnummer", value="R1")])
|
|
@@ -199,13 +237,14 @@ class AdapterTests(unittest.TestCase):
|
|
|
self.assertNotIn("sensitive-token", json.dumps(result))
|
|
self.assertNotIn("sensitive-token", json.dumps(result))
|
|
|
|
|
|
|
|
def test_recipients_from_open_case_and_ad_override(self):
|
|
def test_recipients_from_open_case_and_ad_override(self):
|
|
|
- request = SimpleNamespace(state=SimpleNamespace(principal=SimpleNamespace(email="self@example.com")))
|
|
|
|
|
|
|
+ request = SimpleNamespace(state=SimpleNamespace(principal=SimpleNamespace(username="tester", email="self@example.com")))
|
|
|
db = Mock()
|
|
db = Mock()
|
|
|
- db.execute.return_value.mappings.return_value.first.return_value = dict(
|
|
|
|
|
|
|
+ db.execute.return_value.mappings.return_value.first.side_effect = [dict(
|
|
|
Verursacher_Aktuell_Benutzer_ID="override",
|
|
Verursacher_Aktuell_Benutzer_ID="override",
|
|
|
Kunde_Email="customer@example.com",
|
|
Kunde_Email="customer@example.com",
|
|
|
Vers_Email="insurance@example.com",
|
|
Vers_Email="insurance@example.com",
|
|
|
- )
|
|
|
|
|
|
|
+ ), None]
|
|
|
|
|
+ db.execute.return_value.mappings.return_value.fetchall.return_value = []
|
|
|
with patch(
|
|
with patch(
|
|
|
"app.documents.lookup_directory_user",
|
|
"app.documents.lookup_directory_user",
|
|
|
return_value=SimpleNamespace(email="colleague@example.com", disabled=False),
|
|
return_value=SimpleNamespace(email="colleague@example.com", disabled=False),
|
|
@@ -217,3 +256,16 @@ class AdapterTests(unittest.TestCase):
|
|
|
["self@example.com", "colleague@example.com", "customer@example.com", "insurance@example.com"],
|
|
["self@example.com", "colleague@example.com", "customer@example.com", "insurance@example.com"],
|
|
|
)
|
|
)
|
|
|
self.assertEqual(db.execute.call_args.args[1], dict(client_db="1", beleg_nr="R1"))
|
|
self.assertEqual(db.execute.call_args.args[1], dict(client_db="1", beleg_nr="R1"))
|
|
|
|
|
+
|
|
|
|
|
+ def test_missing_or_invalid_database_emails_keep_valid_session_fallback(self):
|
|
|
|
|
+ request = SimpleNamespace(state=SimpleNamespace(principal=SimpleNamespace(username='tester', email='session@example.com')))
|
|
|
|
|
+ for database_emails in [[], [{'Benutzer_Email': None}], [{'Benutzer_Email': 'invalid'}],
|
|
|
|
|
+ [{'Benutzer_Email': 'invalid'}, {'Benutzer_Email': 'db@example.com'}]]:
|
|
|
|
|
+ with self.subTest(emails=database_emails):
|
|
|
|
|
+ db = Mock()
|
|
|
|
|
+ db.execute.return_value.mappings.return_value.first.side_effect = [dict(Kunde_Email='', Vers_Email=''), None]
|
|
|
|
|
+ db.execute.return_value.mappings.return_value.fetchall.return_value = database_emails
|
|
|
|
|
+ targets = recipients(request, '1_R1', db)
|
|
|
|
|
+ expected = 'db@example.com' if len(database_emails) == 2 else 'session@example.com'
|
|
|
|
|
+ self.assertEqual(targets[0]['email'], expected)
|
|
|
|
|
+ self.assertEqual(targets[1]['email'], '')
|