Ejemplo n.º 1
0
 def test_push_to_fluiddb(self):
     # set stuff up...
     name = str(uuid.uuid4())
     root_path = 'test/%s' % name
     tags = create_schema(TEMPLATE, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     # the good case
     push_to_fluiddb(TEMPLATE, root_path, fom_class, 'foo', 'flimp_test')
     # check an object was created
     result = Object.filter("has %s/foo" % root_path)
     self.assertEqual(1, len(result))
     # lets try the other good case where we don't have an about tag field
     push_to_fluiddb(TEMPLATE, root_path, fom_class, None, 'flimp_test')
     # we should have *two* objects now
     result = Object.filter("has %s/foo" % root_path)
     self.assertEqual(2, len(result))
     # check we have all the expected tags on the objects
     for obj in result:
         tag_paths = obj.tag_paths
         for k in tags:
             self.assertTrue(k in tag_paths)
     # ok... lets make sure that the allowEmpty flag is handled properly
     template = [
         {
             'foo-x': None,
             'bar-x': {
                 'baz-x': ''
             },
             'bof-x': 'Hello',
             'qux-x': False
         },
     ]
     tags = create_schema(template, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     push_to_fluiddb(template,
                     root_path,
                     fom_class,
                     None,
                     'flimp_test',
                     allowEmpty=False)
     # check an object was created
     result = Object.filter("has %s/bof-x" % root_path)
     self.assertEqual(1, len(result))
     tag_paths = result[0].tag_paths
     self.assertEqual(3, len(tag_paths))
Ejemplo n.º 2
0
 def test_push_to_fluiddb(self):
     # set stuff up...
     name = str(uuid.uuid4())
     root_path = 'test/%s' % name
     tags = create_schema(TEMPLATE, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     # the good case
     push_to_fluiddb(TEMPLATE, root_path, fom_class, 'foo',
                     'flimp_test')
     # check an object was created
     result = Object.filter("has %s/foo" % root_path)
     self.assertEqual(1, len(result))
     # lets try the other good case where we don't have an about tag field
     push_to_fluiddb(TEMPLATE, root_path, fom_class, None,
                     'flimp_test')
     # we should have *two* objects now
     result = Object.filter("has %s/foo" % root_path)
     self.assertEqual(2, len(result))
     # check we have all the expected tags on the objects
     for obj in result:
         tag_paths = obj.tag_paths
         for k in tags:
             self.assertTrue(k in tag_paths)
     # ok... lets make sure that the allowEmpty flag is handled properly
     template = [
         {
             'foo-x': None,
             'bar-x': {
                 'baz-x': ''
             },
             'bof-x': 'Hello',
             'qux-x': False
         },
     ]
     tags = create_schema(template, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     push_to_fluiddb(template, root_path, fom_class, None, 'flimp_test',
                     allowEmpty=False)
     # check an object was created
     result = Object.filter("has %s/bof-x" % root_path)
     self.assertEqual(1, len(result))
     tag_paths = result[0].tag_paths
     self.assertEqual(3, len(tag_paths))
Ejemplo n.º 3
0
 def test_create_class(self):
     tags = create_schema(TEMPLATE, 'test/this/is/a/test', 'flimp-test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     attributes = dir(fom_class)
     for k in tags:
         self.assertTrue(k in attributes)
Ejemplo n.º 4
0
 def test_create_class(self):
     tags = create_schema(TEMPLATE, 'test/this/is/a/test', 'flimp-test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     attributes = dir(fom_class)
     for k in tags:
         self.assertTrue(k in attributes)
Ejemplo n.º 5
0
 def test_set_tag_value(self):
     # set stuff up...
     name = str(uuid.uuid4())
     root_path = 'test/%s' % name
     template = [
         {
             'foo': None,
             'bar': {
                 'baz': ''
             },
             'bof': 'Hello',
             'qux': False
         },
     ]
     tags = create_schema(template, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     test_item = template[0]
     tag_values = get_values(test_item, root_path)
     # Empty tags allowed
     allowEmpty = True
     obj = fom_class()
     obj.create()
     for key, value in tag_values.iteritems():
         set_tag_value(fom_class, obj, key, value, allowEmpty)
     self.assertEqual(None, getattr(obj, 'test/%s/foo' % name))
     self.assertEqual('', getattr(obj, 'test/%s/bar/baz' % name))
     self.assertEqual('Hello', getattr(obj, 'test/%s/bof' % name))
     self.assertEqual(False, getattr(obj, 'test/%s/qux' % name))
     # Empty tags are *not* allowed
     allowEmpty = False
     obj = fom_class()
     obj.create()
     for key, value in tag_values.iteritems():
         set_tag_value(fom_class, obj, key, value, allowEmpty)
     tags = obj.tags
     self.assertEqual(3, len(tags))
     # tag values have been set except for the one that was None
     self.assertEqual('', getattr(obj, 'test/%s/bar/baz' % name))
     self.assertEqual('Hello', getattr(obj, 'test/%s/bof' % name))
     self.assertEqual(False, getattr(obj, 'test/%s/qux' % name))
Ejemplo n.º 6
0
 def test_set_tag_value(self):
     # set stuff up...
     name = str(uuid.uuid4())
     root_path = 'test/%s' % name
     template = [
         {
             'foo': None,
             'bar': {
                 'baz': ''
             },
             'bof': 'Hello',
             'qux': False
         },
     ]
     tags = create_schema(template, root_path, 'flimp_test',
                          'flimp unit-test suite')
     self.assertEqual(4, len(tags))
     fom_class = create_class(tags)
     test_item = template[0]
     tag_values = get_values(test_item, root_path)
     # Empty tags allowed
     allowEmpty = True
     obj = fom_class()
     obj.create()
     for key, value in tag_values.iteritems():
          set_tag_value(fom_class, obj, key, value, allowEmpty)
     self.assertEqual(None, getattr(obj, 'test/%s/foo' % name))
     self.assertEqual('', getattr(obj, 'test/%s/bar/baz' % name))
     self.assertEqual('Hello', getattr(obj, 'test/%s/bof' % name))
     self.assertEqual(False, getattr(obj, 'test/%s/qux' % name))
     # Empty tags are *not* allowed
     allowEmpty = False
     obj = fom_class()
     obj.create()
     for key, value in tag_values.iteritems():
          set_tag_value(fom_class, obj, key, value, allowEmpty)
     tags = obj.tags
     self.assertEqual(3, len(tags))
     # tag values have been set except for the one that was None
     self.assertEqual('', getattr(obj, 'test/%s/bar/baz' % name))
     self.assertEqual('Hello', getattr(obj, 'test/%s/bof' % name))
     self.assertEqual(False, getattr(obj, 'test/%s/qux' % name))