|
@@ -1,8 +1,25 @@
|
|
|
-from django.test import TestCase
|
|
|
+import json
|
|
|
+
|
|
|
+from django.test import TestCase, Client
|
|
|
|
|
|
from contribmap.models import Contrib
|
|
|
|
|
|
|
|
|
+class APITestClient(Client):
|
|
|
+ def json_get(self, *args, **kwargs):
|
|
|
+ """ Annotate the response with a .data containing parsed JSON
|
|
|
+ """
|
|
|
+ response = super().get(*args, **kwargs)
|
|
|
+ response.data = json.loads(response.content.decode('utf-8'))
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+class APITestCase(TestCase):
|
|
|
+ def setUp(self):
|
|
|
+ super().setUp()
|
|
|
+ self.client = APITestClient()
|
|
|
+
|
|
|
+
|
|
|
class TestContrib(TestCase):
|
|
|
def test_comma_separatedcharfield(self):
|
|
|
co = Contrib(name='foo', orientations=['SO', 'NE'])
|
|
@@ -42,6 +59,23 @@ class TestContribPrivacy(TestCase):
|
|
|
self.assertEqual(c.get_public_field('name'), None)
|
|
|
|
|
|
|
|
|
+class TestViews(APITestCase):
|
|
|
+ def test_public_json(self):
|
|
|
+ response = self.client.json_get('/map/public.json')
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
+ self.assertEqual(len(response.data['features']), 0)
|
|
|
+
|
|
|
+ Contrib.objects.create(
|
|
|
+ name='John',
|
|
|
+ phone='010101010101',
|
|
|
+ contrib_type=Contrib.CONTRIB_CONNECT,
|
|
|
+ privacy_coordinates=False,
|
|
|
+ )
|
|
|
+ response = self.client.json_get('/map/public.json')
|
|
|
+ self.assertEqual(response.status_code, 200)
|
|
|
+ self.assertEqual(len(response.data['features']), 1)
|
|
|
+
|
|
|
+
|
|
|
class TestDataImport(TestCase):
|
|
|
fixtures = ['bottle_data.yaml']
|
|
|
|