diff options
-rw-r--r-- | service/pixelated/resources/mails_resource.py | 1 | ||||
-rw-r--r-- | service/test/unit/resources/test_archive_resource.py | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index f65041f5..5b5335b9 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -95,6 +95,7 @@ class MailsRecoverResource(Resource): class MailsArchiveResource(Resource): + isLeaf = True def __init__(self, mail_service): Resource.__init__(self) diff --git a/service/test/unit/resources/test_archive_resource.py b/service/test/unit/resources/test_archive_resource.py new file mode 100644 index 00000000..28078222 --- /dev/null +++ b/service/test/unit/resources/test_archive_resource.py @@ -0,0 +1,32 @@ +import unittest +import json +from mockito import mock, when, verify +from test.unit.resources import DummySite +from twisted.web.test.requesthelper import DummyRequest +from pixelated.resources.mails_resource import MailsArchiveResource +from twisted.internet import defer + + +class TestArchiveResource(unittest.TestCase): + def setUp(self): + self.mail_service = mock() + self.web = DummySite(MailsArchiveResource(self.mail_service)) + + def test_render_POST_should_archive_mails(self): + request = DummyRequest(['/mails/archive']) + request.method = 'POST' + content = mock() + when(content).read().thenReturn(json.dumps({'idents': ['1', '2']})) + + when(self.mail_service).archive_mail('1').thenReturn(defer.Deferred()) + when(self.mail_service).archive_mail('2').thenReturn(defer.Deferred()) + + request.content = content + d = self.web.get(request) + + def assert_response(_): + verify(self.mail_service).archive_mail('1') + verify(self.mail_service).archive_mail('2') + + d.addCallback(assert_response) + return d |