summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-21 13:14:13 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2017-02-21 13:33:50 +0100
commit9184895fb1441eae46ba30c70129ee4a30852b72 (patch)
tree9dcc71a6235664dbb6a1c611e04b11630a6978fa
parent1db0f22eb705e1a0035c777a03cfdc2af87636b7 (diff)
downloadChimère-9184895fb1441eae46ba30c70129ee4a30852b72.tar.bz2
Chimère-9184895fb1441eae46ba30c70129ee4a30852b72.zip
v3 to v2 dumps
-rw-r--r--chimere/management/commands/v3_to_v2_markers.py25
-rw-r--r--chimere/management/commands/v3_to_v2_routes.py26
-rw-r--r--chimere/tests.py35
3 files changed, 85 insertions, 1 deletions
diff --git a/chimere/management/commands/v3_to_v2_markers.py b/chimere/management/commands/v3_to_v2_markers.py
new file mode 100644
index 0000000..79188ba
--- /dev/null
+++ b/chimere/management/commands/v3_to_v2_markers.py
@@ -0,0 +1,25 @@
+from io import StringIO
+import json
+
+from django.core.management import call_command
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ help = "Marker dump for v2"
+
+ def handle(self, *args, **options):
+ out = StringIO()
+ call_command('dumpdata', 'chimere.Marker', indent=4, stdout=out)
+ vals = out.getvalue()
+ markers = json.loads(vals)
+ new_markers = []
+ for marker in markers:
+ data = marker.copy()
+ data['fields'].pop('weight')
+ data['fields'].pop('normalised_weight')
+ new_markers.append(data)
+ res = json.dumps(new_markers)
+ self.stdout.write(res)
+
+
diff --git a/chimere/management/commands/v3_to_v2_routes.py b/chimere/management/commands/v3_to_v2_routes.py
new file mode 100644
index 0000000..d373e25
--- /dev/null
+++ b/chimere/management/commands/v3_to_v2_routes.py
@@ -0,0 +1,26 @@
+from io import StringIO
+import json
+
+from django.core.management import call_command
+from django.core.management.base import BaseCommand
+
+
+class Command(BaseCommand):
+ help = "Route dump for v2"
+
+ def handle(self, *args, **options):
+ out = StringIO()
+ call_command('dumpdata', 'chimere.Route', indent=4, stdout=out)
+ vals = out.getvalue()
+ routes = json.loads(vals)
+ new_routes = []
+ for route in routes:
+ data = route.copy()
+ data['fields'].pop('weight')
+ data['fields'].pop('normalised_weight')
+ data['fields'].pop('color')
+ new_routes.append(data)
+ res = json.dumps(new_routes)
+ self.stdout.write(res)
+
+
diff --git a/chimere/tests.py b/chimere/tests.py
index ad54532..fde2702 100644
--- a/chimere/tests.py
+++ b/chimere/tests.py
@@ -4,9 +4,12 @@
import datetime
import lxml.etree
+from io import StringIO
import os
from shutil import copyfile
import json
+import sys
+
test_path = os.path.abspath(__file__)
test_dir_path = os.path.dirname(test_path) + os.sep
@@ -15,6 +18,7 @@ from django.contrib.gis.geos import GEOSGeometry
from django.conf import settings
from django.core import mail
from django.core.files import File
+from django.core.management import call_command
from django.core.urlresolvers import reverse
from django.template import Context
from django.test import TestCase
@@ -404,7 +408,6 @@ class MainUITest(TestCase):
self.assertEqual(200, response.status_code)
-
class AdministratorsTest(TestCase):
def setUp(self):
self.areas = areas_setup()
@@ -693,3 +696,33 @@ class RapprochementTest(TestCase):
class RouteTest(TestCase):
def setUp(self):
self.subcategories = subcategory_setup()
+
+
+class V3ToV2Test(TestCase):
+ def setUp(self):
+ self.areas = areas_setup()
+ self.markers = marker_setup()
+ self.routes = route_setup()
+
+ def test_markers(self):
+ sysout = sys.stdout
+ sys.stdout = StringIO()
+ call_command('v3_to_v2_markers')
+ vals = sys.stdout.getvalue()
+ markers = json.loads(vals)
+ self.assertEqual(len(markers), 3)
+ self.assertNotIn('weight', markers[0]['fields'])
+ self.assertNotIn('normalised_weight', markers[0]['fields'])
+ sys.stdout = sysout
+
+ def test_routes(self):
+ sysout = sys.stdout
+ sys.stdout = StringIO()
+ call_command('v3_to_v2_routes')
+ vals = sys.stdout.getvalue()
+ routes = json.loads(vals)
+ self.assertEqual(len(routes), 2)
+ self.assertNotIn('weight', routes[0]['fields'])
+ self.assertNotIn('normalised_weight', routes[0]['fields'])
+ self.assertNotIn('color', routes[0]['fields'])
+ sys.stdout = sysout