Get emails from config
This commit is contained in:
parent
fde0703621
commit
1d0f011171
|
@ -0,0 +1,5 @@
|
|||
[masonde_001]
|
||||
email = email@fqdn
|
||||
email@fqdn.co.uk
|
||||
masonde_001@fqdn
|
||||
|
23
papi/main.py
23
papi/main.py
|
@ -1,4 +1,6 @@
|
|||
from typing import Optional, List
|
||||
from configparser import ConfigParser
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from fastapi import FastAPI, Request, Body, Depends
|
||||
|
@ -21,6 +23,21 @@ notifications = defaultdict(list)
|
|||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
conf = ConfigParser()
|
||||
conf.read("conf_notifications.ini")
|
||||
|
||||
|
||||
def sondeid2notifsemails(idsonde, mapping=conf):
|
||||
try:
|
||||
section = mapping[idsonde]
|
||||
except KeyError:
|
||||
raise KeyError(f"{idsonde} non trouvé dans {list(mapping.keys())}")
|
||||
|
||||
mails = section["email"]
|
||||
if isinstance(mails, str):
|
||||
mails = [x.strip() for x in mails.split("\n")]
|
||||
return mails
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
|
@ -80,8 +97,12 @@ def list_notification(idsonde: str):
|
|||
@app.get("/notifications/{idsonde}/text")
|
||||
def list_notification_as_text(idsonde: str):
|
||||
content = notifications[idsonde][-1]
|
||||
recipients = sondeid2notifsemails(idsonde)
|
||||
changements = content["changes"]
|
||||
status = content["status"]
|
||||
|
||||
return
|
||||
data = {"recipients": recipients, "changements": changements, "status": status}
|
||||
return data
|
||||
|
||||
|
||||
@app.post("/sonde/{idsonde}/")
|
||||
|
|
|
@ -149,11 +149,11 @@ def test_onchange_notification():
|
|||
|
||||
|
||||
def test_template_rendering():
|
||||
idsonde = "masonde_histo"
|
||||
idsonde = "masonde_001"
|
||||
notifs_text = client.get(f"/notifications/{idsonde}/text")
|
||||
assert notifs_text.ok
|
||||
content = notifs_text
|
||||
assert "contenu" in content.text.lower()
|
||||
assert f"{idsonde}@fqdn" in content.text.lower()
|
||||
|
||||
|
||||
class CodeCoverageTestCase(TestCase):
|
||||
|
|
Loading…
Reference in New Issue