<commit_before>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
<commit_msg>fix archive resource unit test<commit_after>from twisted.trial 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'
        idents = ['1', '2']
        content = mock()
        when(content).read().thenReturn(json.dumps({'idents': ['1', '2']}))

        d1 = defer.Deferred()
        d1.callback(None)
        when(self.mail_service).archive_mail('1').thenReturn(d1)
        d2 = defer.Deferred()
        d2.callback(None)
        when(self.mail_service).archive_mail('2').thenReturn(d2)

        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

{'fraction_non_alphanumeric': 0.11436829066886871, 'fraction_numerical': 0.008257638315441783, 'mean_word_length': 3.437728937728938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3516633', 'n_tokens_mistral': 717, 'n_tokens_neox': 686, 'n_words': 131}