Exemplo n.º 1
0
    def test_clean_filename(self):
        test_path = '/tmp/test/some_filename.ext'
        expected_output = 'some filename'

        f = FileTypeBase(test_path)

        assert f._clean_filename() == expected_output
Exemplo n.º 2
0
    def test_filter_symbols(self):
        test_str = 'a-.$/bc'
        expected_output = 'a    bc'

        f = FileTypeBase('')

        assert f._filter_symbols(test_str) == expected_output
Exemplo n.º 3
0
    def test_find_isbn_in_metadata(self):
        f = FileTypeBase('')

        expected_metadata = {'a': 1}
        test_text = '978-3-16-148410-0'

        f.get_isbn = MagicMock(return_value=test_text)
        _base.query_isbn_data = MagicMock(return_value=expected_metadata)

        isbns = f.find_isbn_in_metadata()
        assert isbns == [expected_metadata]
Exemplo n.º 4
0
    def test_find_isbn_in_text(self):
        f = FileTypeBase('')

        expected_metadata = {'a': 1}

        test_text = [
            'page 1', 'page 2 978-3-16-148410-0 still page 2', 'page 3'
        ]
        f.get_text = MagicMock(return_value=test_text)
        _base.query_isbn_data = MagicMock(return_value=expected_metadata)

        isbns = f.find_isbn_in_text()
        assert isbns == [expected_metadata]
Exemplo n.º 5
0
    def test_update_path(self):
        with self.app.app_context():
            book = Book.query.first()

            test_new_path = 'new_path'
            file_type_object_mock = FileTypeBase(book.path)

            update_paths_module.copy_to_library = MagicMock(return_value=test_new_path)
            update_paths_module.get_file_type_object = MagicMock(return_value=file_type_object_mock)

            new_path = update_paths_module.update_path(book)

            assert test_new_path == new_path
            assert book.path == new_path
Exemplo n.º 6
0
    def test_get_isbn_from_text(self):
        f = FileTypeBase('')

        expected_isbn = '9783161484100'

        test_text = [
            'page 1', 'page 2 978-3-16-148410-0 still page 2', 'page 3'
        ]
        f.get_text = MagicMock(return_value=test_text)
        isbns = f.get_isbns_from_text()
        assert isbns == [expected_isbn]

        test_text = [
            'page 1', 'page 2 ISBN 978-3-16-148410-0 still page 2', 'page 3'
        ]
        f.get_text = MagicMock(return_value=test_text)
        isbns = f.get_isbns_from_text()
        assert isbns == [expected_isbn]

        test_text = ['page 1', 'page 2 9783161484100 still page 2', 'page 3']
        f.get_text = MagicMock(return_value=test_text)
        isbns = f.get_isbns_from_text()
        assert isbns == [expected_isbn]
Exemplo n.º 7
0
    def test_filename(self):
        test_path = '/tmp/test/'
        test_filename = 'testfile.pdf'
        f = FileTypeBase(test_path + test_filename)

        assert f.filename == test_filename