def test_block(self):
     m = Block(ID((1, 3)), BRLBlock("user/user/block/master", 1))
     # print "M: " + str(m)
     s = m.serialize()
     # print "S: " + str(s)
     m2 = Block.deserialize(s)
     # print "S: " + str(m2.serialize())
     # print "S2: " + str(m2)
     self.assertEqual(m, m2)
Exemple #2
0
 def test_block(self):
     m = Block(ID((1, 3)), BRLBlock('user/user/block/master', 1))
     #print "M: " + str(m)
     s = m.serialize()
     #print "S: " + str(s)
     m2 = Block.deserialize(s)
     #print "S: " + str(m2.serialize())
     #print "S2: " + str(m2)
     self.assertEqual(m, m2)
    def testUpdateNotExistingError(self):
        # Not existing collection with not existing object
        self.assertRaises(MongoNotFoundUpdatingException,
                          self.store._update_collection,
                          "notexitingcollection", {'a': 1},
                          set_statement={'a': 2},
                          upsert=False,
                          trx_record=False)

        # Existing collection with not existing object
        self.assertRaises(MongoNotFoundUpdatingException,
                          self.store._update_collection,
                          GenericServerStore.USER_ST, {'a': 1},
                          set_statement={'a': 2},
                          upsert=False,
                          trx_record=False)

        # Existing object update
        myblock = Block(ID((9, 2)), BRLBlock("user/user/myblock/master"))
        self.store.create_block(myblock)
        ret = self.store._update_collection(
            GenericServerStore.BLOCK_ST,
            {Block.SERIAL_ID_KEY: myblock.ID.serialize()},
            set_statement={"$set": {
                Block.SERIAL_CONTENT_COUNTER: 89
            }},
            upsert=False,
            trx_record=False)
        self.assertIsInstance(ret, dict)

        # Existing object update but without changes
        ret = self.store._update_collection(
            GenericServerStore.BLOCK_ST,
            {Block.SERIAL_ID_KEY: myblock.ID.serialize()},
            set_statement={"$set": {
                Block.SERIAL_CONTENT_COUNTER: 89
            }},
            upsert=False,
            trx_record=False)
        self.assertIsInstance(ret, dict)

        # Upsert an existing object
        the_id = ID((22, 33))
        myblock = Block(the_id, BRLBlock("user/user/myblock2/master"))
        self.store.create_block(myblock)
        ret = self.store._update_collection(
            GenericServerStore.BLOCK_ST,
            {Block.SERIAL_ID_KEY: myblock.ID.serialize()},
            set_statement={"$set": {
                Block.SERIAL_CONTENT_COUNTER: 89
            }},
            upsert=True,
            trx_record=False)
        self.assertIsInstance(ret, dict)
 def test_insert_read_block(self):
     name = BRLBlock('%s/%s/TestBlock/trunk' % (self.user.ID, self.user.ID))
     mid = self.user.add_block(name)
     block = Block(mid, name)
     self.store.create_block(block)
     retrieved1 = self.store.read_block(name)
     self.assertEqual(block, retrieved1)
 def make_block(self, user=None, block=None):
     if user is None:
         user = self.make_test_user()
     brl_block = BRLBlock('%s/%s/TestBlock/master' % (user.ID, user.ID))
     mid = user.add_block(brl_block)
     self._db.update_user(user)
     if not block:
         block = Block(mid, brl_block)
     self._db.create_block(block)
     return block
    def test_read_published_blocks_info(self, store_cls):
        """Insert a block and read all published blocks info (brl, lastpubdate)"""
        if store_cls == MongoServerStore:
            store = MongoServerStore(self.conn, self.__class__.__name__)
        else:
            store = TestingMemServerStore()
        block = Block(ID((23, 23)), BRLBlock("bonjovi/bonjovi/itsmylife/master"))
        ppack = PublishRequest(block.last_version())
        r1 = SimpleCell('user/block/r1.h')
        ppack.cells.append(r1)
        ppack.contents['r1.h'] = Content(id_=None, load=Blob('hola'))

        block.add_publication(ppack)
        store.create_block(block, False)
        ret = store.read_published_blocks_info()
        first = ret.next()

        self.assertEquals(first[0], "bonjovi/bonjovi/itsmylife/master")
        self.assertEquals(first[1].__class__, datetime.datetime)
    def create_block(self, brl, private=False):
        '''Creates a block in server due the brl and description'''
        self.security.check_create_block(brl.owner, private)
        user = self._store.read_user(brl.owner)
        try:
            block_id = user.add_block(brl)  # should fail if existing
        except DuplicateBlockException:
            logger.debug('Block %s already existing, not creating it' % brl)
            raise

        block = Block(block_id, brl)
        try:  # FIXME: better upsert?
            self._store.create_block(block, private)  # should fail if existing
        except AlreadyInStoreException:
            pass
        self._store.update_user(user)  # raise exception if not current

        return user
Exemple #8
0
 def setUp(self):
     self.block_id = ID((1, 2))
     self.block = Block(self.block_id, None)
     self.brl = BRLBlock("user/user/block/master")
Exemple #9
0
class BlockTest(unittest.TestCase):
    def setUp(self):
        self.block_id = ID((1, 2))
        self.block = Block(self.block_id, None)
        self.brl = BRLBlock("user/user/block/master")

    def test_new_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        self.block.add_publication(publish_request)
        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(100))
        self.assertEquals({'r1.h': ID(self.block_id + 0)},
                          self.block.last_version_cells())

    def test_add_modify_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 1)},
                         self.block.cells.get_all_ids(1))
        self.assertEqual({'r1.h': ID(self.block_id + 1)},
                         self.block.last_version_cells())

    def test_add_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.tag = STABLE
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)},
                         self.block.contents.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.tag = STABLE
        publish_request.deleted.append('r1.h')
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': self.block_id + 0},
                         self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': self.block_id + 0},
                         self.block.contents.get_all_ids(0))

        self.assertEqual({}, self.block.cells.get_all_ids(1))
        self.assertEqual({}, self.block.contents.get_all_ids(1))
        self.assertEqual({}, self.block.last_version_cells())

    def test_add_modify_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        ids0 = set(self.block.cells.get_all_ids(0).values())
        names0 = set(self.block.cells.get_all_ids(0).keys())
        expected_ids0 = set([
            ID(self.block_id + 0),
            ID(self.block_id + 1),
            ID(self.block_id + 2)
        ])
        expected_names0 = set(['r1.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.deleted.append('r1.h')
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r4.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        prev = self.block.cells.get_all_ids(0)
        id3 = prev['r3.h']
        expected = set([id3, ID(self.block_id + 3), ID(self.block_id + 4)])
        self.assertEqual(expected,
                         set(self.block.cells.get_all_ids(1).values()))
        expected = set(['r4.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected, set(self.block.cells.get_all_ids(1).keys()))
        self.assertEqual(expected, set(self.block.last_version_cells().keys()))

    def test_renames(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.contents['r2.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r3.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r11.h'))
        publish_request.deleted.append('r1.h')
        publish_request.renames = Renames(
            {CellName('r1.h'): CellName('r11.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 1))
        publish_request.cells.append(SimpleCell('user/block/r21.h'))
        publish_request.deleted.append('r2.h')
        publish_request.renames = Renames(
            {CellName('r2.h'): CellName('r21.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEquals({}, self.block.get_renames(0, 0))
        self.assertEquals({'r1.h': 'r11.h'}, self.block.get_renames(0, 1))
        self.assertEquals({
            'r2.h': 'r21.h',
            'r1.h': 'r11.h'
        }, self.block.get_renames(0, 2))
Exemple #10
0
 def setUp(self):
     self.block_id = ID((1, 2))
     self.block = Block(self.block_id, None)
     self.brl = BRLBlock("user/user/block/master")
Exemple #11
0
class BlockTest(unittest.TestCase):

    def setUp(self):
        self.block_id = ID((1, 2))
        self.block = Block(self.block_id, None)
        self.brl = BRLBlock("user/user/block/master")

    def test_new_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        self.block.add_publication(publish_request)
        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(100))
        self.assertEquals({'r1.h': ID(self.block_id + 0)}, self.block.last_version_cells())

    def test_add_modify_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 1)}, self.block.cells.get_all_ids(1))
        self.assertEqual({'r1.h': ID(self.block_id + 1)}, self.block.last_version_cells())

    def test_add_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.tag = STABLE
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': ID(self.block_id + 0)}, self.block.contents.get_all_ids(0))

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.tag = STABLE
        publish_request.deleted.append('r1.h')
        self.block.add_publication(publish_request)

        self.assertEqual({'r1.h': self.block_id + 0}, self.block.cells.get_all_ids(0))
        self.assertEqual({'r1.h': self.block_id + 0}, self.block.contents.get_all_ids(0))

        self.assertEqual({}, self.block.cells.get_all_ids(1))
        self.assertEqual({}, self.block.contents.get_all_ids(1))
        self.assertEqual({}, self.block.last_version_cells())

    def test_add_modify_delete_cell(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        ids0 = set(self.block.cells.get_all_ids(0).values())
        names0 = set(self.block.cells.get_all_ids(0).keys())
        expected_ids0 = set([ID(self.block_id + 0), ID(self.block_id + 1), ID(self.block_id + 2)])
        expected_names0 = set(['r1.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.deleted.append('r1.h')
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.cells.append(SimpleCell('user/block/r4.h'))
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEqual(expected_ids0, ids0)
        self.assertEqual(expected_names0, names0)

        prev = self.block.cells.get_all_ids(0)
        id3 = prev['r3.h']
        expected = set([id3, ID(self.block_id + 3), ID(self.block_id + 4)])
        self.assertEqual(expected, set(self.block.cells.get_all_ids(1).values()))
        expected = set(['r4.h', 'r2.h', 'r3.h'])
        self.assertEqual(expected, set(self.block.cells.get_all_ids(1).keys()))
        self.assertEqual(expected, set(self.block.last_version_cells().keys()))

    def test_renames(self):
        publish_request = PublishRequest(BlockVersion(self.brl, -1))
        publish_request.cells.append(SimpleCell('user/block/r1.h'))
        publish_request.contents['r1.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r2.h'))
        publish_request.contents['r2.h'] = Content(id_=None, load=None)
        publish_request.cells.append(SimpleCell('user/block/r3.h'))
        publish_request.contents['r3.h'] = Content(id_=None, load=None)
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 0))
        publish_request.cells.append(SimpleCell('user/block/r11.h'))
        publish_request.deleted.append('r1.h')
        publish_request.renames = Renames({CellName('r1.h'): CellName('r11.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        publish_request = PublishRequest(BlockVersion(self.brl, 1))
        publish_request.cells.append(SimpleCell('user/block/r21.h'))
        publish_request.deleted.append('r2.h')
        publish_request.renames = Renames({CellName('r2.h'): CellName('r21.h')})
        publish_request.tag = STABLE
        self.block.add_publication(publish_request)

        self.assertEquals({}, self.block.get_renames(0, 0))
        self.assertEquals({'r1.h': 'r11.h'}, self.block.get_renames(0, 1))
        self.assertEquals({'r2.h': 'r21.h', 'r1.h': 'r11.h'}, self.block.get_renames(0, 2))