Example #1
0
 def test_plist_creation(self, args, monkeypatch, tmpdir):
     """
     All arguments should be reflected in the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     args.configure_mock(
         source='some/path/foo', name='foo', index_page=None)
     main.prepare_docset(args, 'bar')
     m_ct.assert_called_once_with(
         'some/path/foo',
         'bar/Contents/Resources/Documents',
     )
     assert os.path.isfile('bar/Contents/Resources/docSet.dsidx')
     p = plistlib.readPlist('bar/Contents/Info.plist')
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
     }
     with sqlite3.connect('bar/Contents/Resources/docSet.dsidx') as db_conn:
         cur = db_conn.cursor()
         # ensure table exists and is empty
         cur.execute('select count(1) from searchIndex')
         assert cur.fetchone()[0] == 0
Example #2
0
def test_prepare_docset(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        monkeypatch.chdir(td)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, 'copytree', m_ct)
        os.mkdir('bar')
        args.configure_mock(source='some/path/foo', name='foo')
        main.prepare_docset(args, 'bar')
        m_ct.assert_called_once_with(
            'some/path/foo',
            'bar/Contents/Resources/Documents',
        )
        assert os.path.isfile('bar/Contents/Resources/docSet.dsidx')
        p = plistlib.readPlist('bar/Contents/Info.plist')
        assert p == {
            'CFBundleIdentifier': 'foo',
            'CFBundleName': 'foo',
            'DocSetPlatformFamily': 'foo',
            'DashDocSetFamily': 'python',
            'isDashDocset': True,
        }
        with sqlite3.connect('bar/Contents/Resources/docSet.dsidx') as db_conn:
            cur = db_conn.cursor()
            # ensure table exists and is empty
            cur.execute('select count(1) from searchIndex')
            assert cur.fetchone()[0] == 0
Example #3
0
 def test_plist_creation(self, monkeypatch, tmpdir):
     """
     All arguments should be reflected in the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     main.prepare_docset("some/path/foo",
                         'bar',
                         name="foo",
                         index_page=None)
     m_ct.assert_called_once_with(
         'some/path/foo',
         'bar/Contents/Resources/Documents',
     )
     assert os.path.isfile('bar/Contents/Resources/docSet.dsidx')
     p = plistlib.readPlist('bar/Contents/Info.plist')
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
     }
     with sqlite3.connect('bar/Contents/Resources/docSet.dsidx') as db_conn:
         cur = db_conn.cursor()
         # ensure table exists and is empty
         cur.execute('select count(1) from searchIndex')
         assert cur.fetchone()[0] == 0
Example #4
0
def test_prepare_docset(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        monkeypatch.chdir(td)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, 'copytree', m_ct)
        os.mkdir('bar')
        args.configure_mock(
            source='some/path/foo', name='foo', index_page=None)
        main.prepare_docset(args, 'bar')
        m_ct.assert_called_once_with(
            'some/path/foo',
            'bar/Contents/Resources/Documents',
        )
        assert os.path.isfile('bar/Contents/Resources/docSet.dsidx')
        p = plistlib.readPlist('bar/Contents/Info.plist')
        assert p == {
            'CFBundleIdentifier': 'foo',
            'CFBundleName': 'foo',
            'DocSetPlatformFamily': 'foo',
            'DashDocSetFamily': 'python',
            'isDashDocset': True,
        }
        with sqlite3.connect('bar/Contents/Resources/docSet.dsidx') as db_conn:
            cur = db_conn.cursor()
            # ensure table exists and is empty
            cur.execute('select count(1) from searchIndex')
            assert cur.fetchone()[0] == 0
Example #5
0
    def test_with_online_redirect_url(self, monkeypatch, tmpdir):
        """
        If an index page is passed, it is added to the plist.
        """
        monkeypatch.chdir(tmpdir)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, "copytree", m_ct)
        os.mkdir("bar")
        docset = main.prepare_docset(
            "some/path/foo",
            "bar",
            name="foo",
            index_page="foo.html",
            enable_js=False,
            online_redirect_url="https://domain.com",
        )

        p = main.read_plist(docset.plist)

        assert p == {
            "CFBundleIdentifier": "foo",
            "CFBundleName": "foo",
            "DocSetPlatformFamily": "foo",
            "DashDocSetFamily": "python",
            "isDashDocset": True,
            "dashIndexFilePath": "foo.html",
            "isJavaScriptEnabled": False,
            "DashDocSetFallbackURL": "https://domain.com",
        }
Example #6
0
    def test_with_online_redirect_url(self, monkeypatch, tmpdir):
        """
        If an index page is passed, it is added to the plist.
        """
        monkeypatch.chdir(tmpdir)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, "copytree", m_ct)
        os.mkdir("bar")
        docset = main.prepare_docset(
            "some/path/foo",
            "bar",
            name="foo",
            index_page="foo.html",
            enable_js=False,
            online_redirect_url="https://domain.com",
        )

        p = main.read_plist(docset.plist)

        assert p == {
            "CFBundleIdentifier": "foo",
            "CFBundleName": "foo",
            "DocSetPlatformFamily": "foo",
            "DashDocSetFamily": "python",
            "isDashDocset": True,
            "dashIndexFilePath": "foo.html",
            "isJavaScriptEnabled": False,
            "DashDocSetFallbackURL": "https://domain.com",
        }
Example #7
0
def test_prepare_docset_index_page(monkeypatch):
    with tempfile.TemporaryDirectory() as td:
        monkeypatch.chdir(td)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, 'copytree', m_ct)
        os.mkdir('bar')
        args.configure_mock(
            source='some/path/foo', name='foo', index_page='foo.html')
        main.prepare_docset(args, 'bar')
        p = plistlib.readPlist('bar/Contents/Info.plist')
        assert p == {
            'CFBundleIdentifier': 'foo',
            'CFBundleName': 'foo',
            'DocSetPlatformFamily': 'foo',
            'DashDocSetFamily': 'python',
            'isDashDocset': True,
            'dashIndexFilePath': 'foo.html',
        }
Example #8
0
 def test_with_index_page(self, args, monkeypatch, tmpdir):
     """
     If an index page is passed, it is added to the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     args.configure_mock(
         source='some/path/foo', name='foo', index_page='foo.html')
     main.prepare_docset(args, 'bar')
     p = plistlib.readPlist('bar/Contents/Info.plist')
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
         'dashIndexFilePath': 'foo.html',
     }
Example #9
0
 def test_with_index_page(self, monkeypatch, tmpdir):
     """
     If an index page is passed, it is added to the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     main.prepare_docset('some/path/foo',
                         'bar',
                         name='foo',
                         index_page='foo.html')
     p = plistlib.readPlist('bar/Contents/Info.plist')
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
         'dashIndexFilePath': 'foo.html',
     }
Example #10
0
 def test_with_javascript_enabled(self, monkeypatch, tmpdir):
     """
     If an index page is passed, it is added to the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     docset = main.prepare_docset('some/path/foo', 'bar', name='foo',
                                  index_page='foo.html',
                                  enable_js=True,
                                  online_redirect_url=None)
     p = plistlib.readPlist(docset.plist)
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
         'dashIndexFilePath': 'foo.html',
         'isJavaScriptEnabled': True,
     }
Example #11
0
 def test_with_javascript_enabled(self, monkeypatch, tmpdir):
     """
     If an index page is passed, it is added to the plist.
     """
     monkeypatch.chdir(tmpdir)
     m_ct = MagicMock()
     monkeypatch.setattr(shutil, 'copytree', m_ct)
     os.mkdir('bar')
     docset = main.prepare_docset('some/path/foo', 'bar', name='foo',
                                  index_page='foo.html',
                                  enable_js=True,
                                  online_redirect_url=None)
     p = plistlib.readPlist(docset.plist)
     assert p == {
         'CFBundleIdentifier': 'foo',
         'CFBundleName': 'foo',
         'DocSetPlatformFamily': 'foo',
         'DashDocSetFamily': 'python',
         'isDashDocset': True,
         'dashIndexFilePath': 'foo.html',
         'isJavaScriptEnabled': True,
     }
Example #12
0
    def test_plist_creation(self, monkeypatch, tmpdir):
        """
        All arguments should be reflected in the plist.
        """
        monkeypatch.chdir(tmpdir)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, "copytree", m_ct)
        os.mkdir("bar")
        docset = main.prepare_docset(
            "some/path/foo",
            "bar",
            name="foo",
            index_page=None,
            enable_js=False,
            online_redirect_url=None,
        )
        m_ct.assert_called_once_with(
            "some/path/foo", "bar/Contents/Resources/Documents"
        )

        assert os.path.isfile("bar/Contents/Resources/docSet.dsidx")

        p = main.read_plist(docset.plist)

        assert p == {
            "CFBundleIdentifier": "foo",
            "CFBundleName": "foo",
            "DocSetPlatformFamily": "foo",
            "DashDocSetFamily": "python",
            "isDashDocset": True,
            "isJavaScriptEnabled": False,
        }

        with sqlite3.connect("bar/Contents/Resources/docSet.dsidx") as db_conn:
            cur = db_conn.cursor()
            # ensure table exists and is empty
            cur.execute("select count(1) from searchIndex")

            assert cur.fetchone()[0] == 0
Example #13
0
    def test_plist_creation(self, monkeypatch, tmpdir):
        """
        All arguments should be reflected in the plist.
        """
        monkeypatch.chdir(tmpdir)
        m_ct = MagicMock()
        monkeypatch.setattr(shutil, "copytree", m_ct)
        os.mkdir("bar")
        docset = main.prepare_docset(
            "some/path/foo",
            "bar",
            name="foo",
            index_page=None,
            enable_js=False,
            online_redirect_url=None,
        )
        m_ct.assert_called_once_with("some/path/foo",
                                     "bar/Contents/Resources/Documents")

        assert os.path.isfile("bar/Contents/Resources/docSet.dsidx")

        p = main.read_plist(docset.plist)

        assert p == {
            "CFBundleIdentifier": "foo",
            "CFBundleName": "foo",
            "DocSetPlatformFamily": "foo",
            "DashDocSetFamily": "python",
            "isDashDocset": True,
            "isJavaScriptEnabled": False,
        }

        with sqlite3.connect("bar/Contents/Resources/docSet.dsidx") as db_conn:
            cur = db_conn.cursor()
            # ensure table exists and is empty
            cur.execute("select count(1) from searchIndex")

            assert cur.fetchone()[0] == 0