Ejemplo n.º 1
0
    def test_unit__send_request__ok__nominal_case(self):
        content_json = {
            "author": {
                "avatar_url": None,
                "public_name": "John Doe",
                "user_id": 3
            },
            "content_id": 2,
            "created": "2018-08-27T12:12:23.807Z",
            "parent_id": 1,
            "raw_content": "<p>This is just an html comment !</p>",
        }
        responses.add(
            responses.POST,
            "http://127.0.0.1:6543/api/workspaces/4/contents/1/comments",
            status=200,
            json=content_json,
        )
        mf = MailFetcher(
            host="host_imap",
            port="993",
            use_ssl=True,
            password="******",
            folder="INBOX",
            use_idle=True,
            use_html_parsing=True,
            use_txt_parsing=True,
            lockfile_path="email_fetcher.lock",
            api_base_url="http://127.0.0.1:6543/api/",
            burst=True,
            api_key="apikey",
            connection_max_lifetime=60,
            heartbeat=60,
            reply_to_pattern="",
            references_pattern="",
            user="******",
        )
        imapc_mock = MagicMock()
        imapc_mock_add_flags = MagicMock()
        imapc_mock.add_flags = imapc_mock_add_flags
        email_mock = MagicMock()
        auth_headers = {
            "Tracim-Api-Key": "apikey",
            "Tracim-Api-Login": "******"
        }
        header_mock = Mock()
        header_mock.return_value = auth_headers
        mf._get_auth_headers = header_mock
        mf._send_request(
            endpoint=
            "http://127.0.0.1:6543/api/workspaces/4/contents/1/comments",
            json_body_dict={"raw_content": "CONTENT"},
            method="POST",
            imapc=imapc_mock,
            mail=email_mock,
        )

        assert imapc_mock_add_flags.call_count == 2
Ejemplo n.º 2
0
    def test_unit__send_request__ok__nominal_case(self):
        content_json = {
          "author": {
            "avatar_url": None,
            "public_name": "John Doe",
            "user_id": 3
          },
          "content_id": 2,
          "created": "2018-08-27T12:12:23.807Z",
          "parent_id": 1,
          "raw_content": "<p>This is just an html comment !</p>"
        }
        responses.add(
            responses.POST,
            'http://127.0.0.1:6543/api/workspaces/4/contents/1/comments',
            status=200,
            json=content_json
        )
        mf = MailFetcher(
            host='host_imap',
            port='993',
            use_ssl=True,
            password='******',
            folder='INBOX',
            use_idle=True,
            use_html_parsing=True,
            use_txt_parsing=True,
            lockfile_path='email_fetcher.lock',
            api_base_url='http://127.0.0.1:6543/api/',
            burst=True,
            api_key='apikey',
            connection_max_lifetime=60,
            heartbeat=60,
            reply_to_pattern='',
            references_pattern='',
            user='******',
        )
        imapc_mock = MagicMock()
        imapc_mock_add_flags = MagicMock()
        imapc_mock.add_flags = imapc_mock_add_flags
        email_mock = MagicMock()
        auth_headers = {
            'Tracim-Api-Key': 'apikey',
            'Tracim-Api-Login': '******'
        }
        header_mock = Mock()
        header_mock.return_value = auth_headers
        mf._get_auth_headers = header_mock
        mf._send_request(
            endpoint='http://127.0.0.1:6543/api/workspaces/4/contents/1/comments',  # nopep8
            json_body_dict={'raw_content': 'CONTENT'},
            method='POST',
            imapc=imapc_mock,
            mail=email_mock,
        )

        assert imapc_mock_add_flags.call_count == 2
Ejemplo n.º 3
0
 def test_unit__notify_tracim(self):
     mf = MailFetcher(
         host='host_imap',
         port='993',
         use_ssl=True,
         password='******',
         folder='INBOX',
         use_idle=True,
         use_html_parsing=True,
         use_txt_parsing=True,
         lockfile_path='email_fetcher.lock',
         api_base_url='http://127.0.0.1:6543/api/',
         burst=True,
         api_key='apikey',
         connection_max_lifetime=60,
         heartbeat=60,
         reply_to_pattern='',
         references_pattern='',
         user='******',
     )
     imapc_mock = MagicMock()
     imapc_mock_add_flags = MagicMock()
     imapc_mock.add_flags = imapc_mock_add_flags
     mail = Mock()
     mail.get_body.return_value = 'CONTENT'
     mail.get_key.return_value = '1'
     mail.get_from_address.return_value = '*****@*****.**'
     mail2 = Mock()
     mail2.get_body.return_value = 'CONTENT2'
     mail2.get_key.return_value = '2'
     mail2.get_from_address.return_value = '*****@*****.**'
     mails = [mail, mail2]
     mf._send_request = Mock()
     mf._create_comment_request = Mock()
     mf._create_comment_request.side_effect = [
         ('POST',
         'http://127.0.0.1:6543/api/workspaces/4/contents/1/comments',
          {'raw_content': 'CONTENT'},
         ),
         ('POST',
          'http://127.0.0.1:6543/api/workspaces/4/contents/2/comments',
          {'raw_content': 'CONTENT2'},
          ),
     ]
     mf._notify_tracim(mails=mails, imapc=imapc_mock)
     args = {
         'mail': mail,
         'imapc': imapc_mock,
         'endpoint': 'http://127.0.0.1:6543/api/workspaces/4/contents/1/comments',  # nopep8
         'json_body_dict': {'raw_content': 'CONTENT'},
         'method': 'POST',
     }
     args2 = {
         'mail': mail,
         'imapc': imapc_mock,
         'endpoint': 'http://127.0.0.1:6543/api/workspaces/4/contents/2/comments',  # nopep8
         'json_body_dict': {'raw_content': 'CONTENT2'},
         'method': 'POST',
     }
     assert mf._send_request.call_count == 2
Ejemplo n.º 4
0
 def test_unit__notify_tracim(self):
     mf = MailFetcher(
         host="host_imap",
         port="993",
         use_ssl=True,
         password="******",
         folder="INBOX",
         use_idle=True,
         use_html_parsing=True,
         use_txt_parsing=True,
         lockfile_path="email_fetcher.lock",
         api_base_url="http://127.0.0.1:6543/api/",
         burst=True,
         api_key="apikey",
         connection_max_lifetime=60,
         heartbeat=60,
         reply_to_pattern="",
         references_pattern="",
         user="******",
     )
     imapc_mock = MagicMock()
     imapc_mock_add_flags = MagicMock()
     imapc_mock.add_flags = imapc_mock_add_flags
     mail = Mock()
     mail.get_body.return_value = "CONTENT"
     mail.get_key.return_value = "1"
     mail.get_from_address.return_value = "*****@*****.**"
     mail2 = Mock()
     mail2.get_body.return_value = "CONTENT2"
     mail2.get_key.return_value = "2"
     mail2.get_from_address.return_value = "*****@*****.**"
     mails = [mail, mail2]
     mf._send_request = Mock()
     mf._create_comment_request = Mock()
     mf._create_comment_request.side_effect = [
         (
             "POST",
             "http://127.0.0.1:6543/api/workspaces/4/contents/1/comments",
             {
                 "raw_content": "CONTENT"
             },
         ),
         (
             "POST",
             "http://127.0.0.1:6543/api/workspaces/4/contents/2/comments",
             {
                 "raw_content": "CONTENT2"
             },
         ),
     ]
     mf._notify_tracim(mails=mails, imapc=imapc_mock)
     assert mf._send_request.call_count == 2