Example #1
0
 def connection_details(self):
     # The kombu drivers seem to use 'N/A' when they don't have a version...
     driver_version = self._conn.transport.driver_version()
     if driver_version and driver_version.lower() == 'n/a':
         driver_version = None
     return misc.AttrDict(uri=self._conn.as_uri(include_password=False),
                          transport=misc.AttrDict(
                              options=dict(self._conn.transport_options),
                              driver_type=self._conn.transport.driver_type,
                              driver_name=self._conn.transport.driver_name,
                              driver_version=driver_version))
Example #2
0
 def test_back_todict(self):
     attrs = {
         'a': 1,
     }
     obj = misc.AttrDict(**attrs)
     self.assertEquals(obj.a, 1)
     self.assertEquals(attrs, dict(obj))
Example #3
0
 def test_runtime_invalid_set(self):
     attrs = {
         'a': 1,
     }
     obj = misc.AttrDict(**attrs)
     self.assertEquals(obj.a, 1)
     with self.assertRaises(AttributeError):
         obj._123 = 'b'
Example #4
0
 def test_ok_create(self):
     attrs = {
         'a': 1,
         'b': 2,
     }
     obj = misc.AttrDict(**attrs)
     self.assertEquals(obj.a, 1)
     self.assertEquals(obj.b, 2)
Example #5
0
 def test_bypass_set_no_get(self):
     attrs = {
         'a': 1,
     }
     obj = misc.AttrDict(**attrs)
     self.assertEquals(1, obj['a'])
     obj['_b'] = 'c'
     with self.assertRaises(AttributeError):
         obj._b = 'e'
     self.assertEquals('c', obj['_b'])
Example #6
0
    def test_runtime_invalid_set(self):
        def bad_assign(obj):
            obj._123 = 'b'

        attrs = {
            'a': 1,
        }
        obj = misc.AttrDict(**attrs)
        self.assertEqual(obj.a, 1)
        self.assertRaises(AttributeError, bad_assign, obj)
Example #7
0
    def test_bypass_set_no_get(self):
        def bad_assign(obj):
            obj._b = 'e'

        attrs = {
            'a': 1,
        }
        obj = misc.AttrDict(**attrs)
        self.assertEqual(1, obj['a'])
        obj['_b'] = 'c'
        self.assertRaises(AttributeError, bad_assign, obj)
        self.assertEqual('c', obj['_b'])
Example #8
0
 def test_bypass_get(self):
     attrs = {
         'a': 1,
     }
     obj = misc.AttrDict(**attrs)
     self.assertEquals(1, obj['a'])
Example #9
0
# Resources (db handles and similar) of course can't be persisted so we need
# to make sure that we pass this resource fetcher to the tasks constructor so
# that the tasks have access to any needed resources (the resources are
# lazily loaded so that they are only created when they are used).
resources = ResourceFetcher()
flow = lf.Flow("initialize-me")

# 1. First we extract the api request into a usable format.
# 2. Then we go ahead and make a database entry for our request.
flow.add(ExtractInputRequest(resources), MakeDBEntry(resources))

# 3. Then we activate our payment method and finally declare success.
sub_flow = gf.Flow("after-initialize")
sub_flow.add(ActivateDriver(resources), DeclareSuccess())
flow.add(sub_flow)

# Initially populate the storage with the following request object,
# prepopulating this allows the tasks that dependent on the 'request' variable
# to start processing (in this case this is the ExtractInputRequest task).
store = {
    'request': misc.AttrDict(user="******", id="1.35"),
}
eng = engines.load(flow, engine_conf='serial', store=store)

# This context manager automatically adds (and automatically removes) a
# helpful set of state transition notification printing helper utilities
# that show you exactly what transitions the engine is going through
# while running the various billing related tasks.
with printing.PrintingListener(eng):
    eng.run()