コード例 #1
0
    def test_invalid_names(self):
        #All valid, not raises
        brl = BRLBlock(
            "validowner/validcreator/va__-lidblocknam.e/validbranch")
        self.assertEqual(brl.block_name.name, "va__-lidblocknam.e")

        #All valid, not raises
        brl = BRLBlock("validowner/validcreator/v123/validbranch")
        self.assertEqual(brl.block_name.name, "v123")

        #Invalid block
        self.assertRaises(InvalidNameException, BRLBlock,
                          "inva.lid.owner/validcreator/v/validbranch")

        #Invalid owner
        self.assertRaises(
            InvalidNameException, BRLBlock,
            "inva.lid.owner/validcreator/va__-lidblocknam.e/validbranch")
        #Invalid creator
        with self.assertRaises(InvalidNameException) as cm:
            BRLBlock("validowner/.vali-dcreator/va__-lidb.e/validbranch")

        self.assertIn(
            "Valid names should begin with alphanumerical characters",
            cm.exception.message)

        #Invalid branch
        with self.assertRaises(InvalidNameException) as cm:
            BRLBlock("validowner/validcreator/va__-lidb.e/.invalidbranch")

        self.assertIn("Valid names MUST begin with a letter or number",
                      cm.exception.message)
コード例 #2
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)
コード例 #3
0
    def get_version_info_test(self):
        store = Mock(GenericServerStore)

        # Block doesn't exist and user is other
        p = PublishService(store, 'any_user')
        block_brl = BRLBlock("user/user/theblock/master")
        store.read_block_permissions = Mock(side_effect=NotInStoreException())
        block_info = p.get_block_info(block_brl)
        self.assertFalse(block_info.can_write)

        # Now block exists
        store.read_block_permissions = Mock(
            return_value=ElementPermissions(block_brl))

        # Block exists and user is the authorized one
        p = PublishService(store, 'theuser')
        block_brl = BRLBlock("theuser/theuser/theblock/master")
        block_info = p.get_block_info(block_brl)
        self.assertTrue(block_info.can_write)

        # No authorized write to an existing block
        p = PublishService(store, 'wronguser')
        user = Mock(User)
        user.administrators = Permissions()
        store.read_user = Mock(return_value=user)
        block_info = p.get_block_info(block_brl)
        self.assertFalse(block_info.can_write)

        # Authorized user with an existing block
        p = PublishService(store, 'theuser')
        block_brl = BRLBlock("theuser/theuser/theblock/master")
        block_info = p.get_block_info(block_brl)
        self.assertTrue(block_info.can_write)
コード例 #4
0
    def test_diamond_single_solution(self):
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        brl_b = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockb'))
        brl_c = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockc'))
        name_a = BlockCellName(self.user + "/blocka/a.h")
        publisher = TestPublisher(self.user, self.store)
        for _ in range(20):
            publisher.publish(brl_a, {'a.h': ('a', [])})

        name_b = BlockCellName(self.user + "/blockb/b.h")
        name_c = BlockCellName(self.user + "/blockc/c.h")

        for i in range(0, 20):
            if i % 2 == 0:
                publisher.publish(brl_b, {'b.h': ('b', [name_a])},
                                  dep_versions=BlockVersion(brl_a, i))
            if (i % 2 == 1 or i == 10):
                publisher.publish(brl_c, {'c.h': ('c', [name_a])},
                                  dep_versions=BlockVersion(brl_a, i))

        request = self.build_unresolved_request([name_b, name_c])
        result = self.service.find(request, BiiResponse())
        self.check_result(result,
                          resolved=[(brl_b, 5, {name_b}),
                                    (brl_c, 5, {name_c})])
コード例 #5
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))
コード例 #6
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))
コード例 #7
0
    def test_serialization(self):

        self.user.add_block(BRLBlock("laso/laso/block2/master"),
                            tags=["ONE", "TWO"],
                            description="The good block")
        self.user.add_block(BRLBlock("laso/laso/block3/master"))

        self.user.administrators.grant("pepito")
        self.user.administrators.grant("josete")

        tokens = [
            SocialAccountToken("xxzc", "zxcc", self.utc_datetime),
            SocialAccountToken("xxzc", "zxcc", self.utc_datetime)
        ]

        social_account = SocialAccount("zcas", self.utc_datetime,
                                       self.utc_datetime, tokens, "zcc")

        self.user.social_accounts = {"google": social_account}
        self.user.publish_counter = 10
        self.user.reuse_counter = 7
        self.user.read_api_counter = 99

        seri = self.user.serialize()
        user2 = User.deserialize(seri)
        self.assertTrue(self._user_equal(self.user, user2))
        self.assertEqual(user2.read_api_counter, 99)
        self.assertEqual(user2.reuse_counter, 7)
        self.assertEqual(user2.publish_counter, 10)
        self.assertEqual(set(user2.administrators), {"pepito", "josete"})

        self.assertEqual(self.user.region, "Madrid")
コード例 #8
0
    def _virtual_setup(self):
        ref_translator = Mock()
        depA = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)
        depB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        baseC = BlockVersion(BRLBlock('user/user/blockC/branch'), 3)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseC, depA, depB])
        full_graph.add_edge(baseC, depA)
        full_graph.add_edge(baseC, depB)

        def res_method(*args):
            c_virtual_leaves = [BlockCellName('user/blockC/win/c.h'),
                                BlockCellName('user/blockC/nix/c.h')]
            c_win_deps = [BlockCellName('user/blockA/a.h')]
            c_nix_deps = [BlockCellName('user/blockB/b.h')]

            result = ReferencedResources()
            for ref in args[0].explode():
                result[ref.block_version][ref.ref] = \
                {Reference(depA, 'a.h'): ((0, 0), 0, []),
                 Reference(depB, 'b.h'): ((1, 1), 1, []),
                 Reference(baseC, 'c.h'): ((2, 2), 2, c_virtual_leaves),
                 Reference(baseC, 'win/c.h'): ((3, 3), 3, c_win_deps),
                 Reference(baseC, 'nix/c.h'): ((4, 4), 4, c_nix_deps)}[ref]
            return result

        ref_translator.get_published_min_refs.side_effect = res_method
        return ref_translator, depA, depB, baseC, full_graph
コード例 #9
0
 def test_create_duplicate_block_different_case(self):
     ''' Attempt to create two blocks with diferent casing eg: MyBlock and myblock '''
     name1 = BRLBlock('%s/%s/testblock/trunk' %
                      (self.user.ID, self.user.ID))
     name2 = BRLBlock('%s/%s/TestBlock/trunk' %
                      (self.user.ID, self.user.ID))
     self.user.add_block(name1)
     with self.assertRaisesRegexp(BiiException,
                                  'There is already a block named'):
         self.user.add_block(name2)
コード例 #10
0
    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)
コード例 #11
0
 def test_references(self):
     r = References()
     bv3 = BlockVersion(BRLBlock('user/user/block/master'), 3)
     bv4 = BlockVersion(BRLBlock('user/user/block/master'), 4)
     cn0 = CellName('foo.h')
     cn1 = CellName('foo1.h')
     r[bv3].add(cn0)
     r[bv3].add(cn1)
     r[bv4].add(cn0)
     l = r.explode()
     self.assertEqual({(bv3, cn0), (bv3, cn1), (bv4, cn0)}, set(l))
コード例 #12
0
    def test_basic(self):
        brl1 = BRLBlock("user/user2/block/branch")
        v1 = BlockVersion(brl1, 1)
        brl2 = BRLBlock("user2/user3/block2/branch3")
        v2 = BlockVersion(brl2, 2)

        table = BlockVersionTable()
        table.add_version(v1)
        table.add_version(v2)

        self.assertEqual(v1, table['user2/block'])
        self.assertEqual(v2, table['user3/block2'])
        self.assertEqual(2, len(table))
コード例 #13
0
ファイル: closure_test.py プロジェクト: luckcc/bii-common
    def test_add_item(self):
        c1 = Closure()
        r1 = Cell('user/block/name1')
        version = BlockVersion(BRLBlock('owner/user/block/branch'), 13)
        biiout = OutputStream()
        resource = Resource(r1, None)
        c1.add_item(resource, version, biiout)
        r2 = Cell('user/block/name1')
        r2.hasMain = True
        resource2 = Resource(r2, None)
        version2 = BlockVersion(BRLBlock('owner/user/block/branch'), 14)
        c1.add_item(resource2, version2, biiout)

        self.assertEqual(ClosureItem(resource, version), c1['user/block/name1'])
        self.assertIn('Incompatible dependency', str(biiout))
コード例 #14
0
    def disjoints_graphs_no_collisions_test(self):
        g1 = BlockVersionGraph()
        g2 = BlockVersionGraph()
        self.assertEqual(BlockVersionGraph(), g1.collision(g2))
        self.assertEqual(BlockVersionGraph(), g2.collision(g1))

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

        g1.add_node(v0)
        g2.add_node(v1)
        self.assertEqual(BlockVersionGraph(), g1.collision(g2))
        self.assertEqual(BlockVersionGraph(), g2.collision(g1))
コード例 #15
0
ファイル: localdb_test.py プロジェクト: toeb/client
 def test_store_dep_table(self):
     original_deptable = BlockVersionTable()
     brl_block = BRLBlock('dummy/dummy/block/master')
     block_version = BlockVersion(brl_block, 0)
     self.db.set_dep_table(block_version, original_deptable)
     retrieved_snap = self.db.get_dep_table(block_version)
     self.assertEquals(original_deptable, retrieved_snap)
コード例 #16
0
    def test_check_make_public_block(self):

        # 1. Already public.
        brl_master = BRLBlock("goku/goku/block/master")
        bper_master = ElementPermissions(brl_master, private=False)
        self.store.upsert_block_permissions(bper_master)

        # 2. Bulma cant make it public even its already public
        ensure = Security("bulma", self.store)
        self._subscribe("bulma", "enterprise_275_50_x")
        self.assertRaises(ForbiddenException, ensure.check_make_private_a_block, "goku")

        # 3. Now block is public, so bulma cant make it public
        bper_master = ElementPermissions(brl_master, private=True)
        self.store.upsert_block_permissions(bper_master)
        self.assertRaises(ForbiddenException, ensure.check_make_public_a_block, "goku")

        # 4. Grant read and write, and bulma still cant make it public
        bper_master.read.grant("bulma")
        bper_master.write.grant("bulma")
        self.store.upsert_block_permissions(bper_master)
        self.assertRaises(ForbiddenException, ensure.check_make_public_a_block, "goku")

        # 5. Make bulma an admin, now bulma can make it public
        goku = self.store.read_user("goku")
        goku.administrators.grant("bulma")
        self.store.update_user(goku)
        ensure.check_make_public_a_block("goku")

        # 5. Bulma can make public the block even when suscription is not active
        self._subscribe("bulma", "free")
        goku = self.store.read_user("goku")
        self.store.update_user(goku)
        ensure.check_make_public_a_block("goku")
コード例 #17
0
    def test_publish_dev_with_tag(self, enqueuer):
        brl = BRLBlock('owner/user/block/branch')
        store = Mock(MongoServerStore)
        store.read_block_permissions = Mock(
            return_value=ElementPermissions(brl, private=False))
        user = Mock()
        user.blocks = {}
        store.read_user = Mock(return_value=user)

        block = Mock(Block)
        block.add_publication.return_value = (['mock_id'], [], [], [])
        block.deltas = []
        ensure = Security('authUser', store)
        ensure.check_read_block = Mock(return_value=True)
        ensure.check_create_block = Mock(return_value=True)
        ensure.check_write_block = Mock(return_value=True)
        ensure.check_publish_block = Mock(return_value=True)

        store.read_block.return_value = block
        store.read_published_cells.return_value = {}
        p = PublishService(store, 'authUser')
        p.security = ensure
        pack = PublishRequest(BlockVersion(brl, -1))
        pack.cells.append(SimpleCell('user/block/r1.h'))
        pack.deptable = BlockVersionTable()
        p.publish(pack)
コード例 #18
0
    def test_delete_block(self):
        # First create master block permissions. Public
        brl = BRLBlock("goku/goku/block/master")
        bper_master = ElementPermissions(brl, private=True)
        self.store.upsert_block_permissions(bper_master)

        # 1. Owner can always delete a private block, even if i am not paying
        ensure = Security("goku", self.store)
        self._subscribe("goku", "enterprise_275_50_x")
        ensure.check_delete_block(brl)

        self._subscribe("freezer", "free")
        ensure.check_delete_block(brl)

        # 2. Other user can't delete block
        ensure = Security("freezer", self.store)
        self._subscribe("freezer", "enterprise_275_50_x")
        self.assertRaises(ForbiddenException, ensure.check_delete_block, brl)

        # 3. A user with read and write permissions cant delete
        ensure = Security("bulma", self.store)
        bper = ElementPermissions(brl, private=True)
        bper.write.grant("bulma")
        bper.read.grant("bulma")
        self.store.upsert_block_permissions(bper)
        self.assertRaises(ForbiddenException, ensure.check_delete_block, brl)

        # 3. But an admin user can delete it
        goku = self.store.read_user("goku")
        goku.administrators.grant("bulma")
        self.store.update_user(goku)
        ensure.check_delete_block(brl)
コード例 #19
0
 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)
コード例 #20
0
ファイル: localdb_test.py プロジェクト: toeb/client
 def test_store_snapshot(self):
     original_snap = [CellName("alf.c"), CellName("willy.c")]
     brl_block = BRLBlock('dummy/dummy/block/master')
     block_version = BlockVersion(brl_block, 0)
     self.db.create_cells_snapshot(block_version, original_snap)
     retrieved_snap = self.db.get_cells_snapshot(block_version)
     self.assertEquals(original_snap, retrieved_snap)
コード例 #21
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())
コード例 #22
0
ファイル: biiapi_proxy_test.py プロジェクト: toeb/client
    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())
コード例 #23
0
    def test_create_block(self):
        brl = BRLBlock("goku/goku/block/master")

        # Always can make a block if its public
        ensure = Security("goku", self.store)
        self._subscribe("goku", "free")
        ensure.check_create_block(brl.owner, private=False)

        # Only can make a private block if subscription is ok
        self.assertRaises(ForbiddenException, ensure.check_create_block, brl.owner, private=True)
        self._subscribe("goku", "enterprise_275_50_x")
        ensure.check_create_block(brl.owner, private=True)

        # Other user can create a block in my namespace if its an admin, not write and read is enought
        ensure = Security("bulma", self.store)
        self._subscribe("bulma", "enterprise_275_50_x")
        self.assertRaises(ForbiddenException, ensure.check_create_block, brl.owner, private=True)

        bper = ElementPermissions(brl.owner, private=True)
        bper.write.grant("bulma")
        bper.read.grant("bulma")
        self.store.upsert_block_permissions(bper)
        self.assertRaises(ForbiddenException, ensure.check_create_block, brl.owner, private=True)

        # 3. But an admin user can delete it
        goku = self.store.read_user("goku")
        goku.administrators.grant("bulma")
        self.store.update_user(goku)
        ensure.check_create_block(brl.owner, private=True)
        ensure.check_create_block(brl.owner, private=False)
コード例 #24
0
    def test_find_two_files_at_a_time(self):
        """Starts with one include, finds it, then two more includes, finish when all are found.
        Found items are taken into account in FindRequest.existing
        """

        NUM_FILES = 10
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        names_a = [
            BlockCellName(self.user + "/blocka/a%d.h" % i)
            for i in range(NUM_FILES)
        ]
        resources_info = {"a%d.h" % i: ("a", []) for i in range(NUM_FILES)}
        publisher = TestPublisher(self.user, self.store)
        publisher.publish(brl_a, resources_info)
        # Use the same request object, to accumulate existing (already found) files
        request = FinderRequest()
        request.policy = Policy.default()
        version = BlockVersion(brl_a, 0)  # The version is always the same
        for i in range(0, NUM_FILES, 2):
            declaration1 = CPPDeclaration(names_a[i])
            declaration2 = CPPDeclaration(names_a[i + 1])
            request.unresolved = {declaration1, declaration2}
            result = self.service.find(request, BiiResponse())
            self.check_result(result,
                              resolved=[(brl_a, 0,
                                         {names_a[i], names_a[i + 1]})])
            # The found one is added to the existing, for next iteration
            request.existing[version][declaration1] = {names_a[i]}
            request.existing[version][declaration2] = {names_a[i + 1]}
            self.assertEqual(len(request.existing[version]), i + 2)
コード例 #25
0
def get_renames(auth_user, bson_data):
    service = BiiService(app.store, auth_user)
    # Don t want a set, want a list
    block = BRLBlock.deserialize(bson_data["block"])
    t1 = bson_data["t1"]
    t2 = bson_data["t2"]
    return service.get_renames(block, t1, t2)
コード例 #26
0
    def test_find_transitive(self):
        '''Test including a block with other dependencies, without conflicts '''
        brl_a = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blocka'))
        name_a = BlockCellName(self.user + "/blocka/a.h")
        publisher = TestPublisher(self.user, self.store)
        publisher.publish(brl_a, {'a.h': ('a', [])})

        brl_b = BRLBlock('%s/%s/%s/master' % (self.user, self.user, 'blockb'))
        name_b = BlockCellName(self.user + "/blockb/b.h")
        #self.publish(brl_b, name_b, deps={name_b: name_a}, dep_versions=BlockVersion(brl_a, 0))
        publisher.publish(brl_b, {'b.h': ('b', [name_a])},
                          dep_versions=BlockVersion(brl_a, 0))

        request = self.build_unresolved_request(name_b)
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(brl_b, 0, {name_b})])
コード例 #27
0
    def test_basic(self):
        store = TestingMemServerStore()
        brl_user = '******'
        store.create_user(User(brl_user))
        brl_block = BRLBlock('user/user/block/master')
        publisher = TestPublisher(brl_user, store)
        publisher.publish(
            brl_block, {
                'r1.h': ('r1', ['user/block/r2.h']),
                'r2.h': ('r2', []),
                'r3.h': ('r3', [])
            })

        store = MemServerStore(store)
        translator = ReferenceTranslatorService(store, brl_user)
        ver = BlockVersion(brl_block, 0)
        missing = References()
        missing[ver].add('r1.h')
        closure = CompatibilityClosure(missing)
        full_graph = BlockVersionGraph()
        full_graph.add_nodes([ver])
        build_compatibility_closure(translator, closure, {ver}, full_graph)
        self.assertEqual(References(), closure.broken)

        expected = set()
        expected.add('user/block/r1.h')
        expected.add('user/block/r2.h')
        self.assertEqual(expected, closure.block_cell_names)
コード例 #28
0
    def test_build_closure_different_versions_restricted(self):
        '''Computes a CompatibilityClosure in which two versions of blockA actually point to the
        same unmodified resource with the typical diamond layout
        Also computes and checks the BlockClosure for that layout'''
        ref_translator = Mock()

        depA1 = BlockVersion(BRLBlock('user/user/blockA/branch'), 4)
        depA2 = BlockVersion(BRLBlock('user/user/blockA/branch'), 5)
        baseB = BlockVersion(BRLBlock('user/user/blockB/branch'), 2)
        baseC = BlockVersion(BRLBlock('user/user/blockC/branch'), 3)

        full_graph = BlockVersionGraph()
        full_graph.add_nodes([baseB, baseC, depA1, depA2])
        full_graph.add_edge(baseB, depA1)
        full_graph.add_edge(baseC, depA2)

        def res_method(*args):
            depsb = [BlockCellName('user/blockA/a.h')]
            depsc = [BlockCellName('user/blockA/a.h')]
            result = ReferencedResources()
            for ref in args[0].explode():
                result[ref.block_version][ref.ref] = \
                {Reference(depA1, 'a.h'): ((0, 0), 0, []),
                 Reference(depA2, 'a.h'): ((0, 0), 0, []),
                 Reference(baseB, 'b.h'): ((1, 4), 1, depsb),
                 Reference(baseC, 'c.h'): ((2, 3), 2, depsc)}[ref]
            return result

        ref_translator.get_published_min_refs.side_effect = res_method

        missing = References()
        missing.add(Reference(baseB, 'b.h'))
        missing.add(Reference(baseC, 'c.h'))
        closure = CompatibilityClosure(missing)
        build_compatibility_closure(ref_translator, closure, {baseC}, full_graph)

        self.assertEqual(References(), closure.broken)
        self.assertEqual({BlockCellName('user/blockC/c.h')}, closure.block_cell_names)
        #self.assertIn(Reference(depA1, 'a.h'), closure.references)
        self.assertNotIn(baseB, closure.references)
        self.assertNotIn(depA1, closure.references)
        self.assertNotIn(depA2, closure.references)
        self.assertIn(baseC, closure.references)
        expected_frontier = References()
        expected_frontier[baseB].add('b.h')
        expected_frontier[depA2].add('a.h')
        self.assertEqual(expected_frontier, closure.frontier)
コード例 #29
0
 def testParsing(self):
     brl = BRLBlock("drodri/pedro/geom/mybranch")
     self.assertEqual(BRLUser('drodri'), brl.owner)
     self.assertEqual('drodri', brl.owner)
     self.assertEqual('pedro/geom', brl.block_name)
     self.assertEqual(BlockName('pedro/geom'), brl.block_name)
     self.assertEqual(ComplexName('mybranch'), brl.branch)
     self.assertEqual('mybranch', brl.branch)
コード例 #30
0
 def testLowerCaseBackslashConversion(self):
     brl = BRLBlock("Drodri\Pedro/geOm\Mybranch")
     self.assertEqual(BRLUser('Drodri'), brl.owner)
     self.assertEqual('Drodri', brl.owner)
     self.assertEqual('Pedro/geOm', brl.block_name)
     self.assertEqual(BlockName('Pedro/geOm'), brl.block_name)
     self.assertEqual(ComplexName('mybranch'), brl.branch)
     self.assertEqual('mybranch', brl.branch)
コード例 #31
0
 def test_pretty(self):
     brl = BRLBlock("drodri/pedro/geOm/mybranch")
     self.assertEqual('pedro/geOm(drodri/mybranch)', brl.to_pretty())
コード例 #32
0
 def test_brl_block(self):
     b = BRLBlock('user/user/block/master', 1)
     s = serialize(b)
     b2 = BRLBlock.deserialize(s)
     self.assertEqual(b, b2)
コード例 #33
0
 def deserialize(data):
     return BlockVersion(BRLBlock.deserialize(data[0]), *data[1:])