# Path: adsft/app.py
# class ADSFulltextCelery(ADSCelery):
# 
# Path: adsft/tasks.py
# def task_check_if_extract(message):
# def task_extract(message):
#     def task_extract_grobid(message):
# def task_output_results(msg):
# def task_identify_facilities(message):
# 
# Path: adsft/checker.py
# def file_last_modified_time(file_input):
# def create_meta_path(dict_input, extract_path):
# def meta_output_exists(file_input, extract_path):
# def load_meta_file(file_input, extract_path):
# def meta_needs_update(dict_input, meta_content,
#                       extract_path):
# def check_if_extract(message_list, extract_path):
#     NEEDS_UPDATE = ["MISSING_FULL_TEXT", "DIFFERING_FULL_TEXT", "STALE_CONTENT",
#                     "STALE_META", "NOT_EXTRACTED_BEFORE", "FORCE_TO_EXTRACT",
#                     "FORCE_TO_SEND"]


import sys
import os
import json
import unittest
import httpretty
from mock import patch
from adsft import app, tasks, checker
from adsmsg import FulltextUpdate
    def test_task_output_results(self):
        with patch('adsft.app.ADSFulltextCelery.forward_message', return_value=None) as forward_message:
            msg = {
                    'bibcode': 'fta',
                    'body': 'Introduction\nTHIS IS AN INTERESTING TITLE\n'
                    }
            tasks.task_output_results(msg)
            self.assertTrue(forward_message.called)
            actual = forward_message.call_args[0][0]
            #self.assertEqual(u'Introduction\n\nTHIS IS AN INTERESTING TITLE\n', actual['fulltext'])
            self.assertTrue(isinstance(actual, FulltextUpdate))
            self.assertEqual(actual.bibcode, msg['bibcode'])
            self.assertEqual(actual.body, msg['body'])

    def test_task_identify_facilities(self):

        with patch('adsft.writer.write_file', return_value=None) as task_write_text:
            msg = {
                    'bibcode': 'fta',
                    'file_format': 'pdf',
                    'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                    'acknowledgements': 'We thank the Alma team.',
                    }

            with patch('adsft.checker.load_meta_file', return_value=msg) as load_meta:
                msg = {
                        'bibcode': 'fta',
                        'file_format': 'pdf',
                        'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                        'acknowledgements': 'We thank the Alma team.',

# Path: adsft/app.py
# class ADSFulltextCelery(ADSCelery):
# 
# Path: adsft/tasks.py
# def task_check_if_extract(message):
# def task_extract(message):
#     def task_extract_grobid(message):
# def task_output_results(msg):
# def task_identify_facilities(message):
# 
# Path: adsft/checker.py
# def file_last_modified_time(file_input):
# def create_meta_path(dict_input, extract_path):
# def meta_output_exists(file_input, extract_path):
# def load_meta_file(file_input, extract_path):
# def meta_needs_update(dict_input, meta_content,
#                       extract_path):
# def check_if_extract(message_list, extract_path):
#     NEEDS_UPDATE = ["MISSING_FULL_TEXT", "DIFFERING_FULL_TEXT", "STALE_CONTENT",
#                     "STALE_META", "NOT_EXTRACTED_BEFORE", "FORCE_TO_EXTRACT",
#                     "FORCE_TO_SEND"]


# Path: adsft/tests/test_tasks.py
import sys
import os
import json
import unittest
import httpretty
from mock import patch
from adsft import app, tasks, checker
from adsmsg import FulltextUpdate

    def test_task_output_results(self):
        with patch('adsft.app.ADSFulltextCelery.forward_message', return_value=None) as forward_message:
            msg = {
                    'bibcode': 'fta',
                    'body': 'Introduction\nTHIS IS AN INTERESTING TITLE\n'
                    }
            tasks.task_output_results(msg)
            self.assertTrue(forward_message.called)
            actual = forward_message.call_args[0][0]
            #self.assertEqual(u'Introduction\n\nTHIS IS AN INTERESTING TITLE\n', actual['fulltext'])
            self.assertTrue(isinstance(actual, FulltextUpdate))
            self.assertEqual(actual.bibcode, msg['bibcode'])
            self.assertEqual(actual.body, msg['body'])

    def test_task_identify_facilities(self):

        with patch('adsft.writer.write_file', return_value=None) as task_write_text:
            msg = {
                    'bibcode': 'fta',
                    'file_format': 'pdf',
                    'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                    'acknowledgements': 'We thank the Alma team.',
                    }

            with patch('adsft.checker.load_meta_file', return_value=msg) as load_meta:
                msg = {
                        'bibcode': 'fta',
                        'file_format': 'pdf',
                        'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                        'acknowledgements': 'We thank the Alma team.',

                        'fulltext': 'Introduction\nTHIS IS AN INTERESTING TITLE\n'