Ejemplo n.º 1
0
 def test_list(self, stash_path):
     storage = ghost.TinyDBStorage(stash_path)
     storage.put(BASE_TEST_KEY)
     key_list = storage.list()
     assert BASE_TEST_KEY in key_list
     assert len(key_list) == 1
     storage_tester.list(key_list)
Ejemplo n.º 2
0
 def test_is_initialized(self, stash_path):
     storage = ghost.TinyDBStorage(stash_path)
     stash = ghost.Stash(storage)
     assert storage.is_initialized is False
     stash.init()
     assert storage.is_initialized is True
     storage_tester.is_initialized(storage.is_initialized)
Ejemplo n.º 3
0
def test_stash(stash_path):
    log_dir = tempfile.mkdtemp()
    ghost.TRANSACTION_LOG_FILE_PATH = \
        os.path.join(log_dir, 'transaction.log')
    stash = ghost.Stash(ghost.TinyDBStorage(stash_path))
    stash.init()
    yield stash
    shutil.rmtree(log_dir, ignore_errors=True)
Ejemplo n.º 4
0
 def test_put(self, stash_path):
     storage = ghost.TinyDBStorage(stash_path)
     key_id = storage.put(BASE_TEST_KEY)
     db = get_tinydb(stash_path)
     assert '1' in db
     assert db['1']['name'] == BASE_TEST_KEY['name']
     assert len(db) == 1
     storage_tester.put(key_id)
Ejemplo n.º 5
0
 def test_init_stash_create_directory(self):
     stash_dir = tempfile.mkdtemp()
     shutil.rmtree(stash_dir, ignore_errors=True)
     stash_path = os.path.join(stash_dir, 'stash.json')
     try:
         storage = ghost.TinyDBStorage(stash_path)
         assert os.path.isdir(stash_dir) is False
         storage.init()
         assert os.path.isdir(stash_dir) is True
     finally:
         shutil.rmtree(stash_dir, ignore_errors=True)
Ejemplo n.º 6
0
 def test_init_stash_already_exists(self):
     fd, stash_path = tempfile.mkstemp()
     os.close(fd)
     try:
         storage = ghost.TinyDBStorage(stash_path)
         with pytest.raises(ghost.GhostError) as ex:
             storage.init()
         assert 'Stash {0} already initialized'.format(stash_path) \
             in str(ex.value)
     finally:
         os.remove(stash_path)
Ejemplo n.º 7
0
 def test_init(self):
     tmpdir = tempfile.mkdtemp()
     shutil.rmtree(tmpdir, ignore_errors=True)
     assert not os.path.isdir(tmpdir)
     stash_path = os.path.join(tmpdir, 'stash.json')
     storage = ghost.TinyDBStorage(stash_path)
     try:
         storage.init()
         assert os.path.isdir(tmpdir)
     finally:
         shutil.rmtree(tmpdir, ignore_errors=True)
Ejemplo n.º 8
0
    def test_get_delete(self, stash_path):
        inserted_key = BASE_TEST_KEY
        storage = ghost.TinyDBStorage(stash_path)
        storage.put(inserted_key)
        retrieved_key = storage.get(BASE_TEST_KEY['name'])
        assert inserted_key == retrieved_key
        storage_tester.get(retrieved_key)

        result = storage.delete(BASE_TEST_KEY['name'])
        storage_tester.delete(result)

        key = storage.get(BASE_TEST_KEY['name'])
        storage_tester.get_nonexisting_key(key)
Ejemplo n.º 9
0
    def test_init(self, stash_path):
        log_dir = tempfile.mkdtemp()
        ghost.TRANSACTION_LOG_FILE_PATH = \
            os.path.join(log_dir, 'transaction.log')

        storage = ghost.TinyDBStorage(stash_path)
        stash = ghost.Stash(storage, TEST_PASSPHRASE)
        passphrase = stash.init()
        assert stash._storage == storage
        assert stash.passphrase == TEST_PASSPHRASE
        assert passphrase == TEST_PASSPHRASE
        assert_stash_initialized(stash_path)

        shutil.rmtree(log_dir, ignore_errors=True)
Ejemplo n.º 10
0
 def test_init_stash_in_current_dir(self):
     """Test this because it depends on the ability
     of the storage to understand whether it should or should not create
     a directory.
     """
     prev_dir = os.getcwd()
     stash_dir = tempfile.mkdtemp()
     os.chdir(stash_dir)
     stash_path = os.path.join(stash_dir, 'stash.json')
     try:
         storage = ghost.TinyDBStorage(stash_path)
         stash = ghost.Stash(storage)
         assert os.path.isfile(stash_path) is False
         stash.init()
         assert os.path.isfile(stash_path) is True
     finally:
         os.chdir(prev_dir)
         shutil.rmtree(stash_dir, ignore_errors=True)
Ejemplo n.º 11
0
def test_cli_stash(stash_path):
    log_dir = tempfile.mkdtemp()
    ghost.GHOST_HOME = tempfile.mkdtemp()
    shutil.rmtree(ghost.GHOST_HOME, ignore_errors=True)
    ghost.TRANSACTION_LOG_FILE_PATH = \
        os.path.join(log_dir, 'transaction.log')
    fd, passphrase_file_path = tempfile.mkstemp()
    os.close(fd)
    ghost.PASSPHRASE_FILENAME = passphrase_file_path
    _invoke('init_stash "{0}"'.format(stash_path))
    os.environ['GHOST_STASH_PATH'] = stash_path
    with open(passphrase_file_path) as passphrase_file:
        passphrase = passphrase_file.read()
    os.environ['GHOST_PASSPHRASE'] = passphrase
    os.environ['GHOST_BACKEND_TYPE'] = 'tinydb'
    yield ghost.Stash(ghost.TinyDBStorage(stash_path), passphrase)
    try:
        os.remove(passphrase_file_path)
        os.remove(stash_path)
        shutil.rmtree(log_dir, ignore_errors=True)
        shutil.rmtree(ghost.GHOST_HOME, ignore_errors=True)
    except:
        pass
Ejemplo n.º 12
0
 def test_empty_list(self, stash_path):
     storage = ghost.TinyDBStorage(stash_path)
     key_list = storage.list()
     storage_tester.empty_list(key_list)