class TestProject(unittest.TestCase):
    def setUp(self):
        _path = os.path.abspath(os.path.dirname(__file__))
        path = os.path.join(_path, 'testproject')
        self.application = WSGIApplication(path,
                                           'settings.ini',
                                           strict=True,
                                           validate_db=False,
                                           disable_autoreload=True)
        console = Console()
        self.archive = self.application.archive
        db.sync_all(self.archive, console)
        self.context = context = Context()

        self.application.populate_context(context)
        set_dynamic(context)
        context['.console'] = console

    def tearDown(self):
        del self.archive
        del self.application

    def test_content(self):
        """Test content in a project"""
        app = self.archive.apps['site']
        html = self.archive('site#render_content',
                            self.context,
                            app,
                            content="#content.tests.base")

        assert '[TESTS]' in html
        assert '<title>[TESTS]</title>' in html

        html = self.archive('site#render_content',
                            self.context,
                            app,
                            content="#content.tests.merge.replace")
        assert "[MERGE TEST][B][END MERGE TEST]" in html

        html = self.archive('site#render_content',
                            self.context,
                            app,
                            content="#content.tests.merge.append")
        assert "[MERGE TEST][A][B][END MERGE TEST]" in html

        html = self.archive('site#render_content',
                            self.context,
                            app,
                            content="#content.tests.merge.prepend")
        assert "[MERGE TEST][B][A][END MERGE TEST]" in html

        html = self.archive('site#render_content',
                            self.context,
                            app,
                            content="#content.tests.node",
                            var="FOO")
        assert "TEMPLATE VAR FOO" in html
    def setUp(self):
        _path = os.path.abspath(os.path.dirname(__file__))
        path = os.path.join(_path, 'testproject')
        self.application = WSGIApplication(path,
                                           'settings.ini',
                                           strict=True,
                                           validate_db=False,
                                           disable_autoreload=True)
        console = Console()
        self.archive = self.application.archive
        db.sync_all(self.archive, console)
        self.context = context = Context()

        self.application.populate_context(context)
        set_dynamic(context)
        context['.console'] = console
Beispiel #3
0
class TestExpose(unittest.TestCase):
    """Test exposed Python code in a project."""
    def setUp(self):
        _path = os.path.abspath(os.path.dirname(__file__))
        path = os.path.join(_path, "testproject")
        self.application = WSGIApplication(
            path,
            "settings.ini",
            strict=True,
            validate_db=False,
            disable_autoreload=True,
        )
        console = Console()
        self.archive = self.application.archive
        db.sync_all(self.archive, console)
        self.context = context = Context()

        self.archive.populate_context(context)
        self.application.populate_context(context)
        set_dynamic(context)
        context[".console"] = console

    def tearDown(self):
        del self.archive
        del self.application

    def test_macros(self):
        app = self.archive.apps["site"]

        self.assertEqual(
            6, self.archive("macro.expose.double", self.context, app, n=3))
        self.assertEqual(
            21, self.archive("macro.expose.tripple", self.context, app, n=7))

    def test_filters(self):
        app = self.archive.apps["site"]
        self.context[".app"] = app
        with pilot.manage(self.context):
            self.assertEqual(1000, self.context.eval("10|'cube'"))
            self.assertEqual(1000, self.context.eval("10|'cube from site'"))
            self.assertEqual(1000, self.context.eval("10|.app.filters.cube"))
Beispiel #4
0
 def build(self):
     log.debug('building %r', self)
     try:
         application = WSGIApplication(self.location,
                                       self.ini,
                                       disable_autoreload=True,
                                       logging=None,
                                       master_settings=self.master_settings)
         self.application = application
     except:
         log.exception('error building %r', self)
         raise
Beispiel #5
0
 def build(self):
     log.debug('building %r', self)
     try:
         pilot.service['name'] = self.name
         try:
             application = WSGIApplication(
                 self.location,
                 self.ini,
                 disable_autoreload=True,
                 logging=None,
                 master_settings=self.master_settings)
             self.application = application
         finally:
             del pilot.service['name']
     except:
         log.exception('error building %r', self)
         raise