def test_delete_main(self): r1 = SimpleCell('user/block/r1.h', CPP) r2 = SimpleCell('user/block/r2.cpp', CPP) r3 = SimpleCell('user/block/r3.cpp', CPP) r4 = SimpleCell('user/block/' + BIICODE_FILE) res = { r1.name: Resource(r1, Content(None, Blob(''))), r2.name: Resource(r2, Content(None, Blob(''))), r3.name: Resource(r3, Content(None, Blob('int main(char* argv){}'))), r4.name: Resource(r4, Content(None, Blob('[mains]\n !r3.cpp'))) } block_holder = BlockHolder(BlockName('user/block'), res) process_holder(block_holder, ParseProcessor()) self.assertTrue(res['user/block/r3.cpp'].cell.hasMain) changes, _ = process_holder(block_holder, MainConfigProcessor()) # Checks self.assertFalse(res['user/block/r1.h'].cell.hasMain) self.assertFalse(res['user/block/r2.cpp'].cell.hasMain) self.assertFalse(res['user/block/r3.cpp'].cell.hasMain) self.assertEqual(0, len(changes.upserted))
def test_find_mains(self): '''basic check that header is implemented by source''' resources = { 'blink.h': Resource( SimpleCell('usr/block/blink.h', CPP), Content(id_=None, load=Blob(header), parser=DRLCPPParser())), 'blink.cpp': Resource( SimpleCell('usr/block/blink.cpp', CPP), Content(id_=None, load=Blob(implementation), parser=DRLCPPParser())), 'mainblink.cpp': Resource(SimpleCell('usr/block/mainblink.cpp', CPP), Content(id_=None, load=Blob(main), parser=DRLCPPParser())) } block_holder = BlockHolder(BlockName('user/block'), resources) for r in resources.itervalues(): r.content.parse() r.content.updated = False processor = ArduinoEntryPointProcesor() processor.do_process(block_holder, Mock()) mainblink = block_holder['mainblink.cpp'].cell content = block_holder['mainblink.cpp'].content self.assertTrue(mainblink.hasMain) self.assertFalse(content.updated) self.assertFalse(content.blob_updated)
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())
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))
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 test_nonzero_one_file_content(self): changes = Changes() changes.modified['modified_cont'] = Modification( Resource(SimpleCell('usr/block/pretty.js'), Content(id_=None, load=Blob('mod_content'))), Resource(SimpleCell('usr/block/pretty.js'), Content(id_=None, load=Blob('mod_content2')))) p = PublishRequest(BlockVersion.loads('usr/block: 3')) p.msg = "Test Msg" p.changes = changes self.assertTrue(bool(p))
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)
def test_mains_with_filter(self): r1 = SimpleCell('user/block/r1.h', CPP) r2 = SimpleCell('user/block/r2.cpp', CPP) r3 = SimpleCell('user/block/no_mains/r3.cpp', CPP) r4 = SimpleCell('user/block/no_mains/r4.cpp', CPP) r5 = SimpleCell('user/block/' + BIICODE_FILE) r6 = SimpleCell('user/block/new_mains/r6.cpp', CPP) r7 = SimpleCell('user/block/new_mains/r7.cpp', CPP) r8 = SimpleCell('user/block/exe_file1.hh', CPP) r9 = SimpleCell('user/block/exe_file2.hh', CPP) res = { r1.name: Resource(r1, Content(None, Blob(''))), r2.name: Resource(r2, Content(None, Blob(''))), r3.name: Resource(r3, Content(None, Blob('int main(char* argv){}'))), r4.name: Resource(r4, Content(None, Blob('int main(char* argv){}'))), r5.name: Resource( r5, Content(None, Blob('[mains]\n!no_mains/*\nnew_mains/*\n*.hh'))), r6.name: Resource(r6, Content(None, Blob(''))), r7.name: Resource(r7, Content(None, Blob(''))), r8.name: Resource(r8, Content(None, Blob(''))), r9.name: Resource(r9, Content(None, Blob(''))) } block_holder = BlockHolder(BlockName('user/block'), res) process_holder(block_holder, ParseProcessor()) self.assertTrue(res['user/block/no_mains/r3.cpp'].cell.hasMain) self.assertTrue(res['user/block/no_mains/r4.cpp'].cell.hasMain) self.assertFalse(res['user/block/new_mains/r6.cpp'].cell.hasMain) self.assertFalse(res['user/block/new_mains/r7.cpp'].cell.hasMain) self.assertFalse(res['user/block/exe_file1.hh'].cell.hasMain) self.assertFalse(res['user/block/exe_file2.hh'].cell.hasMain) process_holder(block_holder, MainConfigProcessor()) # Checks self.assertFalse(res['user/block/r1.h'].cell.hasMain) self.assertFalse(res['user/block/r2.cpp'].cell.hasMain) self.assertFalse(res['user/block/no_mains/r3.cpp'].cell.hasMain) self.assertFalse(res['user/block/no_mains/r4.cpp'].cell.hasMain) self.assertTrue(res['user/block/new_mains/r6.cpp'].cell.hasMain) self.assertTrue(res['user/block/new_mains/r7.cpp'].cell.hasMain) self.assertTrue(res['user/block/exe_file1.hh'].cell.hasMain) self.assertTrue(res['user/block/exe_file2.hh'].cell.hasMain)
def base_version_test(self): hive_holder = HiveHolder({}, {}) parents_resource = Resource( SimpleCell(a1.block_name + BIICODE_FILE), Content(id_=None, load=Blob('[parent]\n ' + str(a1)))) hive_holder.add_holder(BlockHolder(a1.block_name, {parents_resource})) parents_resource = Resource( SimpleCell(b2.block_name + BIICODE_FILE), Content(id_=None, load=Blob('[parent]\n * ' + str(b2)))) hive_holder.add_holder(BlockHolder(b2.block_name, {parents_resource})) hive_holder.add_holder(BlockHolder(cn.block_name, {})) result_table = BlockVersionTable( [b.parent for b in hive_holder.block_holders]) self.assertEqual(result_table, BlockVersionTable([a1, b2, cn]))
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)
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 publish_pack_add(pack, block_cell_name, content_text): name = BlockCellName(block_cell_name) cell1 = SimpleCell(name) pack.cells.add(cell1) pack.contents[name.cell_name] = Content( load=Blob(content_text)) # it MUST have a content to be deleted return cell1
def _process_resources(block_holder): for (cell, content) in block_holder.simple_resources: # Cell from server has the CellID as ID, we need BlockCellName cell.ID = cell.name if content: content = Content(cell.name, content.load, created=True) r = Resource(cell, content) block_holder.add_resource(r)
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)
def setUp(self): testUser = BRLUser('compareUser') self.brl_block = BRLBlock('%s/%s/%s/master' % (testUser, testUser, 'modulea')) r1 = SimpleCell(self.brl_block.block_name + 'r1.h') content = Content(id_=None, load=Blob('hello')) self.r1 = r1 self.c1 = content self.last_version_resources = {'r1.h': Resource(r1, content)}
def test_hive_num_files_reject(self): with self.assertRaises(BiiException): hive = Hive() changes = ProcessorChanges() for i in xrange(BII_HIVE_NUMFILES_LIMIT + 1): name = "user/block/file%d" % i changes.upsert(name, Content(id_=name, load=Blob())) hive.update(changes) changevalidator.check_hive_num_cells(hive)
def get_block_holder(block_name, resources_defs): resources = {} for cell_name, (typ, text) in resources_defs.iteritems(): if typ is None: typ = UNKNOWN cell = SimpleCell(block_name + cell_name, typ) resources[cell_name] = Resource( cell, Content(block_name + cell_name, load=Blob(text))) return BlockHolder(block_name, resources)
def _prepare_context(self, my_conf): if my_conf: my_conf = "[dependencies]\n " + my_conf self.processor = DependenciesConfigurationProcessor() self.r1 = BlockCellName('user/block/r1.h') self.r2 = BlockCellName('user/block/r2.cpp') self.r3 = BlockCellName('user/block/r3.cpp') r1 = SimpleCell(self.r1, CPP) r2 = SimpleCell(self.r2, CPP) r3 = SimpleCell('user/block/r3.cpp', CPP) r4 = SimpleCell('user/block/' + BIICODE_FILE) res = { r1.name: Resource(r1, Content(None, Blob("hi"))), r2.name: Resource(r2, Content(None, Blob("hi"))), r3.name: Resource(r3, Content(None, Blob("hi"))), r4.name: Resource(r4, Content(None, Blob(my_conf))) } return BlockHolder(BlockName('user/block'), res)
def test_create_resource(self): r1 = SimpleCell(self.brl_block.block_name + 'r1.h') content = Content(id_=None, load=Blob('hello')) r2 = SimpleCell(self.brl_block.block_name + 'r2.h') content2 = Content(id_=None, load=Blob('bye')) edition_resources = { 'r1.h': Resource(r1, content), 'r2.h': Resource(r2, content2) } changes = compare(self.last_version_resources, edition_resources) self.assertEqual(0, len(changes.deleted)) self.assertEqual(1, len(changes.created)) self.assertEqual(0, len(changes.renames)) self.assertEqual(0, len(changes.modified)) self.assertEqual(Resource(r2, content2), changes.created['r2.h'])
def checkin_block_files(hive_holder, block_name, files, processor_changes, biiout): ''' Params: hive_holder: HiveHolder block_name: BlockName files: {cell_name: content} processor_changes: ProcessorChanges biiout: biiout ''' block_name = BlockName(block_name) types_blobs = obtain_types_blobs(files) # {cell_name: (TYPE, Content/CellType/None)} # FIXME: What happens if merge result is larger than individual files, reject??? changevalidator.remove_large_cells(types_blobs, biiout) try: block_holder = hive_holder[block_name] except KeyError: block_holder = BlockHolder(block_name, []) hive_holder.add_holder(block_holder) for cell_name, (biitype, blob) in types_blobs.iteritems(): block_cell_name = block_name + cell_name cell = SimpleCell(block_cell_name, biitype) try: resource = block_holder[cell_name] except KeyError: content = Content(block_cell_name, load=blob) processor_changes.upsert(block_cell_name, content) else: content = resource.content if content is None or blob != content.load: content = Content(block_cell_name, load=blob) processor_changes.upsert(block_cell_name, content) resource = Resource(cell, content) block_holder.add_resource(resource) for cell_name, resource in block_holder.resources.items(): if cell_name not in types_blobs: if resource.content is not None: processor_changes.delete(resource.name) block_holder.delete_resource(cell_name) hive_holder.hive.update(processor_changes)
def test_get_version_by_tag(self): brl_block = BRLBlock('%s/%s/TestBlock/master' % (self.testUser.ID, self.testUser.ID)) publish_request = PublishRequest(BlockVersion(brl_block, -1)) publish_request.tag = STABLE publish_request.versiontag = 'mytag' publish_request.cells.append(SimpleCell(brl_block.block_name + 'r1.h')) publish_request.contents['r1.h'] = Content(id_=None, load=Blob('hola')) publish_request.deptable = BlockVersionTable() self.service.publish(publish_request) publish_request = PublishRequest(BlockVersion(brl_block, 0, 'mytag')) publish_request.tag = STABLE publish_request.versiontag = 'mytag' publish_request.cells.append(SimpleCell(brl_block.block_name + 'r12.h')) publish_request.contents['r2.h'] = Content(id_=None, load=Blob('hola')) publish_request.deptable = BlockVersionTable() self.service.publish(publish_request) block_version = self.service.get_version_by_tag(brl_block, 'mytag') self.assertEquals(1, block_version.time)
def _process_leaves(self, virtual_cell, realizations, biiout): '''for a virtual cell, creates the leaves if they don't exist @param virtual_cell: the cell that serves as base @param realizations: a set to add the leaves BlockCellNames @param biiout: biiout ''' block_cell_name = virtual_cell.name for leave in virtual_cell.resource_leaves: realizations.add(leave) try: cell = self.block_holder[leave.cell_name].cell except KeyError: #The leave it is pointing does not exist biiout.info('%s virtual realization not existing, creating it' % leave) cell = SimpleCell(leave) cell.type = virtual_cell.type content = Content(leave, Blob(""), created=True) content.parser = parser_factory(cell.type, cell.name.cell_name) self.block_holder.add_resource(Resource(cell, content)) cell.container = block_cell_name
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)
def test_publish_concurrent_modification(self): self.store = TestingMemServerStore() brl = 'user' self.store.create_user(User(brl)) self.service = BiiService(self.store, brl) self.brl_block = BRLBlock('user/user/block/master') request = PublishRequest(BlockVersion(self.brl_block, -1)) request.cells.append(SimpleCell('user/block/r1.h')) request.contents['r1.h'] = Content(id_=None, load=Blob('hola')) request.deptable = BlockVersionTable() request.tag = DEV self.service.publish(request) '''Branch 1 (from master) creates new resource''' self.brl_block1 = BRLBlock('user/user/block/branch1') request = PublishRequest(BlockVersion(self.brl_block, 0)) request.cells.append(SimpleCell('user/block/r2.h')) request.contents['r2.h'] = Content(id_=None, load=Blob('adios')) request.deptable = BlockVersionTable() with self.assertRaisesRegexp(BiiException, 'Concurrent modification'): self.service.publish(request)
def test_create_missing_simple_resources(self): resources = {'bii/virtual.bii': Resource(SimpleCell('user/block/bii/virtual.bii'), Content(None, Blob(myConf1)))} self.block_holder = BlockHolder(BlockName('user/block'), resources) VirtualConfigurationProcessor().do_process(self.block_holder, OutputStream()) self._sphere_os_checks('sphere.h') self._sphere_os_checks('sphere.cpp') self.assertEqual(None, self.block_holder['sphere.h'].content) self.assertEqual(None, self.block_holder['sphere.cpp'].content)
def test_publish_no_contents(self, enqueuer): brl = BRLBlock('owner/user/block/branch') store = Mock(MongoServerStore) store.read_block_permissions = Mock( return_value=ElementPermissions(brl, private=False)) p = PublishService(store, 'authUser') pack = PublishRequest(BlockVersion(brl, -1)) pack.cells.append(SimpleCell('user/block/r1.h')) pack.contents['r1.h'] = Content(id_=None, load=Blob('hola')) pack.versiontag = 'mytag' with self.assertRaisesRegexp(PublishException, 'DEV'): p.publish(pack)
def prepare_context(self, config): r1 = SimpleCell('user/block/r1.h') r2 = SimpleCell('user/block/r2.cpp') r3 = SimpleCell('user/block2/r3.cpp') r4 = SimpleCell('user/block/' + BIICODE_FILE) self.res = {r1.name: Resource(r1, None), r2.name: Resource(r2, None), r3.name: Resource(r3, None), r4.name: Resource(r4, Content(None, Blob("[mains]\n" + config)))} self.block_holder = BlockHolder(BlockName('user/block'), self.res) self.processor = MainConfigProcessor()
def checkin_block_files(hive_holder, block_name, files, biiout): ''' Params: hive_holder: HiveHolder block_name: BlockName files: {cell_name: content} processor_changes: ProcessorChanges biiout: biiout ''' block_name = BlockName(block_name) types_blobs = obtain_types_blobs(files) # {cell_name: (TYPE, Content/CellType/None)} # FIXME: What happens if merge result is larger than individual files, reject??? changevalidator.remove_large_cells(types_blobs, biiout) try: block_holder = hive_holder[block_name] except KeyError: block_holder = BlockHolder(block_name, []) hive_holder.add_holder(block_holder) for cell_name, (biitype, blob) in types_blobs.iteritems(): block_cell_name = block_name + cell_name cell = SimpleCell(block_cell_name, biitype) try: resource = block_holder[cell_name] except KeyError: content = Content(block_cell_name, load=blob) else: content = resource.content if content is None or blob != content.load: content = Content(block_cell_name, load=blob) else: content.set_blob(blob) resource = Resource(cell, content) block_holder.add_resource(resource) for cell_name, resource in block_holder.resources.items(): if cell_name not in types_blobs: block_holder.delete_resource(cell_name)
def test_check_publish_block(self): # 1. Onwer can write the block if its private brl = BRLBlock("goku/goku/block/master") self._add_block_to_user("goku", brl, True) ensure = Security("goku", self.store) self._subscribe("goku", "enterprise_275_50_x") pack = PublishRequest(BlockVersion(brl, -1)) pack.cells.append(SimpleCell('user/block/r1.h')) pack.contents['r1.h'] = Content(id_=None, load=Blob('hola')) pack.versiontag = 'mytag' ensure.check_publish_block(brl, pack) # If the owner is not paying he can't write ensure = Security("goku", self.store) self._subscribe("goku", "free") self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack) self._subscribe("goku", "enterprise_275_50_x") # 1b. But other not granted user can't write ensure = Security("freezer", self.store) self._subscribe("freezer", "enterprise_275_50_x") self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack) # 2. If bulma is granted as administrator or write he can write ensure = Security("bulma", self.store) self._subscribe("bulma", "enterprise_275_50_x") goku = self.store.read_user("goku") goku.administrators.grant("bulma") self.store.update_user(goku) ensure.check_publish_block(brl, pack) goku.administrators.revoke("bulma") self.store.update_user(goku) self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack) bper = ElementPermissions(brl, private=True) bper.write.grant("bulma") self.store.upsert_block_permissions(bper) ensure.check_publish_block(brl, pack) bper.write.remove("bulma") self.store.upsert_block_permissions(bper) self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack) # 3. If we give read permissions only, user cant write bper = ElementPermissions(brl, private=True) bper.read.grant("bulma") self.store.upsert_block_permissions(bper) self.assertRaises(ForbiddenException, ensure.check_publish_block, brl, pack)
def test_modify_content(self): '''just modify the content of a file''' r1 = SimpleCell(self.brl_block.block_name + 'r1.h') content = Content(id_=None, load=Blob('bye')) edition_resources = {'r1.h': Resource(r1, content)} changes = compare(self.last_version_resources, edition_resources) self.assertEqual(0, len(changes.deleted)) self.assertEqual(0, len(changes.created)) self.assertEqual(0, len(changes.renames)) self.assertEqual(1, len(changes.modified)) self.assertEqual(Resource(r1, content), changes.modified['r1.h'].new)
def setUp(self): self.conn.drop_database(self._testMethodName) self.store = MongoServerStore(self.conn, self._testMethodName) self.mother = ModelCreator(self.store) self.user = self.mother.make_test_user() self.p = PublishService(self.store, self.user.ID) self.brl = BRLBlock('%s/%s/block/master' % (self.user.ID, self.user.ID)) pack = PublishRequest(BlockVersion(self.brl, -1)) pack.cells.append(SimpleCell('%s/block/r1.h' % self.user.ID)) pack.cells.append(SimpleCell('%s/block/r2.h' % self.user.ID)) pack.cells.append(SimpleCell('%s/block/r3.h' % self.user.ID)) pack.contents['r1.h'] = Content(id_=None, load=Blob('r1')) pack.contents['r2.h'] = Content(id_=None, load=Blob('r2')) pack.contents['r3.h'] = Content(id_=None, load=Blob('r3')) pack.deptable = BlockVersionTable() self.pack = pack self.cell_collection = self.store.db[ GenericServerStore.PUBLISHED_CELL_ST] self.content_collection = self.store.db[ GenericServerStore.PUBLISHED_CONTENT_ST] self.block_collection = self.store.db[GenericServerStore.BLOCK_ST]
def python_parse_failure_test(self, parser): """ Weird bug miguel found. Python parser failure was causing 'You're trying to parse a virtual file' message to appear """ response = OutputStream() parser.side_effect = Exception cell = SimpleCell('usr/block/sort_controllers.py', biitype=PYTHON) content = Content(id_=1, load=Blob('print "hello"'), parser=None, is_parsed=False) resource = Resource(cell, content) self.assertFalse(resource.parse(response)) self.assertIn('Error parsing usr/block/sort_controllers.py file', str(response))
def test_content_similarity(self): content = Content(ID((0, 0, 0)), load=None) self.assertEquals(content.similarity(content), 1)