def test_doesnt_interfere(self):
        """should allow config values through kwargs"""
        adapter = AbstractAdapter(foo='bar', middlewares=[3])

        new_adapter = AbstractAdapter()
        self.assertEqual(new_adapter.middlewares, [])
        self.assertEqual(new_adapter.processors, [])
    def test_takes_dict(self):
        a1 = AbstractAdapter({ 'foo': 1 }, middlewares=[1], processors=[2])
        a3 = a1.merge({'bar': 2})

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
        self.assertEqual(a3.middlewares, [1])
        self.assertEqual(a3.processors, [2])
    def test_allow_middlewares_and_processors_through_kwargs(self):
        a1 = AbstractAdapter({ 'foo': 1 }, middlewares=[1], processors=[2])
        a3 = a1.merge(bar='2', middlewares=[1], processors=[2])

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], '2')
        self.assertEqual(a3.middlewares, [1])
        self.assertEqual(a3.processors, [2])
    def test_takes_dict(self):
        a1 = AbstractAdapter({'foo': 1}, middlewares=[1], processors=[2])
        a3 = a1.merge({'bar': 2})

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
        self.assertEqual(a3.middlewares, [1])
        self.assertEqual(a3.processors, [2])
    def test_allow_middlewares_and_processors_through_kwargs(self):
        a1 = AbstractAdapter({'foo': 1}, middlewares=[1], processors=[2])
        a3 = a1.merge(bar='2', middlewares=[1], processors=[2])

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], '2')
        self.assertEqual(a3.middlewares, [1])
        self.assertEqual(a3.processors, [2])
    def test_takes_instance_of_adapter(self):
        a1 = AbstractAdapter({ 'foo': 1 })
        a2 = AbstractAdapter({ 'bar': 2 })
        a3 = a1.merge(a2)

        self.assertEqual(a1.config['foo'], 1)
        self.assertEqual(a2.config['bar'], 2)
        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
    def test_takes_instance_of_adapter(self):
        a1 = AbstractAdapter({'foo': 1})
        a2 = AbstractAdapter({'bar': 2})
        a3 = a1.merge(a2)

        self.assertEqual(a1.config['foo'], 1)
        self.assertEqual(a2.config['bar'], 2)
        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
    def test_delayed_exec_arity(self):
        """should not execute callables if ther arity is greater than 1"""
        adapter = AbstractAdapter({'foo': lambda x: 'bar' * x})
        self.assertEqual(adapter.config['foo'](3), 'barbarbar')

        def foo(x):
            return 'bar' * x

        adapter = AbstractAdapter({'foo': foo})
        self.assertEqual(adapter.config['foo'](3), 'barbarbar')
    def test_delayed_exec(self):
        """should delay execution of callables"""
        foo_val = 'BAD'
        adapter = AbstractAdapter({'foo': lambda: foo_val})
        foo_val = 'GOOD'
        self.assertEqual(adapter.config['foo'], 'GOOD')

        foo_val = 'BAD'

        def foo():
            return foo_val

        adapter = AbstractAdapter({'foo': foo})
        foo_val = 'GOOD'
        self.assertEqual(adapter.config['foo'], 'GOOD')
 def test_global_default(self):
     """
     should use global default instead of 10 second default if the global
     default is not None
     """
     socket.setdefaulttimeout(3)
     adapter = AbstractAdapter({})
     self.assertEqual(socket.getdefaulttimeout(), 3)
 def test_accepts_dict(self):
     """accepts a dictionary to initialize"""
     adapter = AbstractAdapter({'foo': 'bar'})
     self.assertEqual(adapter.config['foo'], 'bar')
 def test_copy_construcotr(self):
     adapter = AbstractAdapter({'foo': 1}, middlewares=[1], processors=[2])
     copy = AbstractAdapter(adapter)
     self.assertEqual(copy.config['foo'], 1)
     self.assertEqual(copy.middlewares, [1])
     self.assertEqual(copy.processors, [2])
 def setUp(self):
     self.adapter = AbstractAdapter({})
 def test_config(self):
     """socket timeout should be configurable"""
     adapter = AbstractAdapter({'timeout': 5})
     self.assertEqual(socket.getdefaulttimeout(), 5)
 def test_init_middleware_with_kwargs(self):
     """middelwares should be initialized to the middlewares key word
     argument if provided"""
     adapter = AbstractAdapter({}, middlewares=[1])
     self.assertEqual(adapter.middlewares, [1])
 def test_init_processors(self):
     """processors should be initialized as an empty list"""
     adapter = AbstractAdapter({})
     self.assertEqual(adapter.processors, [])
 def test_init_processors_with_kwargs(self):
     """
     processors should be initialized to the processors key word argument
     """
     adapter = AbstractAdapter({}, processors='foo')
     self.assertEqual(adapter.processors, 'foo')
    def test_takes_keywords(self):
        a1 = AbstractAdapter({'foo': 1})
        a3 = a1.merge(bar=2)

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
 def test_declares_stack(self):
     """should declate a _stack attr"""
     adapter = AbstractAdapter({})
     self.assertTrue(hasattr(adapter, '_stack'))
     self.assertEquals(adapter._stack, None)
 def test_appends_middlewares_option(self):
     """should append _middlewares option to middlewares"""
     middlewares = [(MiddlewareA, {})]
     adapter = AbstractAdapter({'middlewares': middlewares})
     self.assertEquals(adapter.middlewares, middlewares)
    def test_takes_keywords(self):
        a1 = AbstractAdapter({ 'foo': 1 })
        a3 = a1.merge(bar=2)

        self.assertEqual(a3.config['foo'], 1)
        self.assertEqual(a3.config['bar'], 2)
 def test_default(self):
     """default timeout should be 10 seconds"""
     socket.setdefaulttimeout(None)
     adapter = AbstractAdapter({})
     self.assertEqual(socket.getdefaulttimeout(), None)
Exemple #23
0
 def __init__(self, *args, **kwargs):
     AbstractAdapter.__init__(self, *args, **kwargs)
    def test_allows_kwarg_config(self):
        """should allow config values through kwargs"""
        adapter = AbstractAdapter(foo='bar', middlewares=[3])

        self.assertEqual(adapter.config['foo'], 'bar')
        self.assertEqual(adapter.middlewares, [3])