import os
from ast import literal_eval
import unittest
from webtest import TestApp

from ..run_webservices import app

test_app = TestApp(app)

class TestLatLonExtraction(unittest.TestCase):
    def test_successful_latlon_extract(self):
        expected_return = {
            "success": True,
            "lat_name": "lat",
            "lon_name": "lon",
            "lat_min": -45.759998321533203,
            "lat_max": -45.759998321533203,
            "lon_min": -24.639999389648438,
            "lon_max": 60.279998779296875
        }

        file_location = os.path.abspath('tests/example_data/lat_lon_time.nc')

        response = test_app.get('/lfme/list_latlon/' + file_location)

        self.assertDictEqual(expected_return, response.json)

    def test_successful_latlon_extract_jsonp(self):
        expected_return = {
            'lon_min': -24.639999389648438,
            'lat_max': -45.759998321533203,
            'success': True,
            'lon_name': 'lon',
            'lat_name': 'lat',
            'lon_max': 60.279998779296875,
            'lat_min': -45.759998321533203
        }

        file_location = os.path.abspath('tests/example_data/lat_lon_time.nc')

        response = test_app.get('/lfme/list_latlon/' + file_location + '?callback=test_callback')

        json = response.text

        # Strip out the callback functino and the json string from the response
        # and check for proper content.
        callback = json[:json.index('(')]
        json = json[json.index('(') + 1 : json.rindex(')')]
        json = literal_eval(json)

        self.assertDictEqual(expected_return, json)
        self.assertEqual(callback, "test_callback")

    def test_failure_latlon_extract(self):
        expected_return = {
            "success": False,
            "variables": ["invalid_lon", "invalid_time", "invalid_lat"]
        }

        file_location = os.path.abspath('tests/example_data/lat_lon_time_invalid.nc')

        response = test_app.get('/lfme/list_latlon/' + file_location)

        self.assertDictEqual(expected_return, response.json)

if __name__ == '__main__':
    unittest.main()

@@ -2076,16 +2076,783 @@
 .json)%0A%0A
+    def test_failure_latlon_extract_jsonp(self):%0A        expected_return = %7B%0A            %22success%22: False,%0A            %22variables%22: %5B%22invalid_lon%22, %22invalid_time%22, %22invalid_lat%22%5D%0A        %7D%0A%0A        file_location = os.path.abspath('tests/example_data/lat_lon_time_invalid.nc')%0A%0A        response = test_app.get('/lfme/list_latlon/' + file_location + '?callback=test_callback')%0A        json = response.text%0A%0A        # Strip out the callback functino and the json string from the response%0A        # and check for proper content.%0A        callback = json%5B:json.index('(')%5D%0A        json = json%5Bjson.index('(') + 1 : json.rindex(')')%5D%0A        json = literal_eval(json)%0A%0A        self.assertDictEqual(expected_return, json)%0A        self.assertEqual(callback, %22test_callback%22)%0A%0A
 if __nam

Add failure lfme/lis_latlon jsonp test