Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_session.py: allow setting ports via env #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions test_session.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import unittest
import os
import tempfile
import unittest

import flask
import pylibmc
from pymongo import MongoClient
from redis import Redis

from flask_session import Session


class FlaskSessionTestCase(unittest.TestCase):

def test_null_session(self):
app = flask.Flask(__name__)
Session(app)
Expand All @@ -25,6 +30,7 @@ def expect_exception(f, *args, **kwargs):
def test_redis_session(self):
app = flask.Flask(__name__)
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = Redis(port=os.getenv('REDIS_PORT', '6379'))
Session(app)
@app.route('/set', methods=['POST'])
def set():
Expand All @@ -42,11 +48,13 @@ def delete():
self.assertEqual(c.post('/set', data={'value': '42'}).data, b'value set')
self.assertEqual(c.get('/get').data, b'42')
c.post('/delete')



def test_memcached_session(self):
app = flask.Flask(__name__)
app.config['SESSION_TYPE'] = 'memcached'
app.config['SESSION_MEMCACHED'] = pylibmc.Client(
['127.0.0.1:' + os.getenv('MEMCACHED_PORT', '11211')]
)
Session(app)
@app.route('/set', methods=['POST'])
def set():
Expand All @@ -64,8 +72,7 @@ def delete():
self.assertEqual(c.post('/set', data={'value': '42'}).data, b'value set')
self.assertEqual(c.get('/get').data, b'42')
c.post('/delete')



def test_filesystem_session(self):
app = flask.Flask(__name__)
app.config['SESSION_TYPE'] = 'filesystem'
Expand All @@ -87,11 +94,14 @@ def delete():
self.assertEqual(c.post('/set', data={'value': '42'}).data, b'value set')
self.assertEqual(c.get('/get').data, b'42')
c.post('/delete')

def test_mongodb_session(self):
app = flask.Flask(__name__)
app.testing = True
app.config['SESSION_TYPE'] = 'mongodb'
app.config['SESSION_MONGODB'] = MongoClient(
port=int(os.getenv('MONGODB_PORT', '27017'))
)
Session(app)
@app.route('/set', methods=['POST'])
def set():
Expand Down Expand Up @@ -141,7 +151,7 @@ def test_flasksqlalchemy_session_with_signer(self):
app.config['SESSION_TYPE'] = 'sqlalchemy'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
app.config['SESSION_USE_SIGNER'] = True
session = Session(app)
Session(app)
@app.route('/set', methods=['POST'])
def set():
flask.session['value'] = flask.request.form['value']
Expand All @@ -164,6 +174,7 @@ def test_session_use_signer(self):
app = flask.Flask(__name__)
app.secret_key = 'test_secret_key'
app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = Redis(port=os.getenv('REDIS_PORT', '6379'))
app.config['SESSION_USE_SIGNER'] = True
Session(app)
@app.route('/set', methods=['POST'])
Expand Down