Exemplo n.º 1
0
def test_site(path, tmpdir):
    """
    Test that sites in the examples/ directory build correctly
    """
    site = TarbellSite(path)

    assert os.path.realpath(site.path) == os.path.realpath(path)

    # build the site
    site.generate_static_site(str(tmpdir))

    # compare directories
    built = os.path.join(path, '_site')
    comp = filecmp.dircmp(built, str(tmpdir))

    assert set(comp.same_files) == set(os.listdir(built))
Exemplo n.º 2
0
def render(project=None):
    """Render projects or a specfic project to 'out' directory."""
    site = TarbellSite(os.path.dirname(os.path.abspath(__file__)))
    out = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'out')
    site.render_templates(out, project)
Exemplo n.º 3
0
def render(project=None):
    """Render projects or a specfic project to '_out' directory."""
    site = TarbellSite(os.path.dirname(os.path.abspath(__file__)))
    out = os.path.join(os.path.dirname(os.path.abspath(__file__)), '_out')
    site.render_templates(out, project)
Exemplo n.º 4
0
def test_blueprint_path():
    "Make sure blueprint is loading correctly"
    site = TarbellSite(PATH)

    assert os.path.realpath(site.base.base_dir) == os.path.realpath(
        os.path.join(PATH, '_blueprint'))
Exemplo n.º 5
0
from tarbell.app import TarbellSite
import os

site = TarbellSite(os.path.dirname(os.path.abspath(__file__)))
if __name__ == '__main__':
    site.app.run('0.0.0.0')
Exemplo n.º 6
0
def test_get_site():
    site = TarbellSite(PATH)

    assert os.path.realpath(site.path) == os.path.realpath(PATH)
    assert site.project.name == PROJECT_NAME
Exemplo n.º 7
0
def test_default_excludes():
    "Ensure a basic set of excluded files"
    site = TarbellSite(PATH)

    assert set(site.project.EXCLUDES) == set(EXCLUDES)
Exemplo n.º 8
0
    def setUp(self):
        """ Get a fake Tarbell site instance. """
        test_dir = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'example')

        self.site = TarbellSite(test_dir)
Exemplo n.º 9
0
class TarbellSiteTestCase(unittest.TestCase):
    """
    Tests for the TarbellSite class methods.
    """
    def setUp(self):
        """ Get a fake Tarbell site instance. """
        test_dir = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'example')

        self.site = TarbellSite(test_dir)

    def test_init(self):
        """
        Creating an instance of TarbellSite without a path
        raises a TypeError exception.
        """
        self.assertRaises(TypeError, TarbellSite, )

    def test_filter_files(self):
        name, project, project_path = self.site.projects[0]

        filtered = self.site.filter_files(project_path)
        next = filtered.next()

        """
        Each project tuple has a length of 3
        """
        self.assertEqual(len(next), 3)

        """
        The first item in the project tuple equals the project_path passed
        """
        self.assertEqual(project_path, next[0])

    def test_sort_modules(self):
        """
        Our "base" project is always the last item in the
        return list of sorted modules
        """
        projects = sorted(self.site.projects, cmp=self.site.sort_modules)
        self.assertEqual(projects[-1][0], "base")

    def test_load_projects(self):
        """
        Load projects returns a list with length of 2, since our test app
        has two sub directories: base and project.
        """
        self.assertEqual(len(self.site.load_projects()), 2)

    @unittest.skip('')
    def test_preview(self):
        pass

    def test_get_context(self):
        """
        Our get_context method should return a dictionary
        """
        self.assertTrue(isinstance(self.site.get_context(), dict))

    def test_get_context_from_csv(self):
        """
        Our get_context_from_csv should fetch a local file path or an url
        """
        self.assertTrue(isinstance(self.site.get_context_from_csv(), dict))

        self.site.CONTEXT_SOURCE_FILE = 'https://raw.github.com/newsapps/'
        'flask-tarbell/0.9/tarbell/tests/example/project/data/project.csv'

        self.assertTrue(isinstance(self.site.get_context_from_csv(), dict))

    @unittest.skip('')
    def test_get_context_from_gdoc(self):
        pass

    @unittest.skip('')
    def test__get_context_from_gdoc(self):
        pass

    @unittest.skip('')
    def test_export_xlsx(self):
        pass

    @unittest.skip('')
    def test_process_xlsx(self):
        pass

    @unittest.skip('')
    def test_copy_global_values(self):
        pass

    @unittest.skip('')
    def test_make_headers(self):
        pass

    @unittest.skip('')
    def test_make_worksheet_data(self):
        pass

    @unittest.skip('')
    def test_generate_static_site(self):
        pass
Exemplo n.º 10
0
    def setUp(self):
        """ Get a fake Tarbell site instance. """
        test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                'example')

        self.site = TarbellSite(test_dir)
Exemplo n.º 11
0
class TarbellSiteTestCase(unittest.TestCase):
    """
    Tests for the TarbellSite class methods.
    """
    def setUp(self):
        """ Get a fake Tarbell site instance. """
        test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                'example')

        self.site = TarbellSite(test_dir)

    def test_init(self):
        """
        Creating an instance of TarbellSite without a path
        raises a TypeError exception.
        """
        self.assertRaises(
            TypeError,
            TarbellSite,
        )

    def test_filter_files(self):
        name, project, project_path = self.site.projects[0]

        filtered = self.site.filter_files(project_path)
        next = filtered.next()
        """
        Each project tuple has a length of 3
        """
        self.assertEqual(len(next), 3)
        """
        The first item in the project tuple equals the project_path passed
        """
        self.assertEqual(project_path, next[0])

    def test_sort_modules(self):
        """
        Our "base" project is always the last item in the
        return list of sorted modules
        """
        projects = sorted(self.site.projects, cmp=self.site.sort_modules)
        self.assertEqual(projects[-1][0], "base")

    def test_load_projects(self):
        """
        Load projects returns a list with length of 2, since our test app
        has two sub directories: base and project.
        """
        self.assertEqual(len(self.site.load_projects()), 2)

    @unittest.skip('')
    def test_preview(self):
        pass

    def test_get_context(self):
        """
        Our get_context method should return a dictionary
        """
        self.assertTrue(isinstance(self.site.get_context(), dict))

    def test_get_context_from_csv(self):
        """
        Our get_context_from_csv should fetch a local file path or an url
        """
        self.assertTrue(isinstance(self.site.get_context_from_csv(), dict))

        self.site.CONTEXT_SOURCE_FILE = 'https://raw.github.com/newsapps/'
        'flask-tarbell/0.9/tarbell/tests/example/project/data/project.csv'

        self.assertTrue(isinstance(self.site.get_context_from_csv(), dict))

    @unittest.skip('')
    def test_get_context_from_gdoc(self):
        pass

    @unittest.skip('')
    def test__get_context_from_gdoc(self):
        pass

    @unittest.skip('')
    def test_export_xlsx(self):
        pass

    @unittest.skip('')
    def test_process_xlsx(self):
        pass

    @unittest.skip('')
    def test_copy_global_values(self):
        pass

    @unittest.skip('')
    def test_make_headers(self):
        pass

    @unittest.skip('')
    def test_make_worksheet_data(self):
        pass

    @unittest.skip('')
    def test_generate_static_site(self):
        pass
Exemplo n.º 12
0
# -*- coding: utf-8 -*-

"""
tarbell.scripts.runserver
~~~~~~~~~

Wrapper for Tarbell preview server. Should not be run directly in regular use.
"""

import os
import sys

from tarbell.app import TarbellSite

os.chdir(sys.argv[1])
site = TarbellSite(sys.argv[1])
ip = sys.argv[2]
port = int(sys.argv[3])

# try / except
if __name__ == '__main__':
    site.app.run(ip, port=port)