def testTags(self): o = Object() o.uid = '3' self.db.add_resp(200, 'application/json', '{"tagPaths": []}') self.assertEqual(o.tag_paths, []) self.assertEqual(self.db.reqs[0], ('GET', '/objects/3', NO_CONTENT, { 'showAbout': False }, None)) self.db.add_resp(200, 'application/json', '{"tagPaths": []}') self.assertEquals(o.tags, []) self.assertEqual(self.db.reqs[1], ('GET', '/objects/3', NO_CONTENT, { 'showAbout': False }, None)) self.db.add_resp(200, 'application/json', '{"tagPaths": ["test\\/fomtest"]}') self.assertTrue('test/fomtest' in o.tag_paths) self.assertEqual(self.db.reqs[2], ('GET', '/objects/3', NO_CONTENT, { 'showAbout': False }, None)) self.db.add_resp(200, 'application/json', '{"tagPaths": ["test\\/fomtest"]}') self.assertEquals(o.tags[0].path, 'test/fomtest') self.assertEqual(self.db.reqs[3], ('GET', '/objects/3', NO_CONTENT, { 'showAbout': False }, None))
def testGet(self): o = Object() o.uid = '9' o.get(u'test/test') self.assertEqual( self.last, ('GET', u'/objects/9/test/test', NO_CONTENT, None, None))
def get_object(uuid=None, about=None): """ Returns the referenced object or a new object if uuid or about are not given. """ logger.info("Getting object") if uuid: logger.info("Object with uuid %r" % uuid) return Object(uid=uuid) elif about: logger.info("Object with about tag value: %r" % about) return Object(about=about) else: o = Object() o.create() logger.info("New object with uuid %r" % o.uid) return o
def testSetPrimitive(self): o = Object() o.uid = '9' for i, value in enumerate((None, True, False, 123, 45.67, 'hey')): o.set(u'test/test', value) self.assertEqual(value, o._cache[u'test/test']) self.assertEqual( self.db.reqs[i], ('PUT', u'/objects/9/test/test', value, None, None))
def testCreate(self): """Creating an object works! """ o = Object() self.db.add_resp(201, 'application/json', '{"id": "9d4", "URI": "https"}') o.create() self.assert_(o.uid) self.assertEqual(self.last, ('POST', '/objects', {}, None, None))
def testCreateWithAbout(self): """Make sure creating an object with an about tag value works """ self.db.add_resp(201, 'application/json', '{"id": "9d4", "URI": "https"}') o = Object(about="foo") self.assert_(o.uid) self.assertEqual(self.last, ('POST', '/objects', { u'about': 'foo' }, None, None))
def testHas(self): o = Object() o.uid = '0' self.db.add_resp(404, 'application/json', 'TNoInstanceOnObject') self.assertFalse(o.has('test/fomtest')) self.assertEqual( self.db.reqs[0], ('HEAD', '/objects/0/test/fomtest', NO_CONTENT, None, None)) self.db.add_resp(200, 'application/vnd.fluiddb.value+json', '') self.assertTrue(o.has('test/fomtest')) self.assertEqual( self.db.reqs[1], ('HEAD', '/objects/0/test/fomtest', NO_CONTENT, None, None))
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)
def testEquality(self): b = Object() b.uid = '7' a = Object(b.uid) self.assertEqual(a, b)
def testSetOpaque(self): o = Object() o.uid = '7' o.set(u'test/test', 'xyz', 'application/bananas') self.assertEqual(self.last, ('PUT', u'/objects/7/test/test', 'xyz', None, 'application/bananas'))
def testNew(self): """Make sure a new object is in the correct state """ o = Object() self.assertTrue(o.uid is None)