def testCreateTags(self): """ Checks that a given set of tags from delicious are created in the right place in FluidDB. """ delicious2fluid.login(USERNAME, PASSWORD) tags = set(['foo', 'bar', 'baz']) unique_ns = str(uuid.uuid4()) try: # create the test namespace(s) headers, result = delicious2fluid.call('POST', '/namespaces/test', {'name': unique_ns, 'description': 'a test namespace'}) self.assertEquals('201', headers['status']) # create the tags delicious2fluid.createTags(tags, 'test/%s' % unique_ns) # check they exist for tag in tags: path = '/tags/test/%s/%s' % (unique_ns, tag) headers, result = delicious2fluid.call('GET', path) self.assertEquals('200', headers['status']) finally: # remove the tags for tag in tags: path = '/tags/test/%s/%s' % (unique_ns, tag) delicious2fluid.call('DELETE', path) # remove the test namespace(s) delicious2fluid.call('DELETE', '/namespaces/test/%s' % unique_ns)
def testCreateObjects(self): """ Checks that objects are created correctly and have the appropriate tags associated with them. """ # A couple of mock "objects" obj1 = {'foo': 'A', 'bar': 'B', 'tag': ['foo', 'bar'], 'title': 'foo bar', 'notes': 'baz'} obj2 = {'foo': 'C', 'bar': 'C', 'tag': ['foo', 'bar'], 'title': 'foo bar', 'notes': 'baz'} objs = [obj1, obj2] # Set things up delicious2fluid.login(USERNAME, PASSWORD) tags = set(['foo', 'bar']) unique_ns = str(uuid.uuid4()) try: # create the test namespace(s) headers, result = delicious2fluid.call('POST', '/namespaces/test', {'name': unique_ns, 'description': 'a test namespace'}) self.assertEquals('201', headers['status']) headers, result = delicious2fluid.call('POST', '/namespaces/test/%s' % unique_ns, {'name': 'delicious', 'description': 'a test namespace'}) self.assertEquals('201', headers['status']) # create the tags delicious2fluid.createTags(tags, 'test/%s' % unique_ns) # create the objects delicious2fluid.createObjects(objs, 'test/%s' % unique_ns, about='foo') # Check there are two objects tagged with the 'foo' and 'bar' tags for tag in tags: query_tag = 'has test/%s/%s' % (unique_ns, tag) headers, result = delicious2fluid.call('GET', '/objects', query=query_tag) # there are two objects that are tagged self.assertEquals(2, len(result['ids'])) finally: # remove the tags tags.add('tag') for tag in tags: tag_path = '/tags/test/%s/%s' % (unique_ns, tag) tag_path_obj = '/tags/test/%s/delicious/%s' % (unique_ns, tag) delicious2fluid.call('DELETE', tag_path) delicious2fluid.call('DELETE', tag_path_obj) delicious2fluid.call('DELETE', '/tags/test/%s/title' % unique_ns) delicious2fluid.call('DELETE', '/tags/test/%s/notes' % unique_ns) # remove the test namespaces delicious2fluid.call('DELETE', '/namespaces/test/%s/delicious' % unique_ns) delicious2fluid.call('DELETE', '/namespaces/test/%s' % unique_ns)