def test_cached_read(self):
        """ Test method that creates a copy with file read already performed """
        file_path = os.path.dirname(os.path.realpath(__file__))
        file_path = os.path.join(file_path, 'person_body_template.json')

        # Read file to compare
        file_content = None
        with open(file_path, 'r') as f:
            file_content = f.read()

        handler = ContentHandler()
        handler.setup(file_path, is_file=True)

        # Check it read the file correctly
        cached_handler = handler.create_noread_version()
        self.assertEqual(file_content, handler.get_content())
        self.assertFalse(cached_handler.is_file)

        # Check with templating
        handler.is_template_content = True
        cached_handler = handler.create_noread_version()
        self.assertEqual(file_content, handler.get_content())
        self.assertEqual(handler.is_template_content, cached_handler.is_template_content)
        self.assertFalse(cached_handler.is_file)

        # Check dynamic paths don't try to template
        handler.is_template_path = True
        cached_handler = handler.create_noread_version()
        self.assertTrue(handler is cached_handler)
    def test_cached_read(self):
        """ Test method that creates a copy with file read already performed """
        file_path = os.path.dirname(os.path.realpath(__file__))
        file_path = os.path.join(file_path, 'person_body_template.json')

        # Read file to compare
        file_content = None
        with open(file_path, 'r') as f:
            file_content = f.read()

        handler = ContentHandler()
        handler.setup(file_path, is_file=True)

        # Check it read the file correctly
        cached_handler = handler.create_noread_version()
        self.assertEqual(file_content, handler.get_content())
        self.assertFalse(cached_handler.is_file)

        # Check with templating
        handler.is_template_content = True
        cached_handler = handler.create_noread_version()
        self.assertEqual(file_content, handler.get_content())
        self.assertEqual(handler.is_template_content,
                         cached_handler.is_template_content)
        self.assertFalse(cached_handler.is_file)

        # Check dynamic paths don't try to template
        handler.is_template_path = True
        cached_handler = handler.create_noread_version()
        self.assertTrue(handler is cached_handler)
Example #3
0
    def test_test_content_templating(self):
        test = Test()
        handler = ContentHandler()
        handler.is_template_content = True
        handler.content = '{"first_name": "Gaius","id": "$id","last_name": "Baltar","login": "******"}'
        context = Context()
        context.bind_variables({'id': 9, 'login': '******'})
        test.set_body(handler)

        templated = test.realize(context=context)
        self.assertEqual(string.Template(handler.content).safe_substitute(context.get_values()),
                         templated.body)
Example #4
0
    def test_test_content_templating(self):
        test = Test()
        handler = ContentHandler()
        handler.is_template_content = True
        handler.content = '{"first_name": "Gaius","id": "$id","last_name": "Baltar","login": "******"}'
        context = Context()
        context.bind_variables({'id':9, 'login':'******'})
        test.set_body(handler)

        templated = test.realize(context=context)
        self.assertEqual(string.Template(handler.content).safe_substitute(context.get_values()),
            templated.body)