# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/filebroker.py
# META_EXT = '.yaml'
# BIB_EXT  = '.bib'
# def filter_filename(filename, ext):
#     def __init__(self, directory, create=False):
#     def _create(self):
#     def bib_path(self, citekey):
#     def meta_path(self, citekey):
#     def pull_cachefile(self, filename):
#     def push_cachefile(self, filename, data):
#     def mtime_metafile(self, citekey):
#     def mtime_bibfile(self, citekey):
#     def pull_metafile(self, citekey):
#     def pull_bibfile(self, citekey):
#     def push_metafile(self, citekey, metadata):
#     def push_bibfile(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def listing(self, filestats=True):
#     def __init__(self, directory, scheme='docsdir', subdir='doc'):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
# class FileBroker(object):
# class DocBroker(object):


import unittest
import os
import dotdot
import fake_env
from pubs import content, filebroker

    def test_existing_data(self):

        self.fs.add_real_directory(os.path.join(self.rootpath, 'testrepo'), read_only=False)
        fb = filebroker.FileBroker('testrepo', create = True)

        bib_content = content.read_text_file('testrepo/bib/Page99.bib')
        self.assertEqual(fb.pull_bibfile('Page99'), bib_content)

        meta_content = content.read_text_file('testrepo/meta/Page99.yaml')
        self.assertEqual(fb.pull_metafile('Page99'), meta_content)

    def test_errors(self):

        with self.assertRaises(IOError):
            filebroker.FileBroker('testrepo', create = False)

        fb = filebroker.FileBroker('testrepo', create = True)

        self.assertFalse(fb.exists('Page99'))
        with self.assertRaises(IOError):
            fb.pull_bibfile('Page99')
        with self.assertRaises(IOError):
            fb.pull_metafile('Page99')

    def test_remove(self):

        with self.assertRaises(IOError):
            filebroker.FileBroker('testrepo', create = False)


# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/filebroker.py
# META_EXT = '.yaml'
# BIB_EXT  = '.bib'
# def filter_filename(filename, ext):
#     def __init__(self, directory, create=False):
#     def _create(self):
#     def bib_path(self, citekey):
#     def meta_path(self, citekey):
#     def pull_cachefile(self, filename):
#     def push_cachefile(self, filename, data):
#     def mtime_metafile(self, citekey):
#     def mtime_bibfile(self, citekey):
#     def pull_metafile(self, citekey):
#     def pull_bibfile(self, citekey):
#     def push_metafile(self, citekey, metadata):
#     def push_bibfile(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def listing(self, filestats=True):
#     def __init__(self, directory, scheme='docsdir', subdir='doc'):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
# class FileBroker(object):
# class DocBroker(object):


# Path: tests/test_filebroker.py
import unittest
import os
import dotdot
import fake_env
from pubs import content, filebroker


    def test_existing_data(self):

        self.fs.add_real_directory(os.path.join(self.rootpath, 'testrepo'), read_only=False)
        fb = filebroker.FileBroker('testrepo', create = True)

        bib_content = content.read_text_file('testrepo/bib/Page99.bib')
        self.assertEqual(fb.pull_bibfile('Page99'), bib_content)

        meta_content = content.read_text_file('testrepo/meta/Page99.yaml')
        self.assertEqual(fb.pull_metafile('Page99'), meta_content)

    def test_errors(self):

        with self.assertRaises(IOError):
            filebroker.FileBroker('testrepo', create = False)

        fb = filebroker.FileBroker('testrepo', create = True)

        self.assertFalse(fb.exists('Page99'))
        with self.assertRaises(IOError):
            fb.pull_bibfile('Page99')
        with self.assertRaises(IOError):
            fb.pull_metafile('Page99')

    def test_remove(self):

        with self.assertRaises(IOError):
            filebroker.FileBroker('testrepo', create = False)


        fb = filebroker.FileBroker('testrepo', create = True)