def test_sessionmaker_new_conf(cache_dict): try: from dogpile.cache.region import make_region except ImportError: pytest.skip("dogpile.cache not available") region = make_region().configure('dogpile.cache.memory', arguments={'cache_dict': cache_dict}) settings = {'backend': 'dogpile', 'domain': 'example.com', 'signature_key': test_sig_key, 'region': region } Session = sessionmaker() assert not hasattr(Session, "settings") Session.configure(**settings) assert isinstance(Session(), DogpileSession) del Session.settings["region"] assert "region" not in Session.settings assert isinstance(Session(region=region), DogpileSession) Session.settings["region"] = region assert Session.settings["signature_key"] == test_sig_key session = Session(signature_key=test_enc_key) assert session.sig_key == test_enc_key
def test_sessionmaker_init_keys(filename): Session = sessionmaker() Session.settings = {'secret_file': filename} Session._init_keys(Session.settings) assert 'encryption_key' not in Session.settings assert isinstance(Session.settings['signature_key'], str) assert len(Session.settings['signature_key']) == 32 Session = sessionmaker() Session.settings = {'enable_encryption': True, 'secret_file': filename} Session._init_keys(Session.settings) assert isinstance(Session.settings['signature_key'], str) assert isinstance(Session.settings['encryption_key'], str) assert len(Session.settings['encryption_key']) == 32 assert len(Session.settings['signature_key']) == 32
def sessionmaker(request, cache_dict): """Return a new session factory, one for each tested backend. It will be already configured, so if re-configuration is desired, one should reset the configuration.""" backend = request.param settings = {'backend': backend, 'domain': 'example.com', 'signature_key': test_sig_key, } if backend == 'dogpile': try: from dogpile.cache import make_region except ImportError: pytest.skip("dogpile.cache not available") region = make_region().configure('dogpile.cache.memory', arguments={'cache_dict': cache_dict}) settings["region"] = region elif backend == 'cookie': # No extra settings needed pass Session = pysess.sessionmaker() Session.configure(**settings) return Session
def test_sessionmaker_not_configured(): Session = sessionmaker() with pytest.raises(SessionConfigurationError): Session()
def test_session_unknown_backend(filename): Session = sessionmaker() info = pytest.raises(SessionConfigurationError, Session.configure, backend='doesnotexist', secret_file=filename) assert info.value.message == "Backend doesnotexist not found."
def test_sessionmaker_no_backend(filename): Session = sessionmaker() info = pytest.raises(SessionConfigurationError, Session.configure, secret_file=filename) assert "No backend given" in info.value.message
def test_sessionmaker_call_sanity(wrong_call_settings): settings, msg_part = wrong_call_settings info = pytest.raises(SessionConfigurationError, sessionmaker()._check_call_settings_sanity, settings) msg = info.value.message assert msg_part in msg
def test_sessionmaker_sanity_call(sessionmaker): with pytest.raises(SessionConfigurationError): sessionmaker(**{'secret_file': True})