예제 #1
0
 def __get_by_name(name):
     try:
         return KeyValuePair.get_by_name(name)
     except ValueError as e:
         LOG.debug('Database lookup for name="%s" '
                   'resulted in exception : %s.', name, e)
         return None
예제 #2
0
 def __get_by_name(name):
     try:
         return [KeyValuePair.get_by_name(name)]
     except ValueError as e:
         LOG.debug('Database lookup for name="%s" '
                   'resulted in exception : %s.', name, e)
         return []
예제 #3
0
 def _get_kv(self, key):
     kvp = None
     try:
         kvp = KeyValuePair.get_by_name(key)
     except ValueError:
         # ValueErrors are expected in case of partial lookups
         pass
     # A good default value for un-matched value is empty string since that will be used
     # for rendering templates.
     return kvp.value if kvp else ''
예제 #4
0
 def _get_kv(self, key):
     kvp = None
     try:
         kvp = KeyValuePair.get_by_name(key)
     except ValueError:
         # ValueErrors are expected in case of partial lookups
         pass
     # A good default value for un-matched value is empty string since that will be used
     # for rendering templates.
     return kvp.value if kvp else ''
예제 #5
0
    def test_kvp_crud(self):
        saved = KeyValuePairModelTest._create_save_kvp()
        retrieved = KeyValuePair.get_by_name(saved.name)
        self.assertEqual(saved.id, retrieved.id,
                         'Same KeyValuePair was not returned.')

        # test update
        self.assertEqual(retrieved.value, '0123456789ABCDEF')
        retrieved.value = 'ABCDEF0123456789'
        saved = KeyValuePair.add_or_update(retrieved)
        retrieved = KeyValuePair.get_by_name(saved.name)
        self.assertEqual(retrieved.value, 'ABCDEF0123456789',
                         'Update of key value failed')

        # cleanup
        KeyValuePairModelTest._delete([retrieved])
        try:
            retrieved = KeyValuePair.get_by_name(saved.name)
        except ValueError:
            retrieved = None
        self.assertIsNone(retrieved, 'managed to retrieve after failure.')
예제 #6
0
파일: test_db.py 프로젝트: srenatus/st2
    def test_kvp_crud(self):
        saved = KeyValuePairModelTest._create_save_kvp()
        retrieved = KeyValuePair.get_by_name(saved.name)
        self.assertEqual(saved.id, retrieved.id,
                         'Same KeyValuePair was not returned.')

        # test update
        self.assertEqual(retrieved.value, '0123456789ABCDEF')
        retrieved.value = 'ABCDEF0123456789'
        saved = KeyValuePair.add_or_update(retrieved)
        retrieved = KeyValuePair.get_by_name(saved.name)
        self.assertEqual(retrieved.value, 'ABCDEF0123456789',
                         'Update of key value failed')

        # cleanup
        KeyValuePairModelTest._delete([retrieved])
        try:
            retrieved = KeyValuePair.get_by_name(saved.name)
        except ValueError:
            retrieved = None
        self.assertIsNone(retrieved, 'managed to retrieve after failure.')
예제 #7
0
 def _construct_system_context(data, context):
     """Identify the system context in the data."""
     # The following regex will look for all occurrences of "{{system.*}}",
     # "{{ system.* }}", "{{ system.*}}", and "{{system.* }}" in the data.
     regex = '{{\s*' + SYSTEM_PREFIX + '.(.*?)\s*}}'
     keys = re.findall(regex, json.dumps(data))
     if not keys:
         return context
     kvps = {}
     for key in keys:
         kvp = KeyValuePair.get_by_name(key)
         kvps[key] = kvp.value
     if kvps:
         if SYSTEM_PREFIX not in context:
             context[SYSTEM_PREFIX] = {}
         context[SYSTEM_PREFIX].update(kvps)
     return context