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
|
#!/usr/bin/python3
# =================================================================
#
# Authors: Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2015 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================
import os
JQUERY_VERSION = '1.9.0'
print('''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>pycsw Tester</title>
<style type="text/css">
body {
background-color: #ffffff;
font-family: arial, verdana, sans-serif;
text-align: left;
float: left;
}
.flat {
border: 0px;
}
</style>
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.xml').change(function() {
if ($(this).val() != 'none') {
var arr = $(this).val().split(',');
$.ajax({
type: 'GET',
url: arr[1],
dataType: 'text',
success: function(data) {
$('.request').val(data);
$('.server').val('../csw.py?config=/usr/share/pycsw/' + arr[0]);
}
});
}
});
$('.send').click(function() {
$.ajax({
type: 'POST',
contentType: 'text/xml',
url: $('.server').val(),
data: $('.request').val(),
dataType: 'text',
success: function(data) {
$('.response').val(data);
},
error: function(data1) {
$('.response').val(data1.responseText);
}
});
});
});
</script>
</head>
''')
print('''
<body>
<h2 class="header">pycsw Tester</h2>
<hr/>
<h3 class="header">HTTP POST</h3>
<form action="#" id="tests">
<table>
<tr>
<th>Request</th>
<th>Response</th>
</tr>
<tr>
<td>
<select class="xml">
<option value="none">Select a CSW Request</option>''')
for root, dirs, files in os.walk('functionaltests/suites'):
if files:
for sfile in files:
if os.path.splitext(sfile)[1] in ['.xml'] and 'post' in root: # it's a POST request
query = '%s%s%s' % (root.replace(os.sep, '/'), '/', sfile)
print(' <option value="tests/functionaltests/suites/%s/default.cfg,%s">%s</option>' % (root.split(os.sep)[2], query, query))
print('''
</select>
<input type="button" class="send" value="Send"/>
</td>
<td>
Server: <input type="text" size="40" class="server" value="../csw.py"/>
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="70" class="request"></textarea>
</td>
<td>
<textarea rows="20" cols="70" class="response"></textarea>
</td>
</tr>
</table>
</form>
<hr/>
<h3 class="header">HTTP GET</h3>
<ul>
''')
for root, dirs, files in os.walk('functionaltests/suites'):
if files:
for sfile in files:
if sfile == 'requests.txt': # it's a list of GET requests
file_path = os.path.join(root, sfile)
with open(file_path) as f:
for line in f:
name, query_string = line.strip().partition(",")[::2]
baseurl = "../csw.py"
query = "{baseurl}?{query_string}".format(
baseurl=baseurl,
query_string=query_string.replace("&", "&")
)
print('<li><a href={query!r}>{name}</a></li>'.format(
query=query, name=name))
print('''
</ul>
<hr/>
<footer>
<a href="http://validator.w3.org/check?verbose=1&uri=referer" title="Valid HTML 5!">Valid HTML 5!</a>
<a href="http://jigsaw.w3.org/css-validator/check/referer" title="Valid CSS!">Valid CSS!</a>
</footer>
</body>
</html>
''')
|