Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
pyramid_session_redis / tests / test_connection.py
Size: Mime:
# -*- coding: utf-8 -*-

# stdlib
import unittest

# pypi
from pyramid import testing

# local
from pyramid_session_redis.connection import get_default_connection

# local test suite
from . import DummyRedis


# ==============================================================================


class TestConnection(unittest.TestCase):
    def setUp(self):
        testing.setUp(self)
        self.request = testing.DummyRequest()

    def tearDown(self):
        testing.tearDown(self)

    def test_get_default_connection(self):
        options = dict(host="localhost", port=999)
        inst = get_default_connection(self.request, redis_client=DummyRedis, **options)
        self.assertEqual(inst.host, "localhost")
        self.assertEqual(inst.port, 999)

    def test_get_default_connection_with_url(self):
        url = "redis://username:password@localhost:6379/0"
        inst = get_default_connection(self.request, url=url, redis_client=DummyRedis)
        self.assertEqual(inst.url, url)

    def test_get_default_connection_url_removes_duplicates(self):
        options = dict(host="localhost", port=999, password="password", db=5)
        url = "redis://username:password@localhost:6379/0"
        inst = get_default_connection(
            self.request, url=url, redis_client=DummyRedis, **options
        )
        self.assertEqual(inst.url, url)
        self.assertNotIn("password", inst.opts)
        self.assertNotIn("host", inst.opts)
        self.assertNotIn("port", inst.opts)
        self.assertNotIn("db", inst.opts)