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

Source Code for Module madrona.layer_manager.tests

 1  from django.test import TestCase 
 2  from django.test.client import Client 
 3  from madrona.layer_manager.models import Theme, Layer 
 4  import simplejson 
 5   
6 -class LayerManagerTest(TestCase):
7 - def setUp(self):
8 self.client = Client() 9 self.url = '/layer_manager/get_json' 10 self.theme1 = Theme.objects.create(name="Theme1") 11 self.layer1 = Layer.objects.create(name="Layer1", layer_type='XYZ', 12 url='https://example.com/ocsb1/ocsb/${z}/${x}/${y}.png') 13 self.layer1.themes.add(self.theme1) 14 self.layer2 = Layer.objects.create(name="Layer2", layer_type='XYZ', 15 url='https://example.com/ocsb2/ocsb/${z}/${x}/${y}.png') 16 self.layer2.themes.add(self.theme1)
17
18 - def test_themes(self):
19 response = self.client.get(self.url) 20 self.assertEqual(response.status_code, 200, response.status_code) 21 res_str = response.content 22 obj = simplejson.loads(res_str) 23 self.assertEqual(obj["state"]["activeLayers"], [], obj) 24 self.assertEqual(obj["themes"][0]["name"], "Theme1", obj) 25 self.assertEqual(obj["themes"][0]["layers"], [self.layer1.id, self.layer2.id], obj)
26
27 - def test_state(self):
28 response = self.client.get(self.url) 29 self.assertEqual(response.status_code, 200, response.status_code) 30 res_str = response.content 31 obj = simplejson.loads(res_str) 32 self.assertEqual(obj["state"]["activeLayers"], [], obj) 33
34 - def test_layers(self):
35 response = self.client.get(self.url) 36 self.assertEqual(response.status_code, 200, response.status_code) 37 res_str = response.content 38 obj = simplejson.loads(res_str) 39 self.assertEqual(obj["layers"][0]["name"], "Layer1") 40 for layerid in obj["themes"][0]["layers"]: 41 # make sure we can get the specified layer through the ORM 42 lyr = Layer.objects.get(id=layerid) 43