Forráskód Böngészése

Fix tests and add latitude limit warning

Stephen Dade 5 éve
szülő
commit
53f09bd02f
4 módosított fájl, 61 hozzáadás és 26 törlés
  1. 15 5
      app.py
  2. 33 20
      app_test.py
  3. 8 0
      templates/generate.html
  4. 5 1
      templates/index.html

+ 15 - 5
app.py

@@ -96,6 +96,9 @@ def generate():
         # UUID for this terrain generation
         uuidkey = str(uuid.uuid1())
 
+        # Flag for if user wanted a tile outside +-60deg latitude
+        outsideLat = None
+
         # get a list of files required to cover area
         filelist = []
         done = set()
@@ -108,11 +111,18 @@ def generate():
                 if tag in done:
                     continue
                 done.add(tag)
-                #create_degree(downloader, lat_int, lon_int, folderthis, spacing)
-                filelist.append(os.path.join(os.getcwd(), "processedTerrain", getDatFile(lat_int, lon_int)))
+                # make sure tile is inside the 60deg latitude limit
+                if (abs(lat_int) < 60):
+                    filelist.append(os.path.join(os.getcwd(), "processedTerrain", getDatFile(lat_int, lon_int)))
+                else:
+                    outsideLat = True
+
+        # make sure tile is inside the 60deg latitude limit
+        if (abs(lat_int) < 60):
+            filelist.append(os.path.join(os.getcwd(), "processedTerrain", getDatFile(lat_int, lon_int)))
+        else:
+            outsideLat = True
 
-        #create_degree(downloader, lat, lon, folderthis, spacing)
-        filelist.append(os.path.join(os.getcwd(), "processedTerrain", getDatFile(lat_int, lon_int)))
         # remove duplicates
         filelist = list(dict.fromkeys(filelist))
         print(filelist)
@@ -123,7 +133,7 @@ def generate():
         
         if success:
             print("Generated " + "/terrain/" + uuidkey + ".zip")
-            return render_template('generate.html', urlkey="/terrain/" + uuidkey + ".zip", uuidkey=uuidkey)
+            return render_template('generate.html', urlkey="/terrain/" + uuidkey + ".zip", uuidkey=uuidkey, outsideLat=outsideLat)
         else:
             print("Failed " + "/terrain/" + uuidkey + ".zip")
             return render_template('generate.html', error="Cannot generate terrain", uuidkey=uuidkey)

+ 33 - 20
app_test.py

@@ -17,22 +17,18 @@ def client():
     app.config['TESTING'] = True
 
     # create fake pre-gen terrain files if they don't exist
-    preGen = ['S35E149.DAT', 'S35E147.DAT', 'S30E137.DAT', 'S31E136.DAT', 'S31E137.DAT', 'S31E138.DAT',
-              'S30E136.DAT', 'S30E137.DAT', 'S30E138.DAT', 'S29E136.DAT', 'S29E137.DAT', 'S29E138.DAT']
-    for fileSingle in preGen:
-        full = os.path.join(os.getcwd(), "processedTerrain", fileSingle)
-        print(full)
-        if not os.path.exists(full):
-            print("Making fake file: " + full)
-            createFile(full, 1024 * 1024)
+    #preGen = ['S35E149.DAT', 'S35E147.DAT', 'S30E137.DAT', 'S31E136.DAT', 'S31E137.DAT', 'S31E138.DAT',
+    #          'S30E136.DAT', 'S30E137.DAT', 'S30E138.DAT', 'S29E136.DAT', 'S29E137.DAT', 'S29E138.DAT']
+    #for fileSingle in preGen:
+    #    full = os.path.join(os.getcwd(), "processedTerrain", fileSingle)
+    #    print(full)
+    #    if not os.path.exists(full):
+    #        print("Making fake file: " + full)
+    #        createFile(full, 1024 * 1024)
 
     with app.test_client() as client:
-        #with app.app_context():
-        #    app.init_db()
         yield client
 
-    #shutdown()
-
 def test_homepage(client):
     """Test that the homepage can be generated"""
 
@@ -98,19 +94,38 @@ def test_simplegen(client):
 
     assert b'<title>AP Terrain Generator</title>' in rv.data
     assert b'Error' not in rv.data
+    assert b'Tiles outside of +60 to -60 latitude were requested' not in rv.data
     assert b'download="terrain.zip"' in rv.data
 
     uuidkey = (rv.data.split(b"footer")[1][1:-2]).decode("utf-8") 
     assert uuidkey != ""
 
-    #wait for generator to complete, up to 1 second
-    time.sleep(1)
-
     #file should be ready for download and around 2MB in size
     rdown = client.get('/terrain/' + uuidkey + ".zip", follow_redirects=True)
+    assert b'404 Not Found' not in rdown.data
     assert len(rdown.data) > (1*1024*1024)
 
-    #shutdown()
+def test_simplegenoutside(client):
+    """Test that a small piece of terrain can be generated with partial outside +-60latitude"""
+
+    rv = client.post('/generate', data=dict(
+        lat='-58.363261',
+        long='149.165230',
+        radius='200',
+    ), follow_redirects=True)
+
+    assert b'<title>AP Terrain Generator</title>' in rv.data
+    assert b'Error' not in rv.data
+    assert b'Tiles outside of +60 to -60 latitude were requested' in rv.data
+    assert b'download="terrain.zip"' in rv.data
+
+    uuidkey = (rv.data.split(b"footer")[1][1:-2]).decode("utf-8") 
+    assert uuidkey != ""
+
+    #file should be ready for download and around 2MB in size
+    rdown = client.get('/terrain/' + uuidkey + ".zip", follow_redirects=True)
+    assert b'404 Not Found' not in rdown.data
+    assert len(rdown.data) > (0.25*1024*1024)
 
 def test_multigen(client):
     """Test that a a few small piece of terrains can be generated"""
@@ -146,12 +161,10 @@ def test_multigen(client):
         assert uuidkey != ""
         allUuid.append(uuidkey)
 
-    #wait for generator to complete, up to 1 second
-    time.sleep(1)
-
-    #files should be ready for download and around 2MB in size
+    #files should be ready for download and around 0.7MB in size
     for uukey in allUuid:
         rdown = client.get('/terrain/' + uukey + ".zip", follow_redirects=True)
+        assert b'404 Not Found' not in rdown.data
         assert len(rdown.data) > (0.7*1024*1024)
 
 

+ 8 - 0
templates/generate.html

@@ -9,4 +9,12 @@
   <p>This should be unzipped to the autopilot's SD card, within in the "terrain" folder.</p>
 {% endif %}
 
+{% if outsideLat %}
+  <p>Tiles outside of +60 to -60 latitude were requested, which are not covered by the terrain database. These tiles are not included in the generated zip file.</p>
+{% else %}
+<p></p>
+{% endif %}
+
+<br />
+
 <footer>{{uuidkey}}</footer>

+ 5 - 1
templates/index.html

@@ -1,7 +1,9 @@
 <!doctype html>
 <title>AP Terrain Generator</title>
 <h1>AP Terrain Generator</h1>
-<p>Use this to generate terrain to put on your SD card</p>
+<p>Use this to generate terrain to put on your SD card.</p>
+
+<p>Multiple generated files can be combined on the SD card.</p>
 
 <p>Compatible with Ardupilot Plane 4.0.6+ and Copter 4.0.4+</p>
  
@@ -17,4 +19,6 @@
   <input type="submit" value="Submit" method="post">
  </form> 
 
+<br />
+
 <footer>Created by Stephen Dade, <a href=https://github.com/stephendade/terraingen>Source Code<a>.</footer>