# 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
                        'provider': 'MNRAS'}
            with patch.object(tasks.task_output_results, 'delay', return_value=None) as task_output_results:
                with patch.object(tasks.task_identify_facilities, 'delay', return_value=None) as identify_facilities:
                    tasks.task_extract(msg)
                    self.assertTrue(task_write_text.called)
                    self.assertTrue(identify_facilities.called)
                    actual = task_write_text.call_args[0][0]

                    self.assertEqual(u'I. INTRODUCTION INTRODUCTION GOES HERE Manual Entry TABLE I. TEXT a NOTES a TEXT\nAPPENDIX: APPENDIX TITLE GOES HERE APPENDIX CONTENT', actual['fulltext'])
                    self.assertEqual(u'Acknowledgments WE ACKNOWLEDGE.', actual['acknowledgements'])
                    self.assertEqual([u'ADS/Sa.CXO#Obs/11458'], actual['dataset'])
                    self.assertTrue(task_output_results.called)


    def test_task_extract_pdf(self):
        if self.grobid_service is not None:
            httpretty.enable()
            expected_grobid_fulltext = "<hello/>"
            httpretty.register_uri(httpretty.POST, self.grobid_service,
                           body=expected_grobid_fulltext,
                           status=200)
        with patch('adsft.writer.write_content', return_value=None) as task_write_text:
            msg = {'bibcode': 'fta', 'file_format': 'pdf',
                        'index_date': '2017-06-30T22:45:47.800112Z',
                        'UPDATE': 'NOT_EXTRACTED_BEFORE',
                        'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                        'ft_source': '{}/tests/test_integration/stub_data/full_test.pdf'.format(self.proj_home),
                        'provider': 'MNRAS'}
            with patch.object(tasks.task_identify_facilities, 'delay', return_value=None) as identify_facilities:
                with patch.object(tasks.task_output_results, 'delay', return_value=None) as task_output_results:

# 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

                        'provider': 'MNRAS'}
            with patch.object(tasks.task_output_results, 'delay', return_value=None) as task_output_results:
                with patch.object(tasks.task_identify_facilities, 'delay', return_value=None) as identify_facilities:
                    tasks.task_extract(msg)
                    self.assertTrue(task_write_text.called)
                    self.assertTrue(identify_facilities.called)
                    actual = task_write_text.call_args[0][0]

                    self.assertEqual(u'I. INTRODUCTION INTRODUCTION GOES HERE Manual Entry TABLE I. TEXT a NOTES a TEXT\nAPPENDIX: APPENDIX TITLE GOES HERE APPENDIX CONTENT', actual['fulltext'])
                    self.assertEqual(u'Acknowledgments WE ACKNOWLEDGE.', actual['acknowledgements'])
                    self.assertEqual([u'ADS/Sa.CXO#Obs/11458'], actual['dataset'])
                    self.assertTrue(task_output_results.called)


    def test_task_extract_pdf(self):
        if self.grobid_service is not None:
            httpretty.enable()
            expected_grobid_fulltext = "<hello/>"
            httpretty.register_uri(httpretty.POST, self.grobid_service,
                           body=expected_grobid_fulltext,
                           status=200)
        with patch('adsft.writer.write_content', return_value=None) as task_write_text:
            msg = {'bibcode': 'fta', 'file_format': 'pdf',
                        'index_date': '2017-06-30T22:45:47.800112Z',
                        'UPDATE': 'NOT_EXTRACTED_BEFORE',
                        'meta_path': u'{}/ft/a/meta.json'.format(self.app.conf['FULLTEXT_EXTRACT_PATH']),
                        'ft_source': '{}/tests/test_integration/stub_data/full_test.pdf'.format(self.proj_home),
                        'provider': 'MNRAS'}
            with patch.object(tasks.task_identify_facilities, 'delay', return_value=None) as identify_facilities:
                with patch.object(tasks.task_output_results, 'delay', return_value=None) as task_output_results:

                    with patch.object(tasks.task_output_results, 'delay', return_value=None) as task_output_results: