From 75cbf68789fcf98ce558237c89378b3da6b7b72e Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 27 Oct 2015 14:23:07 -0400 Subject: [PATCH] Clean up imports --- magma/app.py | 2 ++ magma/home/__init__.py | 21 +++++++++++---------- magma/upload.py | 5 +++-- magma/wsgi.py | 1 - tests/conftest.py | 1 + tests/test_upload.py | 10 ++++++---- tests/test_views.py | 8 +++++--- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/magma/app.py b/magma/app.py index 96936bf..b1acbea 100644 --- a/magma/app.py +++ b/magma/app.py @@ -2,7 +2,9 @@ from __future__ import absolute_import import os + from flask import Flask + from magma.home import home_page diff --git a/magma/home/__init__.py b/magma/home/__init__.py index 7253571..18e31a3 100644 --- a/magma/home/__init__.py +++ b/magma/home/__init__.py @@ -1,21 +1,22 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import tempfile -import shutil + import os -from zipfile import BadZipfile +import shutil +import tempfile from contextlib import closing -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from zipfile import BadZipfile -from flask import (Blueprint, flash, request, render_template, make_response, - session,) +from flask import (Blueprint, flash, make_response, render_template, request,) from werkzeug import secure_filename -from magma.upload import process, datasource from magma import UnsupportedFormat +from magma.upload import datasource, process + +try: + from StringIO import StringIO +except ImportError: + from io import StringIO home_page = Blueprint('home_page', __name__) diff --git a/magma/upload.py b/magma/upload.py index 2b1653b..b25ea16 100644 --- a/magma/upload.py +++ b/magma/upload.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from functools import reduce + import glob import os +from functools import reduce from zipfile import ZipFile -from osgeo import ogr, gdal from lxml import etree +from osgeo import gdal, ogr from magma import UnsupportedFormat diff --git a/magma/wsgi.py b/magma/wsgi.py index edef7a0..76e66e9 100644 --- a/magma/wsgi.py +++ b/magma/wsgi.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- from magma.app import create_app - application = create_app() diff --git a/tests/conftest.py b/tests/conftest.py index e0fed8a..0157342 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + import os import pytest diff --git a/tests/test_upload.py b/tests/test_upload.py index f0bdd5c..01d863d 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -1,15 +1,17 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import + from contextlib import closing + +import pytest + +from magma.upload import FGDC, GeoTIFF, Shapefile + try: from StringIO import StringIO except ImportError: from io import StringIO -import pytest - -from magma.upload import Shapefile, FGDC, GeoTIFF - @pytest.yield_fixture def shp(shapefile): diff --git a/tests/test_views.py b/tests/test_views.py index ff96876..adbe0b6 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import pytest +from webtest import Upload -from webtest import TestApp, Upload -from magma.app import create_app def test_can_load_index(testapp): r = testapp.get('/') assert r.status_code == 200 assert 'form' in r + def test_submit_valid_form(testapp): form = testapp.get('/').form form['data'] = Upload('tests/fixtures/SDE_DATA_BD_A8GNS_2003.zip') @@ -18,17 +17,20 @@ def test_submit_valid_form(testapp): res = form.submit() assert res.content_type == 'text/xml' + def test_submit_with_shapefile_without_metadata(testapp): form = testapp.get('/').form form['data'] = Upload('tests/fixtures/SDE_DATA_BD_A8GNS_2003.zip') res = form.submit() assert res.content_type == 'text/xml' + def test_submit_without_shapefile(testapp): form = testapp.get('/').form res = form.submit() assert 'A datafile is required to proceed' in res + def test_submit_with_invalid_shapefile(testapp): form = testapp.get('/').form form['data'] = Upload('tests/fixtures/fgdc.xml')