Package madrona :: Package studyregion :: Module tests
[hide private]

Source Code for Module madrona.studyregion.tests

 1  """ 
 2  This file demonstrates two different styles of tests (one doctest and one 
 3  unittest). These will both pass when you run "manage.py test". 
 4   
 5  Replace these with more appropriate tests for your application. 
 6  """ 
 7   
 8  from django.test import TestCase, Client 
 9  from madrona.studyregion.models import StudyRegion 
10  from django.conf.urls.defaults import * 
11  from django.conf import settings 
12  from django.contrib.gis.geos import GEOSGeometry  
13   
14  urlpatterns = patterns('', 
15      # Example: 
16      (r'/studyregion/', include('madrona.studyregion.urls')), 
17  ) 
18   
19 -class StudyRegionTest(TestCase):
20 fixtures = ['example_data'] 21
22 - def testStudyRegionPresent(self):
23 """ 24 Check presence of test study region 25 """ 26 self.assertTrue(StudyRegion.objects.count() >= 1) 27 self.assertEquals(StudyRegion.objects.all()[0].id, 1)
28
29 - def testComputeLookAt(self):
30 """ 31 Check computing of lookat values 32 """ 33 g1 = GEOSGeometry( 34 'SRID=4326;MULTIPOLYGON(((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37)))') 35 g1.transform(settings.GEOMETRY_DB_SRID) 36 region = StudyRegion.objects.create(geometry=g1, name="Test region", active=True) 37 region.lookAt_Lat = 0 38 region.lookAt_Lon = 0 39 self.assertEquals(region.lookAt_Lat, 0.0) 40 self.assertEquals(region.lookAt_Lon, 0.0) 41 lookat_kml = region.lookAtKml() 42 self.assertAlmostEquals(region.lookAt_Lat, 34.239691894000003) 43 self.assertAlmostEquals(region.lookAt_Lon, -120.03929305)
44
45 - def testLookAtView(self):
46 """ 47 test views.regionLookAtKml 48 """ 49 response = self.client.get('/studyregion/lookAtKml/', {}) 50 self.assertEquals(response.status_code, 200)
51 52 # This test is not really necessary and takes forever to run so lets just comment it out for now 53 # def testKmlChunkView(self): 54 # """ 55 # test views.kml_chunk 56 # """ 57 # response = self.client.get('/studyregion/kml_chunk/34.473517/32.530798/-117.093325/-120.580374/', {}) 58 # self.assertEquals(response.status_code, 200) 59
60 - def testKmlView(self):
61 """ 62 test views.kml 63 """ 64 response = self.client.get('/studyregion/kml/', {}) 65 self.assertEquals(response.status_code, 200)
66 67 # this is a non-critical test, which is failing on the server, but not local dev boxes, with: 68 # TemplateSyntaxError: Caught an exception while rendering: compress/css.html 69 70 # disabling test 71 72 #def testStudyRegionSandboxView(self): 73 #""" 74 #test views.studyregion 75 #""" 76 77 #response = self.client.get('/studyregion/', {}) 78 #self.assertEquals(response.status_code, 200) 79
80 - def testExternalKmlStyle(self):
81 settings.DEBUG = True 82 response = self.client.get('/media/studyregion/styles.kml', {}) 83 self.assertEquals(response.status_code, 200)
84
85 - def testOnlyOneActive(self):
86 # Only need to create one to test since there is an active study 87 # region fixture 88 count = StudyRegion.objects.count() 89 self.assertTrue(count > 0) 90 studyregion = StudyRegion.objects.create(active=True) 91 self.assertTrue(StudyRegion.objects.count() > count) 92 self.assertTrue(StudyRegion.objects.filter(active=True).count() == 1) 93 self.assertTrue(StudyRegion.objects.get(active=True).pk == studyregion.pk)
94