Пример #1
0
    def test_current_unset(self, tmpdir):
        sess_man = sessions.SessionManager(str(tmpdir))

        with pytest.raises(cmdexc.CommandError) as excinfo:
            sess_man.session_save(0, current=True)

        assert str(excinfo.value) == "No session loaded currently!"
Пример #2
0
    def test_session_not_found(self, tmpdir):
        sess_man = sessions.SessionManager(str(tmpdir))

        with pytest.raises(cmdexc.CommandError) as excinfo:
            sess_man.session_delete('foo')

        assert str(excinfo.value) == "Session foo not found!"
Пример #3
0
    def test_internal_without_force(self, tmpdir):
        sess_man = sessions.SessionManager(str(tmpdir))
        with pytest.raises(cmdexc.CommandError) as excinfo:
            sess_man.session_save(0, '_foo')

        expected_text = ("_foo is an internal session, use --force to "
                         "save anyways.")
        assert str(excinfo.value) == expected_text
        assert not (tmpdir / '_foo.yml').exists()
Пример #4
0
    def test_inexistent(self, tmpdir, absolute):
        man = sessions.SessionManager(str(tmpdir))

        if absolute:
            name = str(tmpdir / 'foo')
        else:
            name = 'foo'

        assert not man.exists(name)
Пример #5
0
    def test_deletion_error(self, caplog, tmpdir):
        sess_man = sessions.SessionManager(str(tmpdir))
        (tmpdir / 'foo.yml').ensure()
        tmpdir.chmod(0o555)  # unwritable

        with pytest.raises(cmdexc.CommandError) as excinfo:
            with caplog.at_level(logging.ERROR):
                sess_man.session_delete('foo')

        assert str(excinfo.value).startswith('Error while deleting session: ')
        assert len(caplog.records) == 1
        assert caplog.records[0].message == 'Error while deleting session!'
Пример #6
0
    def test_internal_without_force(self, tmpdir):
        sess_man = sessions.SessionManager(str(tmpdir))
        sess_file = tmpdir / '_foo.yml'
        sess_file.ensure()

        with pytest.raises(cmdexc.CommandError) as excinfo:
            sess_man.session_delete('_foo')

        expected_text = ("_foo is an internal session, use --force to "
                         "delete anyways.")
        assert str(excinfo.value) == expected_text
        assert sess_file.exists()
Пример #7
0
    def test_existent(self, tmp_path, absolute):
        session_dir = tmp_path / 'sessions'
        abs_session = tmp_path / 'foo.yml'
        rel_session = session_dir / 'foo.yml'

        session_dir.mkdir()
        abs_session.touch()
        rel_session.touch()

        man = sessions.SessionManager(str(session_dir))

        if absolute:
            name = str(abs_session)
        else:
            name = 'foo'

        assert man.exists(name)
Пример #8
0
    def test_existent(self, tmpdir, absolute):
        session_dir = tmpdir / 'sessions'
        abs_session = tmpdir / 'foo.yml'
        rel_session = session_dir / 'foo.yml'

        session_dir.ensure(dir=True)
        abs_session.ensure()
        rel_session.ensure()

        man = sessions.SessionManager(str(session_dir))

        if absolute:
            name = str(abs_session)
        else:
            name = 'foo'

        assert man.exists(name)
Пример #9
0
 def test_no_sessions(self, tmpdir):
     sess_man = sessions.SessionManager(str(tmpdir))
     assert not sess_man.list_sessions()
Пример #10
0
 def test_with_other_files(self, tmp_path):
     (tmp_path / 'foo.yml').touch()
     (tmp_path / 'bar.html').touch()
     sess_man = sessions.SessionManager(str(tmp_path))
     assert sess_man.list_sessions() == ['foo']
Пример #11
0
def sess_man():
    """Fixture providing a SessionManager with no session dir."""
    return sessions.SessionManager(base_path=None)
Пример #12
0
 def test_current_set(self, tmpdir, fake_windows):
     sess_man = sessions.SessionManager(str(tmpdir))
     sess_man._current = 'foo'
     sess_man.session_save(0, current=True, quiet=True)
     assert (tmpdir / 'foo.yml').exists()
Пример #13
0
 def test_internal_with_force(self, tmpdir, fake_windows):
     sess_man = sessions.SessionManager(str(tmpdir))
     sess_man.session_save(0, '_foo', force=True, quiet=True)
     assert (tmpdir / '_foo.yml').exists()
Пример #14
0
 def test_with_sessions(self, tmpdir):
     (tmpdir / 'foo.yml').ensure()
     (tmpdir / 'bar.yml').ensure()
     sess_man = sessions.SessionManager(str(tmpdir))
     assert sorted(sess_man.list_sessions()) == ['bar', 'foo']
Пример #15
0
 def test_with_other_files(self, tmpdir):
     (tmpdir / 'foo.yml').ensure()
     (tmpdir / 'bar.html').ensure()
     sess_man = sessions.SessionManager(str(tmpdir))
     assert sess_man.list_sessions() == ['foo']
Пример #16
0
def sess_man(tmpdir):
    """Fixture providing a SessionManager."""
    return sessions.SessionManager(base_path=str(tmpdir))
Пример #17
0
 def test_internal_with_force(self, tmpdir):
     sess_man = sessions.SessionManager(str(tmpdir))
     sess_file = tmpdir / '_foo.yml'
     sess_file.ensure()
     sess_man.session_delete('_foo', force=True)
     assert not tmpdir.listdir()
Пример #18
0
 def test_normal_delete(self, tmpdir):
     sess_man = sessions.SessionManager(str(tmpdir))
     sess_file = tmpdir / 'foo.yml'
     sess_file.ensure()
     sess_man.session_delete('foo')
     assert not tmpdir.listdir()
Пример #19
0
 def __init__(self, webview):
     self.sess_man = sessions.SessionManager(base_path=None)
     self.webview = webview