1 """
2 Unit tests for staticmap rendering via mapnik
3 """
4 from django.conf import settings
5 from django.conf.urls.defaults import *
6 from django.contrib.auth.models import User, Group
7 from django.contrib.gis.geos import GEOSGeometry
8 from django.contrib.contenttypes.models import ContentType
9 from django.test import Client
10 from madrona.common.test_settings_manager import SettingsTestCase as TestCase
11 from madrona.common.utils import enable_sharing
12 from madrona.staticmap.models import MapConfig
13 from madrona.features.tests import TestMpa, TestArray
14
15
17 fixtures = ['example_data']
18
20 self.client = Client()
21
22
23 self.password = 'iluvmapnik'
24 self.user = User.objects.create_user('user1', 'test@madrona.org', password=self.password)
25 self.user2 = User.objects.create_user('user2', 'test@madrona.org', password=self.password)
26
27 self.group1 = Group.objects.create(name="Test Group 1")
28 self.group1.save()
29 self.user.groups.add(self.group1)
30 self.user2.groups.add(self.group1)
31 enable_sharing(self.group1)
32 self.public = Group.objects.get(name=settings.SHARING_TO_PUBLIC_GROUPS[0])
33 self.user.groups.add(self.public)
34
35
36 g1 = GEOSGeometry('SRID=4326;POLYGON((-120.42 34.37, -119.64 34.32, -119.63 34.12, -120.44 34.15, -120.42 34.37))')
37 g1.transform(settings.GEOMETRY_DB_SRID)
38
39
40 mpa1 = TestMpa.objects.create(name='Test_MPA_1', designation='R', user=self.user, geometry_orig=g1)
41 mpa1.save()
42 mpa2 = TestMpa.objects.create(name='Test_MPA_2', designation='P', user=self.user, geometry_orig=g1)
43 mpa2.save()
44 mpa3 = TestMpa.objects.create(name='Test_MPA_3', designation='C', user=self.user, geometry_orig=g1)
45 mpa3.save()
46 self.mpa_ids = [mpa1.pk, mpa2.pk, mpa3.pk]
47 self.mpa_uids = ['%s_%s' % (mpa1.model_uid(), x) for x in self.mpa_ids]
48
49
50 array1 = TestArray.objects.create(name='Test_Array_1', user=self.user)
51 array1.save()
52 array2 = TestArray.objects.create(name='Test_Array_2', user=self.user)
53 array2.save()
54 mpa1.add_to_collection(array1)
55 mpa2.add_to_collection(array2)
56
57 array1.share_with(self.group1)
58 array2.share_with(self.public)
59
60 self.array_ids = [array1.pk, array2.pk]
61 self.array_uids = ['%s_%s' % (array1.model_uid(), x) for x in self.array_ids]
62
68
70 response = self.client.get('/staticmap/default/', {})
71 self.assertEquals(response.status_code, 200)
72 blank_map = response.content
73
74
75 self.client.login(username=self.user.username, password=self.password)
76 uidcsv = ','.join(self.mpa_uids)
77 url = '/staticmap/default/?uids=%s' % uidcsv
78 response = self.client.get(url)
79 self.assertEquals(response.status_code, 200)
80
82
83 self.client.login(username=self.user.username, password=self.password)
84 uidcsv = ','.join(self.mpa_uids)
85
86 url = '/staticmap/default/?autozoom=true&uids=%s' % uidcsv
87 response = self.client.get(url)
88 self.assertEquals(response.status_code, 200)
89
90 url = '/staticmap/default/?show_extent=true&uids=%s' % uidcsv
91 response = self.client.get(url)
92 self.assertEquals(response.status_code, 200)
93
95
96 self.client.login(username=self.user.username, password=self.password)
97 uidcsv = ','.join(self.array_uids)
98 url = '/staticmap/default/?uids=%s' % uidcsv
99 response = self.client.get(url)
100 self.assertEquals(response.status_code, 200)
101
103 response = self.client.get('/staticmap/default/', {})
104 self.assertEquals(response.status_code, 200)
105 blank_map = response.content
106
107
108 self.client.login(username=self.user2.username, password=self.password)
109 response = self.client.get('/staticmap/default/?uids=%s' % self.mpa_uids[2], {})
110 self.assertEquals(response.status_code, 200)
111
112
114 response = self.client.get('/staticmap/default/', {})
115 self.assertEquals(response.status_code, 200)
116 blank_map = response.content
117
118
119 response = self.client.get('/staticmap/default/?uids=%s' % ','.join(self.mpa_uids), {})
120 self.assertEquals(response.status_code, 200)
121
122
124 response = self.client.get('/staticmap/default/', {})
125 self.assertEquals(response.status_code, 200)
126 blank_map = response.content
127
128
129 response = self.client.get('/staticmap/default/?uids=%s' % self.mpa_uids[2], {})
130 self.assertEquals(response.status_code, 200)
131
132 response = self.client.get('/staticmap/default/?uids=%s' % self.mpa_uids[1], {})
133 self.assertEquals(response.status_code, 200)
134
135
140
148