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
def test_unit__create_comment_request__ok__nominal_test(self): mail = Mock() mail.get_body.return_value = "CONTENT" mail.get_key.return_value = "1" mail.get_from_address.return_value = "*****@*****.**" content_info = { "author": { "avatar_url": None, "public_name": "Global manager", "user_id": 1 }, "content_id": 1, "content_type": "thread", "created": "2018-08-24T15:00:08Z", "current_revision_id": 29, "is_archived": False, "is_deleted": False, "label": "coucou", "last_modifier": { "avatar_url": None, "public_name": "Global manager", "user_id": 1 }, "modified": "2018-08-24T15:00:08Z", "parent_id": None, "raw_content": "", "show_in_ui": True, "slug": "coucou", "status": "open", "sub_content_types": ["comment"], "workspace_id": 4, } 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="******", ) mf._get_content_info = Mock() mf._get_content_info.return_value = content_info method, endpoint, body = mf._create_comment_request(mail) assert method == "POST" assert endpoint == "http://127.0.0.1:6543/api/workspaces/4/contents/1/comments" assert body == {"raw_content": "CONTENT"}
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
def test_unit__create_comment_request__ok__nominal_test(self): mail = Mock() mail.get_body.return_value = 'CONTENT' mail.get_key.return_value = '1' mail.get_from_address.return_value = '*****@*****.**' content_info = { "author": { "avatar_url": None, "public_name": "Global manager", "user_id": 1 }, "content_id": 1, "content_type": "thread", "created": "2018-08-24T15:00:08Z", "current_revision_id": 29, "is_archived": False, "is_deleted": False, "label": "coucou", "last_modifier": { "avatar_url": None, "public_name": "Global manager", "user_id": 1 }, "modified": "2018-08-24T15:00:08Z", "parent_id": None, "raw_content": "", "show_in_ui": True, "slug": "coucou", "status": "open", "sub_content_types": [ "comment" ], "workspace_id": 4 } 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='******', ) mf._get_content_info = Mock() mf._get_content_info.return_value = content_info method, endpoint, body = mf._create_comment_request(mail) assert method == 'POST' assert endpoint == 'http://127.0.0.1:6543/api/workspaces/4/contents/1/comments' # nopep8 assert body == {'raw_content': 'CONTENT'}