diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-22 21:01:28 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-09-22 21:01:28 +0200 |
commit | 2fe55c3556ee38ca98db9ef57b9f85ac2d7a11e4 (patch) | |
tree | fd1851f2099f3dc9679ec895884f585be4e675f8 /chimere | |
parent | 763dc6c6775d9e544fa7339f0e4ec4bf21175e93 (diff) | |
download | Chimère-2fe55c3556ee38ca98db9ef57b9f85ac2d7a11e4.tar.bz2 Chimère-2fe55c3556ee38ca98db9ef57b9f85ac2d7a11e4.zip |
tests: fix files management in tests
Diffstat (limited to 'chimere')
-rw-r--r-- | chimere/tests.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/chimere/tests.py b/chimere/tests.py index af97d87..e8b280f 100644 --- a/chimere/tests.py +++ b/chimere/tests.py @@ -4,9 +4,9 @@ import datetime import lxml.etree +import shutil from io import StringIO import os -from shutil import copyfile import json import sys @@ -30,6 +30,12 @@ from chimere.templatetags.chimere_tags import display_news from chimere.utils import ShapefileManager +def copy_file_to_media(source): + dest = os.path.join(settings.MEDIA_ROOT, source.split(os.sep)[-1]) + shutil.copy(source, dest) + return File(open(dest, 'rb')) + + def areas_setup(): area_1 = Area.objects.create( name='area 1', urn='area-1', order=1, available=True, @@ -68,8 +74,8 @@ def subcategory_setup(): media_root = settings.MEDIA_ROOT if not media_root.endswith(os.sep): media_root += os.sep - copyfile(test_dir_path + "static/chimere/img/marker.png", - settings.MEDIA_ROOT + "marker.png") + shutil.copyfile(test_dir_path + "static/chimere/img/marker.png", + settings.MEDIA_ROOT + "marker.png") icon = Icon.objects.create(name='Default icon', image='marker.png', height=25, @@ -327,9 +333,10 @@ class GeoRSSImporterTest(TestCase, ImporterTest): class HtmlXsltImporterTest(TestCase, ImporterTest): def setUp(self): subcategories = subcategory_setup() - xslt1 = File(open(test_dir_path + 'tests/villiers-le-bacle.xslt')) - xslt2 = File(open(test_dir_path + - 'tests/villiers-le-bacle-detail.xslt')) + xslt1 = copy_file_to_media( + test_dir_path + 'tests/villiers-le-bacle.xslt') + xslt2 = copy_file_to_media( + test_dir_path + 'tests/villiers-le-bacle-detail.xslt') importer1 = Importer.objects.create( importer_type='XSLT', source='http://www.chymeres.net/test/ville-villierslebacle.fr/', @@ -342,7 +349,8 @@ class HtmlXsltImporterTest(TestCase, ImporterTest): class XmlXsltImporterTest(TestCase, ImporterTest): def setUp(self): subcategories = subcategory_setup() - xslt1 = File(open(test_dir_path + 'tests/magny-xml.xslt')) + xslt1 = copy_file_to_media( + test_dir_path + 'tests/magny-xml.xslt') importer1 = Importer.objects.create( importer_type='XXLT', source='http://www.chymeres.net/test/magny.xml', @@ -355,7 +363,8 @@ class XmlXsltImporterTest(TestCase, ImporterTest): class JsonImporterTest(TestCase, ImporterTest): def setUp(self): subcategories = subcategory_setup() - jsonfile = File(open(test_dir_path + 'tests/test.json')) + jsonfile = copy_file_to_media( + test_dir_path + 'tests/test.json') importer1 = Importer.objects.create( importer_type='JSON', source_file=jsonfile, @@ -365,7 +374,8 @@ class JsonImporterTest(TestCase, ImporterTest): default_localisation='SRID=4326;POINT(-4.5 48.4)',) importer1.categories.add(subcategories[0]) - jsonfile = File(open(test_dir_path + 'tests/events.json')) + jsonfile = copy_file_to_media( + test_dir_path + 'tests/events.json') importer2 = Importer.objects.create( importer_type='JSON', source_file=jsonfile, @@ -386,7 +396,8 @@ class JsonImporterTest(TestCase, ImporterTest): class IcalImporterTest(TestCase, ImporterTest): def setUp(self): subcategories = subcategory_setup() - icsfile = File(open(test_dir_path + 'tests/test.ics')) + + icsfile = copy_file_to_media(test_dir_path + 'tests/test.ics') importer1 = Importer.objects.create( importer_type='ICAL', source_file=icsfile,) @@ -758,7 +769,7 @@ class V3ToV2Test(TestCase): call_command('v3_to_v2_routes') vals = sys.stdout.getvalue() routes = json.loads(vals) - self.assertEqual(len(routes), 2) + self.assertEqual(len(routes), len(self.routes)) self.assertNotIn('weight', routes[0]['fields']) self.assertNotIn('normalised_weight', routes[0]['fields']) self.assertNotIn('color', routes[0]['fields']) |