/usr/lib/python3/dist-packages/protorpc/webapp/forms_test.py is in python3-protorpc-standalone 0.9.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for protorpc.forms."""
__author__ = 'rafek@google.com (Rafe Kaplan)'
import os
import unittest
from protorpc import test_util
from protorpc import webapp_test_util
from protorpc.webapp import forms
from protorpc.webapp.google_imports import template
class ModuleInterfaceTest(test_util.ModuleInterfaceTest,
test_util.TestCase):
MODULE = forms
def RenderTemplate(name, **params):
"""Load content from static file.
Args:
name: Name of static file to load from static directory.
params: Passed in to webapp template generator.
Returns:
Contents of static file.
"""
path = os.path.join(forms._TEMPLATES_DIR, name)
return template.render(path, params)
class ResourceHandlerTest(webapp_test_util.RequestHandlerTestBase):
def CreateRequestHandler(self):
return forms.ResourceHandler()
def DoStaticContentTest(self, name, expected_type):
"""Run the static content test.
Loads expected static content from source and compares with
results in response. Checks content-type and cache header.
Args:
name: Name of file that should be served.
expected_type: Expected content-type of served file.
"""
self.handler.get(name)
content = RenderTemplate(name)
self.CheckResponse('200 OK',
{'content-type': expected_type,
},
content)
def testGet(self):
self.DoStaticContentTest('forms.js', 'text/javascript')
def testNoSuchFile(self):
self.handler.get('unknown.txt')
self.CheckResponse('404 Not Found',
{},
'Resource not found.')
class FormsHandlerTest(webapp_test_util.RequestHandlerTestBase):
def CreateRequestHandler(self):
handler = forms.FormsHandler('/myreg')
self.assertEquals('/myreg', handler.registry_path)
return handler
def testGetForm(self):
self.handler.get()
content = RenderTemplate(
'forms.html',
forms_path='/tmp/myhandler',
hostname=self.request.host,
registry_path='/myreg')
self.CheckResponse('200 OK',
{},
content)
def testGet_MissingPath(self):
self.ResetHandler({'QUERY_STRING': 'method=my_method'})
self.handler.get()
content = RenderTemplate(
'forms.html',
forms_path='/tmp/myhandler',
hostname=self.request.host,
registry_path='/myreg')
self.CheckResponse('200 OK',
{},
content)
def testGet_MissingMethod(self):
self.ResetHandler({'QUERY_STRING': 'path=/my-path'})
self.handler.get()
content = RenderTemplate(
'forms.html',
forms_path='/tmp/myhandler',
hostname=self.request.host,
registry_path='/myreg')
self.CheckResponse('200 OK',
{},
content)
def testGetMethod(self):
self.ResetHandler({'QUERY_STRING': 'path=/my-path&method=my_method'})
self.handler.get()
content = RenderTemplate(
'methods.html',
forms_path='/tmp/myhandler',
hostname=self.request.host,
registry_path='/myreg',
service_path='/my-path',
method_name='my_method')
self.CheckResponse('200 OK',
{},
content)
def main():
unittest.main()
if __name__ == '__main__':
main()
|