Exemplo n.º 1
0
class TestWatchGroupOfSites(TestCommand):
    """Command watch group:

    Important!
    This test is done in temporary directory. Use self.temp_path to get path to it.
    During tests current working directory is self.temp_path. Previous working
    directory is self.cwd.

    """
    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting

    def test_return_true(self):
        """should return True if watching ended successful."""

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.assertTrue(self.shell('watch'))

    def test_modify_site(self):
        """watcher should rebuild only modified site."""

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.shell('watch')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())

        # Should not rebuild not modified sites.
        path = os.path.join(self.temp_path, 'b', config.build_dir)
        self.assertFalse(os.path.exists(path))

    def test_output_option(self):
        """--output: watcher should use custom output directory."""

        output_path = tempfile.mkdtemp()

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.shell('watch --output ' + output_path)

        path = os.path.join(output_path, 'a', 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())

        # Should not rebuild not modified sites.
        path = os.path.join(output_path, 'b')
        self.assertFalse(os.path.exists(path))
Exemplo n.º 2
0
    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting
Exemplo n.º 3
0
    def test_output_option(self):
        """--output: should build each site in custom output directory."""

        output_path = tempfile.mkdtemp()
        Console().__call__('build --output ' + output_path)

        self.assertCountEqual(['a', 'b'], os.listdir(output_path))
Exemplo n.º 4
0
    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting
Exemplo n.º 5
0
    def test_build_directory(self):
        """should create output directory in site directory."""

        Console().__call__('build a')

        # temp/a/_build
        build_directory = os.path.join(self.temp_path, 'a', config.build_dir)
        self.assertTrue(os.path.exists(build_directory))
Exemplo n.º 6
0
    def setUp(self):
        self.cwd = os.getcwd()
        os.chdir(self.path)

        self.temp_path = tempfile.mkdtemp()

        self.console = Console()
        self.console('build data --output ' + self.temp_path)
Exemplo n.º 7
0
    def test_build_directory(self):
        """should create output directory in each site directory."""

        Console().__call__('build')

        a = os.path.join(self.temp_path, 'a', config.build_dir)
        b = os.path.join(self.temp_path, 'b', config.build_dir)

        self.assertTrue(os.path.exists(a))
        self.assertTrue(os.path.exists(b))
Exemplo n.º 8
0
    def test_skip_python_script(self):
        """should skip python files."""

        Console().__call__('build a')

        # temp/a/_build/site.py
        site_py = os.path.join(self.temp_path, 'a', config.build_dir,
                               'site.py')

        self.assertFalse(os.path.exists(site_py))
Exemplo n.º 9
0
    def test_skip_python_script(self):
        """should skip python files."""

        Console().__call__('build')

        a = os.path.join(self.temp_path, 'a', config.build_dir, 'site.py')
        b = os.path.join(self.temp_path, 'b', config.build_dir, 'site.py')

        self.assertFalse(os.path.exists(a))
        self.assertFalse(os.path.exists(b))
Exemplo n.º 10
0
    def test_page(self):
        """should correctly build page from site content."""

        Console().__call__('build a')

        # temp/a/_build
        build_directory = os.path.join(self.temp_path, 'a', config.build_dir)

        self.assertListEqual(['a.html'], os.listdir(build_directory))
        with open(os.path.join(build_directory, 'a.html')) as page:
            self.assertEqual('hello world', page.read())
Exemplo n.º 11
0
    def test(self):
        """should correctly creates new site files."""

        Console().__call__('new test')

        self.assertTrue(os.path.exists(os.path.join(self.temp_path, 'a')))

        with open(os.path.join(self.temp_path, 'test', 'site.py')) as file:
            self.assertEqual(script, file.read())

        with open(os.path.join(self.temp_path, 'test', 'index.html')) as file:
            self.assertEqual(index, file.read())
Exemplo n.º 12
0
    def test_output_option(self):
        """--output: should build site in custom output directory."""

        output_path = tempfile.mkdtemp()
        Console().__call__('build a --output ' + output_path)

        self.assertListEqual(['a.html'], os.listdir(output_path))

        # Should build site in output directory.
        path = os.path.join(self.temp_path, 'a')
        self.assertNotIn(config.build_dir, os.listdir(path))

        shutil.rmtree(output_path)
Exemplo n.º 13
0
    def test_page(self):
        """should correctly build pages in each site content."""

        Console().__call__('build')

        a = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        b = os.path.join(self.temp_path, 'b', config.build_dir, 'b.html')

        self.assertTrue(os.path.exists(a))
        self.assertTrue(os.path.exists(b))

        with open(a) as page:
            self.assertEqual('hello world', page.read())
        with open(b) as page:
            self.assertEqual('hello world', page.read())
Exemplo n.º 14
0
class TestWatchGroupOfSites(TestCommand):
    """Command watch group:

    Important!
    This test is done in temporary directory. Use self.temp_path to get path to it.
    During tests current working directory is self.temp_path. Previous working
    directory is self.cwd.

    """

    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting


    def test_return_true(self):
        """should return True if watching ended successful."""

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.assertTrue(self.shell('watch'))




    def test_modify_site(self):
        """watcher should rebuild only modified site."""

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.shell('watch')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())

        # Should not rebuild not modified sites.
        path = os.path.join(self.temp_path, 'b', config.build_dir)
        self.assertFalse(os.path.exists(path))


    def test_output_option(self):
        """--output: watcher should use custom output directory."""

        output_path = tempfile.mkdtemp()

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.shell('watch --output ' + output_path)

        path = os.path.join(output_path, 'a', 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())

        # Should not rebuild not modified sites.
        path = os.path.join(output_path, 'b')
        self.assertFalse(os.path.exists(path))
Exemplo n.º 15
0
    def test_returned_value(self):
        """should return True if building each site in group => successful."""

        self.assertTrue(Console().__call__('build'))
Exemplo n.º 16
0
    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
Exemplo n.º 17
0
class TestWatchSite(TestCommand):
    """Command watch:

    Important!
    This test is done in temporary directory. Use self.temp_path to get path to it.
    During tests current working directory is self.temp_path. Previous working
    directory is self.cwd.

    """

    command = 'watch'

    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting


    def test_return_true(self):
        """should return True if watching ended successful."""

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.assertTrue(self.shell(self.command + ' a'))



    def test_modify_file(self):
        """watcher should react on file modifying."""

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())


    def test_create_file(self):
        """watcher should react on file creating."""

        self.shell.before_waiting = (create_file,
                                     [os.path.join(self.temp_path, 'a', 'new.html')])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'new.html')
        with open(path) as file:
            self.assertEqual('hello world', file.read())


    def test_modify_script(self):
        """watcher should correctly re-import site.py"""

        self.shell.before_waiting = (modify_script,
                                     [os.path.join(self.temp_path, 'a', 'site.py')])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('updated', file.read())


    def test_output_option(self):
        """--output: watcher should use custom output directory."""

        output_path = tempfile.mkdtemp()

        self.shell.before_waiting = (modify_file,
                                     [os.path.join(self.temp_path, 'a', 'a.html')])
        self.shell(self.command + ' a --output ' + output_path)

        path = os.path.join(output_path, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())
Exemplo n.º 18
0
    def test_site_exists(self):
        """should raise error when creating site which already exits."""

        self.assertFalse(Console().__call__('new a'))
        self.assertRaises(CommandError, Console().commands['new'].run, 'a')
Exemplo n.º 19
0
class TestWatchSite(TestCommand):
    """Command watch:

    Important!
    This test is done in temporary directory. Use self.temp_path to get path to it.
    During tests current working directory is self.temp_path. Previous working
    directory is self.cwd.

    """

    command = 'watch'

    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
        # For faster checking files changes.
        self.shell.set_interval(0.1)
        # After first rebuild stop command.
        self.shell.after_rebuild = self.shell.stop_waiting

    def test_return_true(self):
        """should return True if watching ended successful."""

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.assertTrue(self.shell(self.command + ' a'))

    def test_modify_file(self):
        """watcher should react on file modifying."""

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())

    def test_create_file(self):
        """watcher should react on file creating."""

        self.shell.before_waiting = (create_file, [
            os.path.join(self.temp_path, 'a', 'new.html')
        ])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'new.html')
        with open(path) as file:
            self.assertEqual('hello world', file.read())

    def test_modify_script(self):
        """watcher should correctly re-import site.py"""

        self.shell.before_waiting = (modify_script, [
            os.path.join(self.temp_path, 'a', 'site.py')
        ])
        self.shell(self.command + ' a')

        path = os.path.join(self.temp_path, 'a', config.build_dir, 'a.html')
        with open(path) as file:
            self.assertEqual('updated', file.read())

    def test_output_option(self):
        """--output: watcher should use custom output directory."""

        output_path = tempfile.mkdtemp()

        self.shell.before_waiting = (modify_file, [
            os.path.join(self.temp_path, 'a', 'a.html')
        ])
        self.shell(self.command + ' a --output ' + output_path)

        path = os.path.join(output_path, 'a.html')
        with open(path) as file:
            self.assertEqual('hello world updated', file.read())
Exemplo n.º 20
0
    def test_returned_value(self):
        """should return True if building successful."""

        self.assertTrue(Console().__call__('build a'))
Exemplo n.º 21
0
class TestViewSite(TestCommand):
    """Command view

    Important!
    This test is done in temporary directory. Use self.temp_path to get path to it.
    During tests current working directory is self.temp_path. Previous working
    directory is self.cwd.

    """

    command = 'view'

    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()

    def test_server(self):
        """should run server and return True."""

        self.shell.before_waiting = self._test_server
        returned = self.shell(self.command + ' a')

        self.assertTrue(returned)

    def _test_server(self):

        # Getting content from urls.
        a = urllib.request.urlopen('http://localhost:4000/a.html').read()
        self.shell.stop_waiting()

        self.assertEqual('hello world', a.decode('UTF-8'))

    def test_host_and_port(self):
        """--host --port: should run server on custom host and port."""

        self.shell.before_waiting = self._test_host_and_port
        self.shell(self.command + ' a --host 127.0.0.2 --port 3000')

    def _test_host_and_port(self):

        # Getting content from urls.
        a = urllib.request.urlopen('http://127.0.0.2:3000/a.html').read()
        self.shell.stop_waiting()

        self.assertEqual('hello world', a.decode('UTF-8'))

    def test_output_option(self):
        """--output: should run server in custom output directory."""

        output_path = tempfile.mkdtemp()

        self.shell.before_waiting = self._test_output_option
        self.shell(self.command + ' a --output ' + output_path)

        # Should build site in output directory.
        path = os.path.join(output_path, 'a.html')
        self.assertTrue(os.path.exists(path))

        shutil.rmtree(output_path)

    def _test_output_option(self):

        # Getting content from urls.
        a = urllib.request.urlopen('http://localhost:4000/a.html').read()
        self.shell.stop_waiting()

        self.assertEqual('hello world', a.decode('UTF-8'))