Example #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!"
Example #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!"
Example #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()
Example #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)
Example #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!'
Example #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()
Example #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)
Example #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)
Example #9
0
 def test_no_sessions(self, tmpdir):
     sess_man = sessions.SessionManager(str(tmpdir))
     assert not sess_man.list_sessions()
Example #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']
Example #11
0
def sess_man():
    """Fixture providing a SessionManager with no session dir."""
    return sessions.SessionManager(base_path=None)
Example #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()
Example #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()
Example #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']
Example #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']
Example #16
0
def sess_man(tmpdir):
    """Fixture providing a SessionManager."""
    return sessions.SessionManager(base_path=str(tmpdir))
Example #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()
Example #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()
Example #19
0
 def __init__(self, webview):
     self.sess_man = sessions.SessionManager(base_path=None)
     self.webview = webview