1 from django.test import TestCase
2 from django.conf import settings
3 from django.contrib.gis import geos
4 from madrona.common.utils import *
5 import os
6
9 """
10 Should return a list of javascript files from
11 media/common/js_includes.xml
12 """
13 from madrona.common import assets
14 files = assets.get_js_files()
15 self.assertEquals(files.__class__.__name__, 'list')
16 self.assertTrue(len(files) > 0)
17
19 """
20 Should return a list of stylesheets from media/common/css_includes.xml
21 """
22 from madrona.common import assets
23 files = assets.get_css_files()
24 self.assertEquals(files.__class__.__name__, 'list')
25 self.assertTrue(len(files) > 0)
26
29
32
33 pnt1 = Point(1,0)
34 pnt2 = Point(0,0)
35 pnt3 = Point(0,1)
36 result = angle(pnt1,pnt2,pnt3)
37 self.assertEquals(result,1.5707963267949001)
38
39
40 pnt1.srid = 3310
41 pnt2.srid = 3310
42 pnt3.srid = 3310
43 result2 = angle(pnt1,pnt2,pnt3)
44 self.assertEquals(result2,1.5707963267949001)
45
47 poly = geos.fromstr('POLYGON((3480407.01 5483810.171,3480407.01 5483810.17,3480409.11 5483777.431,3480407.348 5483777.421,3480405.15 5483777.409,3480404.816 5483777.407,3480394.58 5483777.35,3480395.36 5483811.12,3480404.55 5483810.46,3480405.951 5483810.295,3480406.312 5483795.106,3480405.951 5483810.296,3480406.903 5483810.184,3480407.01 5483810.171))')
48 indecies = spike_ring_indecies(poly.exterior_ring, 0.01)
49 self.assertEquals(indecies[0],10)
50
52 poly = geos.fromstr('POLYGON ((3415632.4900000002235174 5291021.4900000002235174, 3415632.4879999998956919 5291021.4939999999478459, 3415632.4900000002235174 5291021.4939999999478459, 3415628.9300000001676381 5291028.2800000002607703, 3415642.9500000001862645 5291001.5599999995902181, 3415651.1800000001676381 5290985.8600000003352761, 3415659.2700000000186265 5290984.6100000003352761, 3415644.7099999999627471 5290947.8099999995902181, 3415629.1699999999254942 5290921.8300000000745058, 3415621.2799999997951090 5290929.7199999997392297, 3415640.2099999999627471 5290959.4299999997019768, 3415625.3799999998882413 5290971.4100000001490116, 3415627.7900000000372529 5290983.9400000004097819, 3415629.4900000002235174 5290992.1900000004097819, 3415630.1400000001303852 5290995.3600000003352761, 3415625.6499999999068677 5291022.5000000000000000, 3415632.4900000002235174 5291021.4900000002235174))')
53 result = remove_spikes(poly, 0.01)
54 expected_wkt = 'POLYGON ((3415632.4900000002235174 5291021.4900000002235174, 3415632.4879999998956919 5291021.4939999999478459, 3415632.4900000002235174 5291021.4939999999478459, 3415642.9500000001862645 5291001.5599999995902181, 3415651.1800000001676381 5290985.8600000003352761, 3415659.2700000000186265 5290984.6100000003352761, 3415644.7099999999627471 5290947.8099999995902181, 3415629.1699999999254942 5290921.8300000000745058, 3415621.2799999997951090 5290929.7199999997392297, 3415640.2099999999627471 5290959.4299999997019768, 3415625.3799999998882413 5290971.4100000001490116, 3415627.7900000000372529 5290983.9400000004097819, 3415629.4900000002235174 5290992.1900000004097819, 3415630.1400000001303852 5290995.3600000003352761, 3415625.6499999999068677 5291022.5000000000000000, 3415632.4900000002235174 5291021.4900000002235174))'
55 self.assertEquals(result.wkt,expected_wkt)
56 result = remove_spikes(result, 0.01)
57 self.assertEquals(result,expected_wkt)
58
59 from django.utils.hashcompat import md5_constructor as md5
60
69
70
73 exdir = os.path.dirname(os.path.abspath(__file__))
74 self.supported_uastring_examples = [x.strip() for x in open(exdir + '/supported_user_agent_examples.txt').readlines()]
75 self.unsupported_uastring_examples = [x.strip() for x in open(exdir + '/unsupported_user_agent_examples.txt').readlines()]
76
83
90
92 url = '/'
93 agent = {'HTTP_USER_AGENT': self.supported_uastring_examples[0]}
94 response = self.client.get(url, **agent)
95 self.assertEquals(response.status_code, 200, url)
96
97 response = self.client.get(url, **agent)
98 self.assertEquals(response.status_code, 200, url)
99
100 response = self.client.get(url, **agent)
101 self.assertEquals(response.status_code, 200, url)
102
104
105 url = '/'
106 agent = {'HTTP_USER_AGENT': self.unsupported_uastring_examples[0]}
107 response = self.client.get(url, **agent)
108 self.assertEquals(response.status_code, 200, url)
109
110 url = '/?supported=false'
111 response = self.client.get(url, **agent)
112 self.assertEquals(response.status_code, 200, url)
113
115
117 """ Ensure that the upload directory is not web accessible """
118
119 url = settings.MEDIA_URL + 'upload/'
120 response = self.client.get(url)
121 self.assertEquals(response.status_code, 403, url)
122
123 url = settings.MEDIA_URL + 'upload/test.txt'
124 response = self.client.get(url)
125 self.assertEquals(response.status_code, 403, url)
126
127 url = settings.MEDIA_URL + '/upload/test.txt'
128 response = self.client.get(url)
129 self.assertEquals(response.status_code, 403, url)
130
131 url = settings.MEDIA_URL + '/./upload/test.txt'
132 response = self.client.get(url)
133 self.assertEquals(response.status_code, 403, url)
134
136
138 """ Make sure we dont have any apps with duplicate app_labels
139 for the sake of south, contenttypes and any other django piece
140 which relies on app_label """
141
142 labels = [x.split('.')[-1] for x in settings.INSTALLED_APPS]
143 counts = {}
144 for label in labels:
145 if label not in counts.keys():
146 counts[label] = 1
147 else:
148 counts[label] += 1
149
150 for k,v in counts.items():
151 self.assertEquals(v, 1, 'app_label %s refers to %s apps' % (k,v))
152
154
156 imports = [
157 'networkx',
158 'south',
159 'django.contrib.gis',
160 'elementtree',
161 'sphinx',
162 'mapnik',
163 'BeautifulSoup',
164 'xlwt',
165 'registration',
166 'compress',
167 'maintenancemode',
168 ]
169 from django.utils import importlib
170 for dep in imports:
171 try:
172 m = importlib.import_module(dep)
173 except:
174 m = None
175 self.assertNotEquals(m,None,'Cannot import %s' % dep)
176
177
178 from django.contrib.gis.geos import GEOSGeometry
179 from madrona.common.utils import forceLHR, forceRHR
180
182
184 gright = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -119.64 34.32, -119.63 34.12, -122.44 34.15, -120.42 34.37))')
185 gleft = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -122.44 34.15, -119.63 34.12, -119.64 34.32, -120.42 34.37))')
186
187
188 self.assertEqual(gright.coords, forceRHR(gright).coords)
189 self.assertEqual(gleft.coords, forceLHR(gleft).coords)
190
191
192 self.assertEqual(gleft.coords, forceLHR(gright).coords)
193 self.assertEqual(gright.coords, forceRHR(gleft).coords)
194
196 g = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -119.64 34.32, -119.63 34.12, -122.44 34.15, -120.42 34.37))')
197 kml = asKml(g)
198
200
201 gcomplex = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -120.422 34.372, -119.64 34.32, -119.63 34.12, -122.44 34.15, -120.42 34.37))')
202 gsimple = GEOSGeometry('SRID=4326;POLYGON ((-120.42 34.37, -119.64 34.32, -119.63 34.12, -122.44 34.15, -120.42 34.37))')
203
204 gsimplified_large = gcomplex.simplify(0.01)
205 self.assertEqual(gsimple, gsimplified_large)
206
207 gsimplified_small = gcomplex.simplify(0.000001)
208 self.assertEqual(gcomplex, gsimplified_small)
209