Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

from django.test import TestCase 

from django.test.client import Client 

from madrona.layer_manager.models import Theme, Layer 

import simplejson 

 

class LayerManagerTest(TestCase): 

    def setUp(self): 

        self.client = Client() 

        self.url = '/layer_manager/get_json' 

        self.theme1 = Theme.objects.create(name="Theme1") 

        self.layer1 = Layer.objects.create(name="Layer1", layer_type='XYZ', 

                url='https://example.com/ocsb1/ocsb/${z}/${x}/${y}.png') 

        self.layer1.themes.add(self.theme1) 

        self.layer2 = Layer.objects.create(name="Layer2", layer_type='XYZ', 

                url='https://example.com/ocsb2/ocsb/${z}/${x}/${y}.png') 

        self.layer2.themes.add(self.theme1) 

 

    def test_themes(self): 

        response = self.client.get(self.url) 

        self.assertEqual(response.status_code, 200, response.status_code) 

        res_str = response.content 

        obj = simplejson.loads(res_str) 

        self.assertEqual(obj["state"]["activeLayers"], [], obj) 

        self.assertEqual(obj["themes"][0]["name"], "Theme1", obj) 

        self.assertEqual(obj["themes"][0]["layers"], [self.layer1.id, self.layer2.id], obj) 

 

    def test_state(self): 

        response = self.client.get(self.url) 

        self.assertEqual(response.status_code, 200, response.status_code) 

        res_str = response.content 

        obj = simplejson.loads(res_str) 

        self.assertEqual(obj["state"]["activeLayers"], [], obj) 

 

    def test_layers(self): 

        response = self.client.get(self.url) 

        self.assertEqual(response.status_code, 200, response.status_code) 

        res_str = response.content 

        obj = simplejson.loads(res_str) 

        self.assertEqual(obj["layers"][0]["name"], "Layer1") 

        for layerid in obj["themes"][0]["layers"]: 

            # make sure we can get the specified layer through the ORM 

            lyr = Layer.objects.get(id=layerid)