Ejemplo n.º 1
0
def upload_file():
    """ Upload ephemeris files via POST requests.

    Returns:
        On success: HTTP 200 if filename successfully
        On error:   HTTP error code associated with error.
    """
    if request.method == 'POST':
        # check if the post request has included the file
        if 'file' not in request.files:
            raise InputError("file", "file is missing from POST request")
        file = request.files['file']

        # check if filename included by browser
        if file.filename == '':
            raise InputError("filename", "empty filename")
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            local_filename = os.path.join(app.config['UPLOAD_DIRECTORY'],
                                          filename)
            file.save(local_filename)

            # add the ephemeris data to the DB
            sat_id = parse_ephemeris_file(local_filename)
            if sat_id < 0:
                raise InputError("contents", "malformed ephemeris file")
    return jsonify({'response': 'OK', 'status_code': 200})
Ejemplo n.º 2
0
 def setUpClass(cls):
     """Add default test responses."""
     super(TestSatellitesApi, cls).setUpClass()
     parse_ephemeris_file("ephemeris/Aqua_27424.e")
     parse_ephemeris_file("ephemeris/Radarsat2.e")
     parse_ephemeris_file("ephemeris/Rapideye2_33312.e")
     cls.response_data = '[{"id": 1, "name": "Aqua_27424"}, ' \
                          '{"id": 2, "name": "Radarsat2"}, ' \
                          '{"id": 3, "name": "Rapideye2_33312"}]'
Ejemplo n.º 3
0
 def setUpClass(cls):
     super(TestViewCone, cls).setUpClass()
     parse_ephemeris_file("ephemeris/Radarsat2.e")
     parse_ephemeris_file("ephemeris/Aqua_27424.e")
     parse_ephemeris_file("ephemeris/Rapideye2_33312.e")
     parse_ephemeris_file("ephemeris/TanSuo1_28220.e")
     parse_ephemeris_file("ephemeris/Terra_25994.e")
     parse_ephemeris_file("ephemeris/Worldview1_32060.e")
Ejemplo n.º 4
0
 def setUpClass(cls):
     """Add default test responses."""
     super(TestVisibilityApi, cls).setUpClass()
     parse_ephemeris_file("ephemeris/Radarsat2.e")
Ejemplo n.º 5
0
 def setUpClass(cls):
     super(TestVisibilityFinder, cls).setUpClass()
     parse_ephemeris_file("ephemeris/Radarsat2.e")