Skip to content

Commit cfdb0e3

Browse files
committed
[IMP] fastapi_log_mail: Adapt to log collection
1 parent 0d7f4eb commit cfdb0e3

File tree

11 files changed

+44
-79
lines changed

11 files changed

+44
-79
lines changed

fastapi_log_mail/README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
===========
2-
Fastapi Log
3-
===========
1+
========================
2+
FastAPI Log notification
3+
========================
44

55
..
66
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -28,8 +28,8 @@ Fastapi Log
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
This module allows to send an email when an exception occurs in an
32-
endpoint.
31+
This module allows to create an activity when an exception is logged in
32+
a fastapi endpoint.
3333

3434
**Table of contents**
3535

@@ -39,8 +39,7 @@ endpoint.
3939
Configuration
4040
=============
4141

42-
In any endpoint that has logging enabled, insert an email template in
43-
"Error E-mail Template".
42+
Configure a fastapi endpoint as explained in ``api_log_mail``.
4443

4544
Bug Tracker
4645
===========

fastapi_log_mail/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from . import models

fastapi_log_mail/__manifest__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
{
5-
"name": "Fastapi Log",
5+
"name": "FastAPI Log notification",
66
"version": "16.0.1.0.0",
77
"license": "AGPL-3",
88
"author": "PyTech, Odoo Community Association (OCA)",
99
"maintainers": [
1010
"SirPyTech",
1111
],
1212
"website": "https://github.com/OCA/rest-framework",
13-
"summary": "Email exceptions of Endpoints.",
13+
"summary": "Notify logged exceptions.",
1414
"category": "Tools",
1515
"depends": [
1616
"fastapi_log",
17-
"mail",
17+
"api_log_mail",
1818
],
1919
"data": [
2020
"views/fastapi_endpoint_views.xml",

fastapi_log_mail/models/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

fastapi_log_mail/models/api_log.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

fastapi_log_mail/models/fastapi_endpoint.py

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
In any endpoint that has logging enabled, insert an email template in "Error E-mail Template".
1+
Configure a fastapi endpoint as explained in `api_log_mail`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This module allows to send an email when an exception occurs in an endpoint.
1+
This module allows to create an activity when an exception is logged in a fastapi endpoint.

fastapi_log_mail/static/description/index.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>Fastapi Log</title>
6+
<title>FastAPI Log notification</title>
77
<style type="text/css">
88

99
/*
@@ -360,8 +360,8 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document" id="fastapi-log">
364-
<h1 class="title">Fastapi Log</h1>
363+
<div class="document" id="fastapi-log-notification">
364+
<h1 class="title">FastAPI Log notification</h1>
365365

366366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367367
!! This file is generated by oca-gen-addon-readme !!
@@ -370,8 +370,8 @@ <h1 class="title">Fastapi Log</h1>
370370
!! source digest: sha256:ef0c0bceb8ae27bcfebaebc22e2fb4747475f2a2c60dd2d410bc40b6efee9b6a
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi_log_mail"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi_log_mail"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373-
<p>This module allows to send an email when an exception occurs in an
374-
endpoint.</p>
373+
<p>This module allows to create an activity when an exception is logged in
374+
a fastapi endpoint.</p>
375375
<p><strong>Table of contents</strong></p>
376376
<div class="contents local topic" id="contents">
377377
<ul class="simple">
@@ -387,8 +387,7 @@ <h1 class="title">Fastapi Log</h1>
387387
</div>
388388
<div class="section" id="configuration">
389389
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
390-
<p>In any endpoint that has logging enabled, insert an email template in
391-
“Error E-mail Template”.</p>
390+
<p>Configure a fastapi endpoint as explained in <tt class="docutils literal">api_log_mail</tt>.</p>
392391
</div>
393392
<div class="section" id="bug-tracker">
394393
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
# Copyright 2025 Akretion (http://www.akretion.com).
22
# @author Florian Mounier <florian.mounier@akretion.com>
3+
# Copyright 2025 Simone Rubino - PyTech
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
5+
46
import os
57
import unittest
68

7-
from odoo.addons.api_log.tests.common import CommonAPILog
89
from odoo.addons.fastapi.schemas import DemoExceptionType
9-
from odoo.addons.mail.tests.common import MailCase
10+
from odoo.addons.fastapi_log.tests.common import Common
11+
12+
from fastapi import status
1013

1114

12-
@unittest.skipIf(os.getenv("SKIP_HTTP_CASE"), "FastAPIEncryptedErrorsCase skipped")
13-
class FastAPIEncryptedErrorsCase(CommonAPILog, MailCase):
15+
@unittest.skipIf(os.getenv("SKIP_HTTP_CASE"), "TestFastapiLogMail skipped")
16+
class TestFastapiLogMail(Common):
1417
@classmethod
1518
def setUpClass(cls):
1619
super().setUpClass()
17-
cls.fastapi_demo_app = cls.env.ref("fastapi.fastapi_endpoint_demo")
18-
19-
cls.fastapi_demo_app._handle_registry_sync()
20-
cls.fastapi_demo_app.log_requests = True
21-
cls.fastapi_demo_app.fastapi_log_mail_template_id = cls.env[
22-
"mail.template"
20+
cls.fastapi_demo_app.api_log_mail_exception_activity_type_id = cls.env[
21+
"mail.activity.type"
2322
].create(
2423
{
25-
"name": "Test exception email template",
26-
"model_id": cls.env.ref("api_log.model_api_log").id,
24+
"name": "Test exception activity",
25+
"res_model": "api.log",
2726
}
2827
)
2928

30-
def test_endpoint_exception_send_email(self):
31-
"""If an endpoint has an email template,
32-
when an exception occurs an email is sent using the configured template.
29+
def test_endpoint_exception_create_activity(self):
30+
"""If an endpoint has an activity type,
31+
when an exception occurs an activity of the configured type is created.
3332
"""
3433
# Arrange
35-
mail_template = self.fastapi_demo_app.fastapi_log_mail_template_id
34+
app = self.fastapi_demo_app
35+
activity_type = app.api_log_mail_exception_activity_type_id
3636
route = (
37-
"/fastapi_demo/demo/exception?"
37+
"/fastapi_demo/test/demo/exception?"
3838
f"exception_type={DemoExceptionType.user_error.value}"
39-
"&error_message=User Error"
39+
"&error_message=An error happened"
4040
)
4141
# pre-condition
42-
self.assertTrue(mail_template)
42+
self.assertTrue(activity_type)
4343

4444
# Act
45-
with self.mock_mail_gateway():
46-
self.url_open(route, timeout=200)
45+
with self.log_capturer() as capturer:
46+
response = self.url_open(route, timeout=200)
4747

4848
# Assert
49-
sent_email = self._filter_mail()
50-
self.assertTrue(sent_email)
49+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
50+
log = capturer.records
51+
self.assertEqual(len(log), 1)
52+
self.assertTrue(log.activity_ids)

0 commit comments

Comments
 (0)