コード例 #1
0
    def test_parse_test_templated_headers(self):
        """ Test parsing with templated headers """

        heads = {"Accept": "Application/json", "$AuthHeader": "$AuthString"}
        templated_heads = {
            "Accept": "Application/json",
            "apikey": "magic_passWord"
        }
        context = Context()
        context.bind_variables({
            'AuthHeader': 'apikey',
            'AuthString': 'magic_passWord'
        })

        # If this doesn't throw errors we have silent failures
        input_invalid = {
            "url": "/ping",
            "method": "DELETE",
            "NAME": "foo",
            "group": "bar",
            "body": "<xml>input</xml>",
            "headers": 'goat'
        }
        try:
            test = TestCase('', None, context)
            test.parse(input_invalid)
            fail("Expected error not thrown")
        except ValidatorError:
            pass
コード例 #2
0
    def test_header_templating(self):
        context = Context()
        test = TestCase('', None, None, context)
        head_templated = {'x': {'template': "$val"}}

        context.bind_variables({'val': 'gouda'})
        # No templating applied
        test.headers = head_templated
        self.assertEqual(1, len(test.headers))
        self.assertEqual('gouda', test.headers['x'])
コード例 #3
0
 def test_test_content_templating(self):
     context = Context()
     test = TestCase('', None, None, context)
     handler = ContentHandler()
     handler.is_template_content = True
     handler.content = '{"first_name": "Gaius","id": "$id","last_name": "Baltar","login": "******"}'
     context.bind_variables({'id': 9, 'login': '******'})
     test.body = handler
     test.pre_update(context=context)
     self.assertEqual(
         string.Template(handler.content).safe_substitute(
             context.get_values()), test.body)
コード例 #4
0
    def test_content_file_template(self):
        """ Test file read and templating of read files in this directory """
        variables = {'id': 1, 'login': '******'}
        context = Context()

        file_path = os.path.dirname(os.path.realpath(__file__))
        file_path = os.path.join(file_path, 'person_body_template.json')

        file_content = None
        with open(file_path, 'r') as f:
            file_content = f.read()

        # Test basic read
        handler = ContentHandler()
        handler.setup(file_path, is_file=True)
        self.assertEqual(file_content, handler.get_content())

        # Test templating of read content
        handler.setup(file_path, is_file=True, is_template_content=True)
        self.assertEqual(file_content, handler.get_content())
        self.assertEqual(file_content,
                         handler.get_content(context))  # No substitution
        substituted = string.Template(file_content).safe_substitute(variables)
        context.bind_variables(variables)
        self.assertEqual(substituted, handler.get_content(context))

        # Test path templating
        templated_file_path = '$filepath'
        context.bind_variable('filepath', file_path)
        handler.setup(file_path, is_file=True, is_template_path=True)
        self.assertEqual(file_content, handler.get_content(context))

        # Test double templating with files
        handler.setup(file_path,
                      is_file=True,
                      is_template_path=True,
                      is_template_content=True)
        self.assertEqual(substituted, handler.get_content(context=context))