Example #1
0
 def testCreate(self):
     ns = Namespace(u'test/test')
     ns.create(u'fomtest description')
     self.assertEqual(self.last, ('POST', u'/namespaces/test', {
         'name': u'test',
         'description': u'fomtest description'
     }, None, None))
Example #2
0
    def testPOSTNewUnicodeTagUnderUnicodeNamespace(self):
        """
        There shouldn't be a problem creating a tag under a namespace whose
        name is expressed in non-ascii characters.

        See the following bug:
        https://bugs.edge.launchpad.net/fluiddb/+bug/762779
        """
        # Use the testuser1 root namespace.
        ns = Namespace('testuser1')
        # Create an interestingly named namespace
        quran = u'\ufe8e\ufee0\ufed7\ufead\ufe81'
        quranNS = ns.create_namespace(quran, 'For the purposes of testing')
        # Attempt to create a new tag underneath
        newTag = False
        try:
            # just check it can be created
            sura = u'\ufeb1\ufeed\ufead'
            newTag = quranNS.create_tag(sura, 'This is a test', False)
            expectedPath = u'testuser1/' + quran + '/' + sura
            self.assertEqual(expectedPath, newTag.path)
        finally:
            if newTag:
                newTag.delete()
            quranNS.delete()
Example #3
0
    def testPOSTNewUnicodeTagUnderUnicodeNamespace(self):
        """
        There shouldn't be a problem creating a tag under a namespace whose
        name is expressed in non-ascii characters.

        See the following bug:
        https://bugs.edge.launchpad.net/fluiddb/+bug/762779
        """
        # Use the testuser1 root namespace.
        ns = Namespace('testuser1')
        # Create an interestingly named namespace
        quran = u'\ufe8e\ufee0\ufed7\ufead\ufe81'
        quranNS = ns.create_namespace(quran, 'For the purposes of testing')
        # Attempt to create a new tag underneath
        newTag = False
        try:
            # just check it can be created
            sura = u'\ufeb1\ufeed\ufead'
            newTag = quranNS.create_tag(sura, 'This is a test', False)
            expectedPath = u'testuser1/' + quran + '/' + sura
            self.assertEqual(expectedPath, newTag.path)
        finally:
            if newTag:
                newTag.delete()
            quranNS.delete()
Example #4
0
 def test_create_child(self):
     n = Namespace(u'test')
     self.db.add_resp(201, 'application/json', '{"id": "4", "URI": "https')
     child = n.create_namespace(u'test', u'fomtest description')
     self.assertEquals(child.path, u'test/test')
     self.assertEqual(self.last, ('POST', u'/namespaces/test', {
         'name': u'test',
         'description': u'fomtest description'
     }, None, None))
Example #5
0
 def testDescription(self):
     ns = Namespace(u'test/test')
     ns.description = u'testDesc'
     self.assertEqual(self.last, (
         'PUT',
         u'/namespaces/test/test',
         {u'description': u'testDesc'},
         None,
         None))
Example #6
0
 def testCreate(self):
     ns = Namespace(u'test/test')
     ns.create(u'fomtest description')
     self.assertEqual(self.last, (
         'POST',
         u'/namespaces/test',
         {'name': u'test',
          'description': u'fomtest description'},
         None,
         None))
Example #7
0
 def testCreateTag(self):
     n = Namespace(u'test')
     self.db.add_resp(201, 'application/json', '{"id": "4", "URI": "https')
     new_tag = n.create_tag(u'test', 'a test')
     self.assertTrue(isinstance(new_tag, Tag))
     self.assertEqual(self.last, ('POST', u'/tags/test', {
         u'indexed': False,
         u'name': u'test',
         u'description': 'a test'
     }, None, None))
Example #8
0
 def test_create_child(self):
     n = Namespace(u'test')
     self.db.add_resp(201, 'application/json',
         '{"id": "4", "URI": "https')
     child = n.create_namespace(u'test', u'fomtest description')
     self.assertEquals(child.path, u'test/test')
     self.assertEqual(self.last, (
         'POST',
         u'/namespaces/test',
         {'name': u'test', 'description': u'fomtest description'},
         None,
         None))
Example #9
0
 def testCreateTag(self):
     n = Namespace(u'test')
     self.db.add_resp(201, 'application/json',
         '{"id": "4", "URI": "https')
     new_tag = n.create_tag(u'test', 'a test')
     self.assertTrue(isinstance(new_tag, Tag))
     self.assertEqual(self.last, (
         'POST',
         u'/tags/test',
         {u'indexed': False,
          u'name': u'test',
          u'description': 'a test'},
         None,
         None))
Example #10
0
 def test_make_namespace_path(self):
     # create a new namespace path (returning the leaf namespace)
     unique_ns = str(uuid.uuid4())
     path = "test/%s/foo" % unique_ns
     result = make_namespace_path(path, 'flimp-test', 'For the purposes of'
                             ' testing flimp')
     self.assertEqual(path, result.path)
     # try to create an existing namespace path (just return the leaf)
     result = make_namespace(path, 'flimp-test', 'For the purposes of'
                             ' testing flimp')
     self.assertEqual(path, result.path)
     # be a good citizen an tidy up the mess
     result.delete()
     ns = Namespace("test/%s" % unique_ns)
     ns.delete()
Example #11
0
 def test_make_namespace_path(self):
     # create a new namespace path (returning the leaf namespace)
     unique_ns = str(uuid.uuid4())
     path = "test/%s/foo" % unique_ns
     result = make_namespace_path(path, 'flimp-test', 'For the purposes of'
                                  ' testing flimp')
     self.assertEqual(path, result.path)
     # try to create an existing namespace path (just return the leaf)
     result = make_namespace(path, 'flimp-test', 'For the purposes of'
                             ' testing flimp')
     self.assertEqual(path, result.path)
     # be a good citizen an tidy up the mess
     result.delete()
     ns = Namespace("test/%s" % unique_ns)
     ns.delete()
Example #12
0
 def testPermissions(self):
     n = Namespace(u'test')
     # Get good
     self.db.add_resp(200, 'application/json',
                      '{"policy": "closed", "exceptions": ["test"]}')
     p = n.permissions['create']
     self.assertTrue(isinstance(p, Permission))
     self.assertEquals(self.db.reqs[0],
                       ('GET', '/permissions/namespaces/test', NO_CONTENT, {
                           u'action': 'create'
                       }, None))
Example #13
0
 def test_generate(self):
     template = TEMPLATE[0]
     root_namespace = Namespace('test')
     name = str(uuid.uuid4())
     tags = {}
     generate(root_namespace, name, template, 'flimp unit-test suite',
              'flimp-test', tags)
     self.assertEqual(4, len(tags))
     self.assertTrue('test/%s/foo' % name in tags)
     self.assertTrue('test/%s/baz/qux' % name in tags)
     self.assertTrue('test/%s/quux' % name in tags)
     self.assertTrue('test/%s/corge' % name in tags)
Example #14
0
 def test_make_tag(self):
     # create a new tag
     parent_ns = Namespace('test')
     tag_name = str(uuid.uuid4())
     expected_path = 'test/%s' % tag_name
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     # try to create an existing tag (just return the existing one)
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     result.delete()
Example #15
0
    def testQueryWithUnicodeTagName(self):
        """
        Make sure that a query using a tag whose name contains non-ASCII
        unicode characters works correctly.

        See https://bugs.edge.launchpad.net/fluiddb/+bug/681354 for the reason
        this is tested.
        """
        # Use the testuser1 root namespace.
        ns = Namespace('testuser1')
        # Umlauts FTW!
        tag_name = u'C\xfc\xe4h'
        # Create the tag.
        tag = ns.create_tag(tag_name, 'Used for testing purposes', False)
        try:
            # Run a query that uses the tag.  If we haven't fixed the bug,
            # FluidDB will hang at this point.
            result = Object.filter('has testuser1/%s' % tag_name)
            # Check the result is an empty list (i.e., no results found).
            self.assertEqual([], result)
        finally:
            # Clean up the tag.
            tag.delete()
Example #16
0
    def testQueryWithUnicodeTagName(self):
        """
        Make sure that a query using a tag whose name contains non-ASCII
        unicode characters works correctly.

        See https://bugs.edge.launchpad.net/fluiddb/+bug/681354 for the reason
        this is tested.
        """
        # Use the testuser1 root namespace.
        ns = Namespace('testuser1')
        # Umlauts FTW!
        tag_name = u'C\xfc\xe4h'
        # Create the tag.
        tag = ns.create_tag(tag_name, 'Used for testing purposes', False)
        try:
            # Run a query that uses the tag.  If we haven't fixed the bug,
            # FluidDB will hang at this point.
            result = Object.filter('has testuser1/%s' % tag_name)
            # Check the result is an empty list (i.e., no results found).
            self.assertEqual([], result)
        finally:
            # Clean up the tag.
            tag.delete()
Example #17
0
def make_namespace(path, name, desc):
    """
    Given a path, name and description will attempt to create and return a new
    namespace.

    path - the path to the new namespace

    name - the name of the dataset that's causing this namespace to be created
    (used when setting the description of the new namespace)

    desc - the description of the dataset that's causing the namespace to be
    create (used when setting the description of the new namespace)
    """
    try:
        logger.info('Checking namespace %r' % path)
        ns_head, ns_tail = os.path.split(path)
        result = Namespace(path)
        result.create(NAMESPACE_DESC % (ns_tail, name, desc))
        logger.info('Done')
    except Fluid412Error:
        # 412 simply means the namespace already exists
        result = Namespace(path)
        logger.info('%r already existed' % result.path)
    return result
Example #18
0
def generateNamespaceData(username):
    """Generate random namespace, tag and tag value data.

    @param username: The username to connect as.
    """
    rootNamespace = Namespace(username)
    name = 'namespace-%s' % ''.join(
        choice(ascii_letters) for i in xrange(randint(8, 12)))
    namespace = rootNamespace.create_namespace(name, 'A child namespace')
    logQueue.put(('CREATE_NAMESPACE path=%s/%s', (username, name)))
    countQueue.put(1)

    for tagName in WORDS:
        tag = namespace.create_tag(tagName, 'A tag', False)
        logQueue.put(('CREATE_TAG path=%s/%s/%s', (username, name, tagName)))
        countQueue.put(1)
        for i in range(randint(2, 20)):
            value = getRandomValue()
            about = 'namespace %s tag %s count %d' % (name, tagName, i)
            obj = Object(uuid4(), about=about)
            obj.set(tag.path, value)
            logQueue.put(('CREATE_TAG_VALUE value=%s tag=%s/%s/%s',
                          (value, username, name, tagName)))
            countQueue.put(1)
Example #19
0
def generateNamespaceData(username):
    """Generate random namespace, tag and tag value data.

    @param username: The username to connect as.
    """
    rootNamespace = Namespace(username)
    name = 'namespace-%s' % ''.join(choice(ascii_letters)
                                    for i in xrange(randint(8, 12)))
    namespace = rootNamespace.create_namespace(name, 'A child namespace')
    logQueue.put(('CREATE_NAMESPACE path=%s/%s', (username, name)))
    countQueue.put(1)

    for tagName in WORDS:
        tag = namespace.create_tag(tagName, 'A tag', False)
        logQueue.put(('CREATE_TAG path=%s/%s/%s', (username, name, tagName)))
        countQueue.put(1)
        for i in range(randint(2, 20)):
            value = getRandomValue()
            about = 'namespace %s tag %s count %d' % (name, tagName, i)
            obj = Object(uuid4(), about=about)
            obj.set(tag.path, value)
            logQueue.put(('CREATE_TAG_VALUE value=%s tag=%s/%s/%s',
                          (value, username, name, tagName)))
            countQueue.put(1)
Example #20
0
def make_namespace(path, name, desc):
    """
    Given a path, name and description will attempt to create and return a new
    namespace.

    path - the path to the new namespace

    name - the name of the dataset that's causing this namespace to be created
    (used when setting the description of the new namespace)

    desc - the description of the dataset that's causing the namespace to be
    create (used when setting the description of the new namespace)
    """
    try:
        logger.info('Checking namespace %r' % path)
        ns_head, ns_tail = os.path.split(path)
        result = Namespace(path)
        result.create(NAMESPACE_DESC % (ns_tail, name, desc))
        logger.info('Done')
    except Fluid412Error:
        # 412 simply means the namespace already exists
        result = Namespace(path)
        logger.info('%r already existed' % result.path)
    return result
Example #21
0
                       values=dictTags)


if __name__ == "__main__":

    #############################
    # Bind to FluidInfo instance
    fileCredentials = open(os.path.expanduser('~/.fluidDBcredentials'), 'r')
    username = fileCredentials.readline().strip()
    password = fileCredentials.readline().strip()
    fileCredentials.close()
    # fdb = Fluid('https://sandbox.fluidinfo.com')  # The sandbox instance
    fdb = Fluid()  # The main instance
    fdb.login(username, password)
    fdb.bind()
    nsUser = Namespace(username)

    sUserNS = nsUser.path  # Ugly use of a global, I know. :-)

    dictObjects = dict()

    fRequest = urllib2.urlopen(urlISOcodeListing)

    # Get enconding of raw listing.
    # This should usually be UTF-8, but it could change and cause a big headache!
    # sEncoding = fRequest.headers['content-type'].split('charset=')[-1]
    # ^^^^This is not working, since http://loc.org is not specifying the encoding. Dammit!
    #      fRequest.headers['content-type'] = 'text/plain'
    #        instead of:
    #      fRequest.headers['content-type'] = 'text/html; charset=utf-8'
    # So we hardcode it:
Example #22
0
                       values=dictTags)


if __name__ == "__main__":

    #############################
    # Bind to FluidInfo instance
    fileCredentials = open(os.path.expanduser('~/.fluidDBcredentials'), 'r')
    username = fileCredentials.readline().strip()
    password = fileCredentials.readline().strip()
    fileCredentials.close()
    # fdb = Fluid('https://sandbox.fluidinfo.com')  # The sandbox instance
    fdb = Fluid()  # The main instance
    fdb.login(username, password)
    fdb.bind()
    nsUser = Namespace(username)

    sUserNS = nsUser.path  # Ugly use of a global, I know. :-)

    dictObjects = dict()

    ldIWM = GetInterwikimap()

    for sIwmPrefix, dIWM in ldIWM.items():
        Response = fdb.values.get(
            query=u'fluiddb/about="' + sIwmPrefix + '" AND (HAS ' + sUserNS +
            u'/lang/iso639/1 OR HAS ' + sUserNS + u'/lang/iso639/2)',
            taglist=[
                sUserNS + '/lang/iso639/related-2B',
                sUserNS + '/lang/iso639/related-2T'
            ])
Example #23
0
from fom.dev import sandbox_fluid
from fom.mapping import Object, Namespace, tag_value, tag_relation

# Use and bind the sandbox (for playing)
fluid = sandbox_fluid()

# let's start by creating a new Namespace for this application and then some
# tags

# Use the test user's namespace
ns = Namespace(u'test')

# create a child namespace for ourselves
ns.create_namespace(u'maptest', u'a test namespace')

# use our child namespace
ns = Namespace(u'test/maptest')

# create some tags
ns.create_tag(u'description', u'description', indexed=False)
ns.create_tag(u'timestamp', u'description', indexed=False)
ns.create_tag(u'username', u'description', indexed=False)

# Now we will define some behaviours mapping to groups of individual tags


class Describable(Object):
    """Mixin to provide describable behaviour
    """
    description = tag_value(u'test/maptest/description')
Example #24
0
 def testChildTag(self):
     n = Namespace(u'test')
     child = n.tag(u'test')
     self.assertTrue(isinstance(child, Tag))
     self.assertEquals(child.path, u'test/test')
Example #25
0
 def testChildNamespace(self):
     n = Namespace(u'test')
     child = n.namespace(u'test')
     self.assertTrue(isinstance(child, Namespace))
     self.assertEquals(child.path, u'test/test')
Example #26
0
 def testChildNamespace(self):
     n = Namespace(u'test')
     child = n.namespace(u'test')
     self.assertTrue(isinstance(child, Namespace))
     self.assertEquals(child.path, u'test/test')
Example #27
0
 def testDescription(self):
     ns = Namespace(u'test/test')
     ns.description = u'testDesc'
     self.assertEqual(self.last, ('PUT', u'/namespaces/test/test', {
         u'description': u'testDesc'
     }, None, None))
Example #28
0
 def testChildTag(self):
     n = Namespace(u'test')
     child = n.tag(u'test')
     self.assertTrue(isinstance(child, Tag))
     self.assertEquals(child.path, u'test/test')
Example #29
0
 def testNew(self):
     n = Namespace(u'test')
     self.assertEquals(n.path, u'test')
     self.assertTrue(n.fluid is self.api)
Example #30
0

from fom.dev import sandbox_fluid
from fom.mapping import Object, Namespace, tag_value, tag_relation

# Use and bind the sandbox (for playing)
fluid = sandbox_fluid()

# let's start by creating a new Namespace for this application and then some
# tags

# Use the test user's namespace
ns = Namespace(u'test')

# create a child namespace for ourselves
ns.create_namespace(u'maptest', u'a test namespace')

# use our child namespace
ns = Namespace(u'test/maptest')

# create some tags
ns.create_tag(u'description', u'description', indexed=False)
ns.create_tag(u'timestamp', u'description', indexed=False)
ns.create_tag(u'username', u'description', indexed=False)


# Now we will define some behaviours mapping to groups of individual tags

class Describable(Object):
    """Mixin to provide describable behaviour
    """
Example #31
0
def create_tags():
    ns = Namespace(u'test/medical')
    ns.create(u'Medical tags')
    ns.create_tag(u'date_of_birth', u'Date of birth', True)
    ns.create_tag(u'age', u'Decimal age', True)
    ns.create_tag(u'height', u'Height', True)
    ns.create_tag(u'weight', u'Weight', True)
    ns.create_tag(u'bmi', u'Body Mass Index', True)
    ns.create_tag(u'date', u'Date', True)
    ns.create_tag(u'sex', u'Sex', True)
    ns.create_tag(u'pubertal_stage', u'Pubertal stage')