예제 #1
0
파일: test_watch.py 프로젝트: gsdu8g9/stado
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))
예제 #2
0
파일: test_watch.py 프로젝트: gsdu8g9/stado
    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
예제 #3
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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))
예제 #4
0
파일: test_watch.py 프로젝트: lecnim/stado
    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
예제 #5
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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))
예제 #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)
예제 #7
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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))
예제 #8
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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))
예제 #9
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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))
예제 #10
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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())
예제 #11
0
파일: test_new.py 프로젝트: gsdu8g9/stado
    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())
예제 #12
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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)
예제 #13
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    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())
예제 #14
0
파일: test_watch.py 프로젝트: lecnim/stado
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))
예제 #15
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    def test_returned_value(self):
        """should return True if building each site in group => successful."""

        self.assertTrue(Console().__call__('build'))
예제 #16
0
파일: test_view.py 프로젝트: gsdu8g9/stado
    def setUp(self):
        TestCommand.setUp(self)

        self.shell = Console()
예제 #17
0
파일: test_watch.py 프로젝트: lecnim/stado
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())
예제 #18
0
파일: test_new.py 프로젝트: gsdu8g9/stado
    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')
예제 #19
0
파일: test_watch.py 프로젝트: gsdu8g9/stado
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())
예제 #20
0
파일: test_build.py 프로젝트: gsdu8g9/stado
    def test_returned_value(self):
        """should return True if building successful."""

        self.assertTrue(Console().__call__('build a'))
예제 #21
0
파일: test_view.py 프로젝트: gsdu8g9/stado
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'))