예제 #1
0
    def test_save_fulltext_files01(self):
        self.create_general_config()
        book = Book(Host(self.test_root))
        book.fulltext = {
            "20200101000000000": {
                'index.html': {
                    'content': 'dummy text 1 中文',
                    }
                },
            "20200101000000001": {
                'index.html': {
                    'content': 'dummy text 2 中文',
                    }
                },
            }

        book.save_fulltext_files()

        with open(os.path.join(self.test_root, 'tree', 'fulltext.js'), encoding='UTF-8') as fh:
            self.assertEqual(fh.read(), """/**
 * This file is generated by WebScrapBook and is not intended to be edited.
 */
scrapbook.fulltext({
 "20200101000000000": {
  "index.html": {
   "content": "dummy text 1 中文"
  }
 },
 "20200101000000001": {
  "index.html": {
   "content": "dummy text 2 中文"
  }
 }
})""")
예제 #2
0
    def test_save_fulltext_files03(self):
        self.create_general_config()
        os.makedirs(os.path.join(self.test_root, 'tree'))
        with open(os.path.join(self.test_root, 'tree', 'fulltext.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy')
        with open(os.path.join(self.test_root, 'tree', 'fulltext1.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy1')
        with open(os.path.join(self.test_root, 'tree', 'fulltext2.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy2')
        with open(os.path.join(self.test_root, 'tree', 'fulltext3.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy3')
        with open(os.path.join(self.test_root, 'tree', 'fulltext4.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy4')
        with open(os.path.join(self.test_root, 'tree', 'fulltext6.js'), 'w', encoding='UTF-8') as fh:
            fh.write('dummy6')

        book = Book(Host(self.test_root))
        book.fulltext = {
            "20200101000000000": {
                'index.html': {
                    'content': 'dummy text 1 中文',
                    },
                'frame.html': {
                    'content': 'frame page content',
                    },
                },
            "20200101000000001": {
                'index.html': {
                    'content': 'dummy text 2 中文',
                    },
                },
            }

        book.save_fulltext_files()

        with open(os.path.join(self.test_root, 'tree', 'fulltext.js'), encoding='UTF-8') as fh:
            self.assertEqual(fh.read(), """/**
 * This file is generated by WebScrapBook and is not intended to be edited.
 */
scrapbook.fulltext({
 "20200101000000000": {
  "index.html": {
   "content": "dummy text 1 中文"
  },
  "frame.html": {
   "content": "frame page content"
  }
 }
})""")
        with open(os.path.join(self.test_root, 'tree', 'fulltext1.js'), encoding='UTF-8') as fh:
            self.assertEqual(fh.read(), """/**
 * This file is generated by WebScrapBook and is not intended to be edited.
 */
scrapbook.fulltext({
 "20200101000000001": {
  "index.html": {
   "content": "dummy text 2 中文"
  }
 }
})""")
        self.assertFalse(os.path.exists(os.path.join(self.test_root, 'tree', 'fulltext2.js')))
        self.assertFalse(os.path.exists(os.path.join(self.test_root, 'tree', 'fulltext3.js')))
        self.assertFalse(os.path.exists(os.path.join(self.test_root, 'tree', 'fulltext4.js')))
        self.assertFalse(os.path.exists(os.path.join(self.test_root, 'tree', 'fulltext5.js')))
        self.assertTrue(os.path.exists(os.path.join(self.test_root, 'tree', 'fulltext6.js')))
예제 #3
0
 def test_load_fulltext_files03(self, mock_func):
     book = Book(Host(self.test_root))
     book.fulltext = {}
     book.load_fulltext_files(refresh=True)
     mock_func.assert_called_once_with('fulltext')
예제 #4
0
 def test_load_fulltext_files02(self, mock_func):
     book = Book(Host(self.test_root))
     book.fulltext = {}
     book.load_fulltext_files()
     mock_func.assert_not_called()