mirror of https://github.com/kianby/stacosys
remove IMAP part
parent
1ae37ff18e
commit
7f2ff74ebe
@ -1,23 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from enum import Enum
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
|
||||||
|
|
||||||
|
|
||||||
class Template(Enum):
|
|
||||||
DROP_COMMENT = "drop_comment"
|
|
||||||
APPROVE_COMMENT = "approve_comment"
|
|
||||||
NEW_COMMENT = "new_comment"
|
|
||||||
NOTIFY_MESSAGE = "notify_message"
|
|
||||||
RSS_TITLE_MESSAGE = "rss_title_message"
|
|
||||||
WEB_COMMENT_APPROVAL = "web_comment_approval"
|
|
||||||
|
|
||||||
|
|
||||||
class Templater:
|
|
||||||
def __init__(self, template_path):
|
|
||||||
self._env = Environment(loader=FileSystemLoader(template_path))
|
|
||||||
|
|
||||||
def get_template(self, lang, template: Template):
|
|
||||||
return self._env.get_template(lang + "/" + template.value + ".tpl")
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
Hi,
|
|
||||||
|
|
||||||
The comment should be published soon. It has been approved.
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
||||||
|
|
||||||
|
|
||||||
{{ original }}
|
|
@ -1,9 +0,0 @@
|
|||||||
Hi,
|
|
||||||
|
|
||||||
The comment will not be published. It has been dropped.
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
||||||
|
|
||||||
|
|
||||||
{{ original }}
|
|
@ -1,16 +0,0 @@
|
|||||||
Hi,
|
|
||||||
|
|
||||||
A new comment has been submitted for post {{ url }}
|
|
||||||
|
|
||||||
You have two choices:
|
|
||||||
- reject the comment by replying NO (or no),
|
|
||||||
- accept the comment by sending back the email as it is.
|
|
||||||
|
|
||||||
If you choose the latter option, Stacosys is going to publish the commennt.
|
|
||||||
|
|
||||||
Please find comment details below:
|
|
||||||
|
|
||||||
{{ comment }}
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
@ -1 +0,0 @@
|
|||||||
New comment
|
|
@ -1 +0,0 @@
|
|||||||
{{ site }} : comments
|
|
@ -1,9 +0,0 @@
|
|||||||
Bonjour,
|
|
||||||
|
|
||||||
Le commentaire sera bientôt publié. Il a été approuvé.
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
||||||
|
|
||||||
|
|
||||||
{{ original }}
|
|
@ -1,9 +0,0 @@
|
|||||||
Bonjour,
|
|
||||||
|
|
||||||
Le commentaire ne sera pas publié. Il a été rejeté.
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
||||||
|
|
||||||
|
|
||||||
{{ original }}
|
|
@ -1,16 +0,0 @@
|
|||||||
Bonjour,
|
|
||||||
|
|
||||||
Un nouveau commentaire a été posté pour l'article {{ url }}
|
|
||||||
|
|
||||||
Vous avez deux réponses possibles :
|
|
||||||
- rejeter le commentaire en répondant NO (ou no),
|
|
||||||
- accepter le commentaire en renvoyant cet email tel quel.
|
|
||||||
|
|
||||||
Si cette dernière option est choisie, Stacosys publiera le commentaire très bientôt.
|
|
||||||
|
|
||||||
Voici les détails concernant le commentaire :
|
|
||||||
|
|
||||||
{{ comment }}
|
|
||||||
|
|
||||||
--
|
|
||||||
Stacosys
|
|
@ -1 +0,0 @@
|
|||||||
Nouveau commentaire
|
|
@ -1 +0,0 @@
|
|||||||
{{ site }} : commentaires
|
|
@ -1,33 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: UTF-8 -*-
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
import unittest
|
|
||||||
from email.header import Header
|
|
||||||
from email.message import Message
|
|
||||||
|
|
||||||
from stacosys.core import imap
|
|
||||||
|
|
||||||
|
|
||||||
class ImapTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_utf8_decode(self):
|
|
||||||
h = Header(s="Chez Darty vous avez re\udcc3\udca7u un nouvel aspirateur Vacuum gratuit jl8nz",
|
|
||||||
charset="unknown-8bit")
|
|
||||||
decoded = imap._email_non_ascii_to_uft8(h)
|
|
||||||
self.assertEqual(decoded, "Chez Darty vous avez reçu un nouvel aspirateur Vacuum gratuit jl8nz")
|
|
||||||
|
|
||||||
def test_parse_date(self):
|
|
||||||
now = datetime.datetime.now()
|
|
||||||
self.assertGreaterEqual(imap._parse_date(None), now)
|
|
||||||
parsed = imap._parse_date("Wed, 8 Dec 2021 20:05:20 +0100")
|
|
||||||
self.assertEqual(parsed.day, 8)
|
|
||||||
self.assertEqual(parsed.month, 12)
|
|
||||||
self.assertEqual(parsed.year, 2021)
|
|
||||||
# do not compare hours. don't care about timezone
|
|
||||||
|
|
||||||
def test_to_plain_text_content(self):
|
|
||||||
msg = Message()
|
|
||||||
payload = b"non\r\n\r\nLe 08/12/2021 \xc3\xa0 20:04, kianby@free.fr a \xc3\xa9crit\xc2\xa0:\r\n> Bonjour,\r\n>\r\n> Un nouveau commentaire a \xc3\xa9t\xc3\xa9 post\xc3\xa9 pour l'article /2021/rester-discret-sur-github//\r\n>\r\n> Vous avez deux r\xc3\xa9ponses possibles :\r\n> - rejeter le commentaire en r\xc3\xa9pondant NO (ou no),\r\n> - accepter le commentaire en renvoyant cet email tel quel.\r\n>\r\n> Si cette derni\xc3\xa8re option est choisie, Stacosys publiera le commentaire tr\xc3\xa8s bient\xc3\xb4t.\r\n>\r\n> Voici les d\xc3\xa9tails concernant le commentaire :\r\n>\r\n> author: ET Rate\r\n> site:\r\n> date: 2021-12-08 20:03:58\r\n> url: /2021/rester-discret-sur-github//\r\n>\r\n> gfdgdgf\r\n>\r\n>\r\n> --\r\n> Stacosys\r\n"
|
|
||||||
msg.set_payload(payload, "UTF-8")
|
|
||||||
self.assertTrue(imap._to_plain_text_content(msg))
|
|
@ -1,52 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: UTF-8 -*-
|
|
||||||
|
|
||||||
import os
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from stacosys.core.templater import Templater, Template
|
|
||||||
|
|
||||||
|
|
||||||
class TemplateTestCase(unittest.TestCase):
|
|
||||||
|
|
||||||
def get_template_content(self, lang, template_name, **kwargs):
|
|
||||||
current_path = os.path.dirname(__file__)
|
|
||||||
template_path = os.path.abspath(os.path.join(current_path, "../stacosys/templates"))
|
|
||||||
template = Templater(template_path).get_template(lang, template_name)
|
|
||||||
return template.render(kwargs)
|
|
||||||
|
|
||||||
def test_approve_comment(self):
|
|
||||||
content = self.get_template_content("fr", Template.APPROVE_COMMENT, original="[texte]")
|
|
||||||
self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire sera bientôt publié."))
|
|
||||||
self.assertTrue(content.endswith("[texte]"))
|
|
||||||
content = self.get_template_content("en", Template.APPROVE_COMMENT, original="[texte]")
|
|
||||||
self.assertTrue(content.startswith("Hi,\n\nThe comment should be published soon."))
|
|
||||||
self.assertTrue(content.endswith("[texte]"))
|
|
||||||
|
|
||||||
def test_drop_comment(self):
|
|
||||||
content = self.get_template_content("fr", Template.DROP_COMMENT, original="[texte]")
|
|
||||||
self.assertTrue(content.startswith("Bonjour,\n\nLe commentaire ne sera pas publié."))
|
|
||||||
self.assertTrue(content.endswith("[texte]"))
|
|
||||||
content = self.get_template_content("en", Template.DROP_COMMENT, original="[texte]")
|
|
||||||
self.assertTrue(content.startswith("Hi,\n\nThe comment will not be published."))
|
|
||||||
self.assertTrue(content.endswith("[texte]"))
|
|
||||||
|
|
||||||
def test_new_comment(self):
|
|
||||||
content = self.get_template_content("fr", Template.NEW_COMMENT, comment="[comment]")
|
|
||||||
self.assertTrue(content.startswith("Bonjour,\n\nUn nouveau commentaire a été posté"))
|
|
||||||
self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
|
|
||||||
content = self.get_template_content("en", Template.NEW_COMMENT, comment="[comment]")
|
|
||||||
self.assertTrue(content.startswith("Hi,\n\nA new comment has been submitted"))
|
|
||||||
self.assertTrue(content.endswith("[comment]\n\n--\nStacosys"))
|
|
||||||
|
|
||||||
def test_notify_message(self):
|
|
||||||
content = self.get_template_content("fr", Template.NOTIFY_MESSAGE)
|
|
||||||
self.assertEqual("Nouveau commentaire", content)
|
|
||||||
content = self.get_template_content("en", Template.NOTIFY_MESSAGE)
|
|
||||||
self.assertEqual("New comment", content)
|
|
||||||
|
|
||||||
def test_rss_title(self):
|
|
||||||
content = self.get_template_content("fr", Template.RSS_TITLE_MESSAGE, site="[site]")
|
|
||||||
self.assertEqual("[site] : commentaires", content)
|
|
||||||
content = self.get_template_content("en", Template.RSS_TITLE_MESSAGE, site="[site]")
|
|
||||||
self.assertEqual("[site] : comments", content)
|
|
Loading…
Reference in New Issue