Exemplo n.º 1
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())
Exemplo n.º 2
0
 def localdb(self):
     '''return instance of LocalDB'''
     if self._localdb is None:
         path = os.path.join(self._folder, 'bii.db')
         self._localdb = LocalDB(path)
     return self._localdb
Exemplo n.º 3
0
class UserCache(object):

    def __init__(self, folder):
        """Path to folder to write files"""
        self._folder = folder
        self._username = None
        self._localdb = None

    @property
    def folder(self):
        return self._folder

    def _create_layout_templates(self):
        for name, content in {"simple": _simple_layout,
                              "clion": _clion_layout,
                              "tmp": _tmp_layout}.iteritems():
            layout_path = os.path.join(self._folder, "%s_layout.bii" % name)
            if not os.path.exists(layout_path):
                save(layout_path, content)

    def layout(self, name):
        if not name:
            return None
        self._create_layout_templates()
        layout_path = os.path.join(self._folder, name.lower() + "_layout.bii")
        if os.path.exists(layout_path):
            return load(layout_path)

    @property
    def bii_ignore(self):
        from biicode.client.workspace.bii_ignore import BiiIgnore, default_bii_ignore
        path = os.path.join(self._folder, 'ignore.bii')
        if not os.path.exists(path):
            save(path, default_bii_ignore)
        return BiiIgnore.loads(load(path))

    @property
    def localdb(self):
        '''return instance of LocalDB'''
        if self._localdb is None:
            path = os.path.join(self._folder, 'bii.db')
            self._localdb = LocalDB(path)
        return self._localdb

    @property
    def username(self):
        if self._username is None:
            self._username = self.localdb.get_username()
        return self._username

    @property
    def default_policies(self):
        """ Return default WS policies.

        @return: default workspace policies
        """
        path = os.path.join(self._folder, 'default_policies.bii')
        if not os.path.exists(path):
            # load hardcoded default policies: default_policies
            save(path, default_policies)
            return default_policies
        current_defaults = load(path)
        # Migration to new simple policies.bii format
        if current_defaults.lstrip().startswith("# This is the file"):
            current_defaults = default_policies
            save(path, default_policies)
        return current_defaults

    def close(self):
        if self._localdb is not None:
            self._localdb.disconnect()
            self._localdb = None
Exemplo n.º 4
0
 def setUp(self):
     self.hiveFolder = tempfile.mkdtemp(suffix='biicode',
                                        dir=BII_TEST_FOLDER)
     self.db = LocalDB(os.path.join(self.hiveFolder, 'bii.db'))
Exemplo n.º 5
0
class LocalDBTest(TestCase):
    _suites = ['client']

    def setUp(self):
        self.hiveFolder = tempfile.mkdtemp(suffix='biicode',
                                           dir=BII_TEST_FOLDER)
        self.db = LocalDB(os.path.join(self.hiveFolder, 'bii.db'))

    def tearDown(self):
        if os.path.isdir(self.hiveFolder):
            self.db.disconnect()
            # os.chmod(self.hiveFolder, stat.S_IWRITE)
            shutil.rmtree(self.hiveFolder)

    def test_not_logged_in(self):
        user = self.db.get_login()
        self.assertEquals(user, (None, None))

    def test_logged_in(self):
        user = "******", "dummypass"
        self.db.set_login(user)
        user2 = self.db.get_login()
        self.assertEquals(user, user2)

    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 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)

    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)

    def test_delete_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)
        ID = encode_serialized_value(block_version.serialize())
        self.db.delete(ID, DEP_TABLES)
        self.assertRaises(NotInStoreException, self.db.get_dep_table,
                          block_version)
Exemplo n.º 6
0
 def setUp(self):
     self.hiveFolder = tempfile.mkdtemp(suffix='biicode', dir=BII_TEST_FOLDER)
     self.db = LocalDB(os.path.join(self.hiveFolder, 'bii.db'))
Exemplo n.º 7
0
class LocalDBTest(TestCase):
    _suites = ['client']

    def setUp(self):
        self.hiveFolder = tempfile.mkdtemp(suffix='biicode', dir=BII_TEST_FOLDER)
        self.db = LocalDB(os.path.join(self.hiveFolder, 'bii.db'))

    def tearDown(self):
        if os.path.isdir(self.hiveFolder):
            self.db.disconnect()
            # os.chmod(self.hiveFolder, stat.S_IWRITE)
            shutil.rmtree(self.hiveFolder)

    def test_not_logged_in(self):
        user = self.db.get_login()
        self.assertEquals(user, (None, None))

    def test_logged_in(self):
        user = "******", "dummypass"
        self.db.set_login(user)
        user2 = self.db.get_login()
        self.assertEquals(user, user2)

    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 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)

    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)

    def test_delete_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)
        ID = encode_serialized_value(block_version.serialize())
        self.db.delete(ID, DEP_TABLES)
        self.assertRaises(NotInStoreException, self.db.get_dep_table, block_version)