Beispiel #1
0
    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())
Beispiel #2
0
    def setUp(self):
        self.folder = self.new_tmp_folder()

        brl_block = BRLBlock('dummy/dummy/block/master')
        self.block_version = BlockVersion(brl_block, 0)

        alf = Resource(SimpleCell("dummy/block/alf.c"),
                       Content(ID((0, 1, 2)), Blob("Hello Alf")))
        alf.cell.ID = ID((0, 1, 2))
        willy = Resource(SimpleCell("dummy/block/willy.c"),
                         Content(ID((0, 1, 3)), Blob("Hello Willy")))
        willy.cell.ID = ID((0, 1, 45))

        self.referenced_resources = ReferencedResources()
        self.referenced_resources[self.block_version].update({
            CellName("alf.c"):
            alf,
            CellName("willy.c"):
            willy
        })
        self.cells_snapshot = [CellName("alf.c"), CellName("willy.c")]
        self.dep_table = BlockVersionTable()

        self.restapi = Mock(BiiAPI)
        self.restapi.get_published_resources.return_value = self.referenced_resources
        self.restapi.get_cells_snapshot.return_value = self.cells_snapshot
        self.restapi.get_dep_table.return_value = self.dep_table
        self.restapi.get_version_delta_info.return_value = BlockDelta(
            '', DEV, None)
        self.localdb = LocalDB(os.path.join(self.folder, 'bii.db'))
        self.proxy = BiiAPIProxy(self.localdb, self.restapi, Mock())
Beispiel #3
0
    def test_compatible(self):
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()

        brl0 = BRLBlock('user/user/block/master')
        brl1 = BRLBlock('user/user/block2/master')
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)
        v2 = BlockVersion(brl1, 0)
        v3 = BlockVersion(brl1, 1)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))
        content_id2 = ID((0, 0, 1))

        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        c2.add_item((cell_id1, content_id1),  cell_id1, v1, 'file1')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        c1.add_item((cell_id2, content_id2),  cell_id2, v2, 'file2')
        c2.add_item((cell_id2, content_id2),  cell_id2, v3, 'file2')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))
Beispiel #4
0
    def test_empty(self):
        '''when one is empty, always compatible'''
        c1 = CompatibilityClosure()
        c2 = CompatibilityClosure()
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        brl0 = BRLBlock('user/user/block/master')
        brl1 = BRLBlock('user/user/block2/master')
        v0 = BlockVersion(brl0, 0)
        v2 = BlockVersion(brl1, 0)

        cell_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 0, 1))

        content_id1 = ID((0, 0, 0))
        content_id2 = ID((0, 0, 1))

        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))

        c1.add_item((cell_id2, content_id2),  cell_id2, v2, 'file2')
        self.assertEqual(0, c1.conflicts(c2))
        self.assertEqual(0, c2.conflicts(c1))
Beispiel #5
0
    def test_interface(self):
        cell_id1 = ID((0, 0, 0))
        content_id1 = ID((0, 0, 0))
        cell_id2 = ID((0, 1, 0))
        content_id2 = ID((0, 1, 0))
        brl0 = BRLBlock('user/user/block/master')
        brl1 = BRLBlock('user/user/block2/master')
        v0 = BlockVersion(brl0, 0)
        v1 = BlockVersion(brl0, 1)
        v2 = BlockVersion(brl1, 0)

        c1 = CompatibilityClosure()
        c1.add_item((cell_id1, content_id1),  cell_id1, v0, 'file1')
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 0, 'file1')}", str(c1))

        # adding a compatible item is no problem
        c1.add_item((cell_id1, content_id1),  cell_id1, v1, 'file1')
        self.assertEqual("{0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')}", str(c1))

        c1.add_item((cell_id2, content_id2),  cell_id2, v2, 'file2')
        self.assertIn("0:0:0: ((0:0:0, 0:0:0), user/block: 1, 'file1')", str(c1))
        self.assertIn("0:1:0: ((0:1:0, 0:1:0), user/block2: 0, 'file2')", str(c1))

        self.assertEqual({v0.block_name + 'file1', v2.block_name + 'file2'}, c1.block_cell_names)

        refs = References()
        refs[v1].add('file1')
        refs[v2].add('file2')
        self.assertEqual(refs, c1.references)
Beispiel #6
0
 def test_byte_order(self):
     i1 = ID((1, 2, 3))
     bin_id = i1.serialize()
     for i in [0, 1, 2, 4, 5, 6, 8, 9, 10]:
         self.assertEqual('\x00', bin_id[i])
     self.assertEqual('\x01', bin_id[3])
     self.assertEqual('\x02', bin_id[7])
     self.assertEqual('\x03', bin_id[11])
Beispiel #7
0
 def test_byte_order(self):
     i1 = ID((1, 2, 3))
     bin_id = i1.serialize()
     for i in [0, 1, 2, 4, 5, 6, 8, 9, 10]:
         self.assertEqual('\x00', bin_id[i])
     self.assertEqual('\x01', bin_id[3])
     self.assertEqual('\x02', bin_id[7])
     self.assertEqual('\x03', bin_id[11])
Beispiel #8
0
 def test_address_table(self):
     a = AddressTable(ID((1, 3)))
     a.create(CellName('f2.h'), ID((1, 3, 18)), 2)
     s = serialize(a)
     #print "S: " + str(s)
     b = AddressTable.deserialize(s, ID((1, 3)))
     #print "B: " + str(b)
     self.assertEqual(a, b)
Beispiel #9
0
 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 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)
Beispiel #11
0
    def test_simple_published_cell(self):
        # Simple publish resource
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = ID()
        simpleresource.root = ID()

        # Include inside "a" the "kls" attribute
        s = simpleresource.serialize()

        self.assertEqual(
            s[Deserializer.POLIMORPHIC_KEYWORD],
            ClassTypedSerializer.getValue(simpleresource.__class__))
        ob = CellDeserializer(ID).deserialize(s)
        self.assert_bii_equal(simpleresource, ob)
 def _publishDependentCell(self, block_id):
     low, high = self._biigraph._get_range_block(block_id)
     count = 0
     d = self.lbcn
     bcn = d[block_id]
     brl = self._getBlockBRL(bcn)
     for row in range(low, high + 1):
         r = SimpleCell(d[block_id])
         r.root = ID((0, bcn.block_name[-1:], 0))
         deps = DependencySet()
         dep_table = BlockVersionTable()
         for block in range(block_id):
             time = self._biigraph._get_dep_elem_offset(row, block)
             if time != -1:
                 deps.add_implicit(d[block])
                 dep_table[d[block].block_name] = \
                    BlockVersion(self._getBlockBRL(d[block]), time)
         r.dependencies = deps
         pack = PublishRequest(BlockVersion(brl, count - 1))
         pack.tag = STABLE
         count += 1
         pack.cells.append(r)
         pack.contents[r.name.cell_name] = Content(
             id_=None, load=Blob('hola {0}'.format(r.name.cell_name)))
         pack.deptable = dep_table
         self.service.publish(pack)
Beispiel #13
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.user = User("laso")
     self.user.password = "******"
     self.user.numeric_id = ID((22, ))
     self.user.firstname = "Jose"
     self.user.lastname = "Gomez"
     self.user.country = "ES"
     self.user.description = "Developer"
     self.user.email = "*****@*****.**"
     self.user.visible_email = True
     self.user.allow_mailing = True
     self.user.active = True
     self.user.staff = False
     self.user.joined_date = UtcDatetime.get_current_utc_datetime()
     self.user.last_api_call = UtcDatetime.get_current_utc_datetime()
     self.user.add_block(BRLBlock("laso/laso/block/master"), ["arduino"])
     # Profile fields
     self.user.street_1 = "Melancolia Street"
     self.user.street_2 = "123"
     self.user.city = "Madrid"
     self.user.postal_code = "28027"
     self.user.region = "Madrid"
     self.user.vat = "B81884306"
     self.user.tax_id = "ESB81884306"
     self.utc_datetime = UtcDatetime.deserialize(datetime.datetime.now())
Beispiel #14
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_CONFIRMATION_DATE, None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(
            BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(
            doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(
            str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
 def _changes():
     changes = Changes()
     changes.deleted['deleted'] = Resource(None, 'old_content')
     changes.deleted['renamed'] = Resource(
         SimpleCell('usr/block/renamed'),
         Content(ID((1234, )), load=Blob('old_content2')))
     changes.created['created'] = Resource(
         SimpleCell('usr/block/created'),
         Content(id_=None, load=Blob('created')))
     changes.created['renamed2'] = Resource(
         SimpleCell('usr/block/renamed2'),
         Content(id_=None, load=Blob('old_content2')))
     changes.modified['modified_cont'] = Modification(
         Resource(SimpleCell('usr/block/modified_cont'),
                  Content(id_=None, load=Blob('mod_content'))),
         Resource(SimpleCell('usr/block/modified_cont'),
                  Content(id_=None, load=Blob('mod_content2'))))
     changes.modified['modified_cell'] = Modification(
         Resource(SimpleCell('usr/block/modified_cell'),
                  Content(id_=None, load=Blob('mod_cell'))),
         Resource(SimpleCell('usr/block/modified_cell', CPP),
                  Content(id_=None, load=Blob('mod_cell'))))
     changes.modified['modified_both'] = Modification(
         Resource(SimpleCell('usr/block/modified_both'),
                  Content(id_=None, load='mod_both')),
         Resource(SimpleCell('usr/block/modified_both', CPP),
                  Content(id_=None, load=Blob('mod_both2'))))
     changes.renames = Renames({'renamed': 'renamed2'})
     return changes
    def read_content_sizes(self, content_ids):
        dbcol = self.db[GenericServerStore.PUBLISHED_CONTENT_ST]
        ids = [a.serialize() for a in content_ids]
        projection = {"l.sz": 1}
        cursor = dbcol.find({"_id": {"$in": ids}}, projection)
        result = {ID.deserialize(doc["_id"]): doc["l"]["sz"] for doc in cursor}

        return result
    def read_content_sizes(self, content_ids):
        dbcol = self.db[GenericServerStore.PUBLISHED_CONTENT_ST]
        ids = [a.serialize() for a in content_ids]
        projection = {"l.sz": 1}
        cursor = dbcol.find({"_id": {"$in": ids}}, projection)
        result = {ID.deserialize(doc["_id"]): doc["l"]["sz"] for doc in cursor}

        return result
Beispiel #18
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 generate_user_id(self):
     counters = self.db["counters"]
     updated = counters.find_and_modify(query={'_id': 'users'},
                                        update={"$inc": {
                                            'seq': 1
                                        }},
                                        upsert=True,
                                        new=True)
     return ID((updated['seq'], ))
Beispiel #20
0
    def test_id(self):
        rf = UserID(13)
        s = rf.serialize()
        rf2 = ID.deserialize(s)

        #print(str(rf.__class__))
        #print(str(rf2.__class__))

        self.assertEqual(rf, rf2)
 def test_insert_read_published_content(self):
     block = self.mother.make_block(self.user)
     brl = BlockCellName('%s/geom/sphere.cpp' % block.ID.owner)
     content = model_creator.make_content(brl, False)
     content.ID = ID((2, 3, 4))  # 'dummy_id'
     self.store.create_published_contents([content])
     retrieved = self.store.read_published_contents([content.ID])
     self.assertEqual(content, retrieved[content.ID])
     self.assertEqual(1, len(retrieved))
    def test_id(self):
        rf = UserID(13)
        s = rf.serialize()
        rf2 = ID.deserialize(s)

        #print(str(rf.__class__))
        #print(str(rf2.__class__))

        self.assertEqual(rf, rf2)
Beispiel #23
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(doc.get(User.SERIAL_CONFIRMATION_DATE,
                                                                 None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
Beispiel #24
0
 def deserialize(doc):
     numeric_id = ID.deserialize(doc[Block.SERIAL_NUMERIC_ID_KEY])
     m = Block(brl_id=BRLBlock(doc[Block.SERIAL_ID_KEY]), numeric_id=numeric_id)
     m._cells_table = AddressTable.deserialize(doc[Block.SERIAL_CELL_TABLE], numeric_id)
     m._contents_table = AddressTable.deserialize(doc[Block.SERIAL_CONTENT_TABLE], numeric_id)
     m._deps_table = TimeBaseMapDeserializer(BlockVersionTable).deserialize(doc[Block.SERIAL_DEPS_TABLE])
     m._renames = TimeBaseMapDeserializer(Renames).deserialize(doc[Block.SERIAL_RENAMES])
     m._deltas = ListDeserializer(BlockDelta).deserialize(doc[Block.SERIAL_DELTAS])
     m._cell_count = int(doc[Block.SERIAL_CELLS_COUNTER])
     m._content_count = int(doc[Block.SERIAL_CONTENT_COUNTER])
     return m
Beispiel #25
0
    def test_store_published_resources(self):
        s = References()
        brl_block = BRLBlock('dummy/dummy/block/master')
        block_version = BlockVersion(brl_block, 0)
        s[block_version] = [
            CellName("alf.c"),
            CellName("willy.c"),
            CellName('maya.h'),
            CellName('win/maya.h'),
            CellName('nix/maya.h')
        ]

        alf = Resource(SimpleCell("dummy/block/alf.c"),
                       Content(ID((0, 1, 2)), Blob("Hello Alf")))
        alf.cell.ID = ID((0, 1, 2))
        willy = Resource(SimpleCell("dummy/block/willy.c"),
                         Content(ID((0, 1, 3)), Blob("Hello Willy")))
        willy.cell.ID = ID((0, 1, 45))
        maya_v = Resource(VirtualCell("dummy/block/maya.h"), None)
        maya_v.cell.ID = ID((0, 1, 3))
        maya_win = Resource(SimpleCell("dummy/block/win/maya.h"),
                            Content(ID((0, 1, 4)), Blob("Hello Maya")))
        maya_win.cell.ID = ID((0, 1, 4))
        maya_nix = Resource(SimpleCell("dummy/block/nix/maya.h"),
                            Content(ID((0, 1, 5)), Blob("Hello Maya")))
        maya_nix.cell.ID = ID((0, 1, 5))

        # Expected return
        referenced_resources = ReferencedResources()
        referenced_resources[block_version].update({
            CellName("alf.c"):
            alf,
            CellName("willy.c"):
            willy,
            CellName('maya.h'):
            maya_v,
            CellName('win/maya.h'):
            maya_win,
            CellName('nix/maya.h'):
            maya_nix,
        })

        self.db.create_published_resources(referenced_resources)
        retrieved = self.db.get_published_resources(s)

        self.assertEquals(referenced_resources, retrieved)
Beispiel #26
0
    def test_content(self):
        #Content with ContentID
        c = Content(ID((0, 1, 2)), load=Blob("Hello"))
        s = c.serialize()
        c2 = ContentDeserializer(ID).deserialize(s)
        self.assertEqual(c, c2)

        #Content with BlockCellName
        c = Content(BlockCellName("user/block/path/to/file.h"),
                    load=Blob("Bye"))
        s = c.serialize()
        c2 = ContentDeserializer(BlockCellName).deserialize(s)
        self.assertEqual(c, c2)
Beispiel #27
0
    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()))
Beispiel #28
0
    def test_simple_edition_cell_with_container(self):
        virtual_cell = BlockCellName('user/block/path/file.h')
        simpleresource = SimpleCell("user/block/path/to/file.h")
        simpleresource.ID = BlockCellName("user/block/path/to/file.h")
        simpleresource.root = ID()
        simpleresource.dependencies.add_implicit(
            BlockCellName("user/block/path/file.h"))
        simpleresource.container = virtual_cell

        s = simpleresource.serialize()

        self.assertEqual(s[Deserializer.POLIMORPHIC_KEYWORD],
                         ClassTypedSerializer.getValue(SimpleCell))
        ob = CellDeserializer(BlockCellName).deserialize(s)
        self.assert_bii_equal(ob, simpleresource)
Beispiel #29
0
 def deserialize(doc):
     numeric_id = ID.deserialize(doc[Block.SERIAL_NUMERIC_ID_KEY])
     m = Block(brl_id=BRLBlock(doc[Block.SERIAL_ID_KEY]),
               numeric_id=numeric_id)
     m._cells_table = AddressTable.deserialize(doc[Block.SERIAL_CELL_TABLE],
                                               numeric_id)
     m._contents_table = AddressTable.deserialize(
         doc[Block.SERIAL_CONTENT_TABLE], numeric_id)
     m._deps_table = TimeBaseMapDeserializer(BlockVersionTable).deserialize(
         doc[Block.SERIAL_DEPS_TABLE])
     m._renames = TimeBaseMapDeserializer(Renames).deserialize(
         doc[Block.SERIAL_RENAMES])
     m._deltas = ListDeserializer(BlockDelta).deserialize(
         doc[Block.SERIAL_DELTAS])
     m._cell_count = int(doc[Block.SERIAL_CELLS_COUNTER])
     m._content_count = int(doc[Block.SERIAL_CONTENT_COUNTER])
     return m
    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)
Beispiel #31
0
 def deserialize(self, data):
     if data is None:
         return None
     try:
         kls = Deserializer.get_polymorphic_class(data)
         r = kls.deserialize(data)
         r.name = BlockCellName(data[Cell.SERIAL_NAME_KEY])
         r.root = ID.deserialize(data[Cell.SERIAL_ROOT_KEY])
         r.ID = self.id_type.deserialize(data[Cell.SERIAL_ID_KEY])
         r.type = BiiType(data[Cell.SERIAL_TYPE_KEY])
         r.hasMain = data[Cell.SERIAL_MAIN_KEY]
         try:
             r.dependencies.cell_name = r.name
         except AttributeError:
             pass
         return r
     except Exception as e:
         tb = traceback.format_exc()
         logger.warning(tb)
         raise BiiSerializationException(e)
 def test_set_changes(self):
     p = PublishRequest()
     changes = self._changes()
     p.changes = changes
     self.assertTrue(bool(p))
     self.assertItemsEqual(['deleted', 'renamed'], p.deleted)
     self.assertEqual(changes.renames, p.renames)
     self.assertEqual(
         {
             SimpleCell('usr/block/created'),
             SimpleCell('usr/block/renamed2'),
             SimpleCell('usr/block/modified_cell', CPP),
             SimpleCell('usr/block/modified_both', CPP)
         }, set(p.cells))
     self.assertEqual(
         {
             'created': Content(id_=None, load=Blob('created')),
             'modified_cont': Content(id_=None, load=Blob('mod_content2')),
             'modified_both': Content(id_=None, load=Blob('mod_both2'))
         }, p.contents)
     self.assertEqual({'renamed2': ID((1234, ))}, p.contents_ids)
Beispiel #33
0
 def test_content_similarity(self):
     content = Content(ID((0, 0, 0)), load=None)
     self.assertEquals(content.similarity(content), 1)
Beispiel #34
0
 def setUp(self):
     self.block_id = ID((1, 2))
     self.block = Block(self.block_id, None)
     self.brl = BRLBlock("user/user/block/master")
Beispiel #35
0
 def create(self, name, item_id, current_time):
     if item_id.parent == self._block_id:
         id_ = ID((item_id[2], ))
     else:
         id_ = item_id
     return self.setdefault(name, TimeBaseMap()).append(current_time, id_)