示例#1
0
    def test_arrays_route(self):

        content_type = 'application/json'

        # Create test data - two arrays
        array_CE = Array(array_code='CE')
        array_CE.array_name  = 'Endurance'
        array_CE.description = 'Coastal node array description...'
        array_CE.display_name= 'Coastal Endurance'
        array_CE.geo_location= 'POINT(-70 40)'
        db.session.add(array_CE)
        db.session.commit()

        array_NU = Array(array_code='RS')
        array_NU.array_name  = 'Regional Scale'
        array_NU.description = 'Coastal node array off Washington and Oregon coasts...'
        array_NU.display_name= 'Coastal Regional Scale'
        array_NU.geo_location= 'POINT(-70 45)'
        db.session.add(array_NU)
        db.session.commit()

        response = self.client.get(url_for('main.get_array',id='RS'), content_type=content_type)
        self.assertTrue(response.status_code == 200)

        # verify resulting fields for array are returned
        response_data = response.data
        self.assertTrue(self._check_array_fields_provided(response_data))

        #TODO Verify two arrays are returned
        response = self.client.get(url_for('main.get_arrays'), content_type=content_type)
        self.assertTrue(response.status_code == 200)
示例#2
0
    def test_update_array(self):

        content_type =  'application/json'
        headers = self.get_api_headers('admin', 'test')

        # Create array data
        array_CE = Array(array_code='CE')
        array_CE.array_name  = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name= 'Coastal Endurance'
        array_CE.geo_location= 'POINT(-70 40)'
        db.session.add(array_CE)
        db.session.commit()

        data = json.dumps({'description':'description update'})
        response = self.client.put(url_for('main.update_array', id=1), headers=headers, data=data)
        self.assertTrue(response.status_code == 200)

        # fetch array and compare contents returned with expected contents
        response = self.client.get(url_for('main.get_array',id='CE'), content_type=content_type)
        self.assertTrue(response.status_code == 200)

        # verify resulting fields for array are returned
        response_data = response.data
        self.assertTrue(self._check_array_fields_provided(response_data))

        # create dictionary from string;
        dict_data = json.loads(response_data)

        expected_data = {'array_code': 'CE', 'display_name':'Coastal Endurance',
                         'description': 'description update','array_name': 'Endurance', 'id': 1,
                         'geo_location': {u'type': u'Point', u'coordinates': [-70, 40]}, }
        self.assertTrue(dict_data == expected_data)
示例#3
0
    def test_delete_unknown_array(self):

        headers = self.get_api_headers('admin', 'test')
        # Create array, attempt to retrieve non-existent array using invalid id
        array_CE = Array(array_code='CE')
        array_CE.array_name  = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name= 'Coastal Endurance'
        array_CE.geo_location= 'POINT(-70 45)'
        db.session.add(array_CE)
        db.session.commit()

        response = self.client.delete(url_for('main.delete_array', id=5), headers=headers)
        self.assertEquals(response.status_code, 409)
示例#4
0
 def test_array(self):
     # Test the json in the object
     array = Array()
     self.assertTrue(
         array.to_json()
         == {
             "id": None,
             "array_code": None,
             "array_name": None,
             "description": None,
             "display_name": None,
             "geo_location": None,
         }
     )
示例#5
0
    def test_delete_array(self):

        headers = self.get_api_headers('admin', 'test')

        # Create array
        array_CE = Array(array_code='CE')
        array_CE.array_name  = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name= 'Coastal Endurance'
        array_CE.geo_location= 'POINT(-70 45)'
        db.session.add(array_CE)
        db.session.commit()

        response = self.client.delete(url_for('main.delete_array', id=1), headers=headers)
        self.assertEquals(response.status_code, 200)
示例#6
0
    def test_update_array_with_error(self):

        headers = self.get_api_headers('admin', 'test')

        # Create array with geo_locations == None
        array_CE = Array(array_code='CE')
        array_CE.array_name  = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name= 'Coastal Endurance'
        array_CE.geo_location= None
        db.session.add(array_CE)
        db.session.commit()

        data = json.dumps({'description':'update'})
        response = self.client.put(url_for('main.update_array', id=1), headers=headers, data=data)
        self.assertTrue(response.status_code == 409)
示例#7
0
def create_array():
    try:
        array_json = request.json
        if 'array_code' in array_json and 'display_name' in array_json and 'geo_location' in array_json:
            if array_json['array_code'] and array_json['display_name'] and array_json['geo_location']:
                array = Array.from_json(request.json)
                db.session.add(array)
                db.session.commit()
                return jsonify(array.to_json()), 201
            else:
                raise Exception('One or more values are empty: array_code, array_name or geo_location.')
        else:
            raise Exception('Missing array_code, array_name and-or geo_location field in request.')
    except Exception, err:
        return conflict('Insufficient data, or bad data format: %s' % err.message)
示例#8
0
    def test_array(self):
        #Create a sample data set.
        #TODO : This will be replaced by an endpoint
        array_code = Array(array_code='CE')

        db.session.add(array_code)
        db.session.commit()

        #test the api route for lists
        response = self.client.get(url_for('main.get_arrays'),
                                   content_type='application/json')

        self.assertTrue(response.status_code == 200)

        response = self.client.get(url_for('main.get_array', id='CE'),
                                   content_type='application/json')

        self.assertTrue(response.status_code == 200)
示例#9
0
    def test_array(self):
        '''
        general test for array api route for lists
        '''
        content_type = 'application/json'

        #Create a sample data set.
        array_code = Array(array_code='CE')
        db.session.add(array_code)
        db.session.commit()

        response = self.client.get(url_for('main.get_arrays'),
                                   content_type=content_type)
        self.assertTrue(response.status_code == 200)

        response = self.client.get(url_for('main.get_array', id='CE'),
                                   content_type=content_type)
        self.assertTrue(response.status_code == 200)
示例#10
0
    def test_delete_unknown_array(self):

        headers = self.get_api_headers('admin', 'test')
        # Create array, attempt to retrieve non-existent array using invalid id
        array_CE = Array(array_code='CE')
        array_CE.array_name = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name = 'Coastal Endurance'
        array_CE.geo_location = 'POINT(-70 45)'
        db.session.add(array_CE)
        db.session.commit()

        response = self.client.delete(url_for('main.delete_array', id=5),
                                      headers=headers)
        self.assertEquals(response.status_code, 409)
示例#11
0
    def test_delete_array(self):

        headers = self.get_api_headers('admin', 'test')

        # Create array
        array_CE = Array(array_code='CE')
        array_CE.array_name = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name = 'Coastal Endurance'
        array_CE.geo_location = 'POINT(-70 45)'
        db.session.add(array_CE)
        db.session.commit()

        response = self.client.delete(url_for('main.delete_array', id=1),
                                      headers=headers)
        self.assertEquals(response.status_code, 200)
示例#12
0
    def test_update_array_with_error(self):

        headers = self.get_api_headers('admin', 'test')

        # Create array with geo_locations == None
        array_CE = Array(array_code='CE')
        array_CE.array_name = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name = 'Coastal Endurance'
        array_CE.geo_location = None
        db.session.add(array_CE)
        db.session.commit()

        data = json.dumps({'description': 'update'})
        response = self.client.put(url_for('main.update_array', id=1),
                                   headers=headers,
                                   data=data)
        self.assertTrue(response.status_code == 409)
示例#13
0
    def test_update_array(self):

        content_type = 'application/json'
        headers = self.get_api_headers('admin', 'test')

        # Create array data
        array_CE = Array(array_code='CE')
        array_CE.array_name = 'Endurance'
        array_CE.description = 'description...'
        array_CE.display_name = 'Coastal Endurance'
        array_CE.geo_location = 'POINT(-70 40)'
        db.session.add(array_CE)
        db.session.commit()

        data = json.dumps({'description': 'description update'})
        response = self.client.put(url_for('main.update_array', id=1),
                                   headers=headers,
                                   data=data)
        self.assertTrue(response.status_code == 200)

        # fetch array and compare contents returned with expected contents
        response = self.client.get(url_for('main.get_array', id='CE'),
                                   content_type=content_type)
        self.assertTrue(response.status_code == 200)

        # verify resulting fields for array are returned
        response_data = response.data
        self.assertTrue(self._check_array_fields_provided(response_data))

        # create dictionary from string;
        dict_data = json.loads(response_data)

        expected_data = {
            'array_code': 'CE',
            'display_name': 'Coastal Endurance',
            'description': 'description update',
            'array_name': 'Endurance',
            'id': 1,
            'geo_location': {
                u'type': u'Point',
                u'coordinates': [-70, 40]
            },
        }
        self.assertTrue(dict_data == expected_data)
示例#14
0
    def test_arrays_route(self):

        content_type = 'application/json'

        # Create test data - two arrays
        array_CE = Array(array_code='CE')
        array_CE.array_name = 'Endurance'
        array_CE.description = 'Coastal node array description...'
        array_CE.display_name = 'Coastal Endurance'
        array_CE.geo_location = 'POINT(-70 40)'
        db.session.add(array_CE)
        db.session.commit()

        array_NU = Array(array_code='RS')
        array_NU.array_name = 'Regional Scale'
        array_NU.description = 'Coastal node array off Washington and Oregon coasts...'
        array_NU.display_name = 'Coastal Regional Scale'
        array_NU.geo_location = 'POINT(-70 45)'
        db.session.add(array_NU)
        db.session.commit()

        response = self.client.get(url_for('main.get_array', id='RS'),
                                   content_type=content_type)
        self.assertTrue(response.status_code == 200)

        # verify resulting fields for array are returned
        response_data = response.data
        self.assertTrue(self._check_array_fields_provided(response_data))

        #TODO Verify two arrays are returned
        response = self.client.get(url_for('main.get_arrays'),
                                   content_type=content_type)
        self.assertTrue(response.status_code == 200)
示例#15
0
    def test_update_array_with_empty_values(self):
        '''
        Create array with empty values: array_code, display_name
        Add test for empty geo_location
        '''
        headers = self.get_api_headers('admin', 'test')

        # Create array with array_code empty, expect failure
        array_ac = Array(array_code='')
        array_ac.array_name = 'Endurance'
        array_ac.description = 'description...'
        array_ac.display_name = 'Coastal Endurance'
        array_ac.geo_location = 'POINT(-70 40)'
        db.session.add(array_ac)
        db.session.commit()

        data = json.dumps({'description': 'update'})
        response = self.client.put(url_for('main.update_array', id=1),
                                   headers=headers,
                                   data=data)
        self.assertTrue(response.status_code == 409)

        # Create array with display_name empty, expect failure
        array_dn = Array(array_code='DN')
        array_dn.array_name = 'name'
        array_dn.description = 'description...'
        array_dn.display_name = ''
        array_dn.geo_location = 'POINT(-70 40)'
        db.session.add(array_dn)
        db.session.commit()

        data = json.dumps({'description': 'update'})
        response = self.client.put(url_for('main.update_array', id=1),
                                   headers=headers,
                                   data=data)
        self.assertTrue(response.status_code == 409)

        # Create valid array object, update with geo_location empty, expect failure
        array_gl = Array(array_code='GL')
        array_gl.array_name = 'name'
        array_gl.description = 'description...'
        array_gl.display_name = 'display name'
        array_gl.geo_location = 'POINT(-70 40)'
        db.session.add(array_gl)
        db.session.commit()

        data = json.dumps({'geo_location': ''})
        response = self.client.put(url_for('main.update_array', id=1),
                                   headers=headers,
                                   data=data)
        self.assertTrue(response.status_code == 409)
示例#16
0
 def test_array(self):
     #Test the json in the object
     array = Array()
     self.assertTrue(array.to_json() == {'id': None, 'array_code': None, \
     'array_name': None, 'description': None, 'display_name': None, \
     'geo_location': None})
示例#17
0
 def test_array(self):
     #Test the json in the object
     array = Array()
     self.assertTrue(array.to_json() == {'id': None, 'array_code': None, \
     'array_name': None, 'description': None, 'display_name': None, \
     'geo_location': None})
示例#18
0
    def test_update_array_with_empty_values(self):
        '''
        Create array with empty values: array_code, display_name
        Add test for empty geo_location
        '''
        headers = self.get_api_headers('admin', 'test')

        # Create array with array_code empty, expect failure
        array_ac = Array(array_code='')
        array_ac.array_name  = 'Endurance'
        array_ac.description = 'description...'
        array_ac.display_name= 'Coastal Endurance'
        array_ac.geo_location= 'POINT(-70 40)'
        db.session.add(array_ac)
        db.session.commit()

        data = json.dumps({'description':'update'})
        response = self.client.put(url_for('main.update_array', id=1), headers=headers, data=data)
        self.assertTrue(response.status_code == 409)

        # Create array with display_name empty, expect failure
        array_dn = Array(array_code='DN')
        array_dn.array_name  = 'name'
        array_dn.description = 'description...'
        array_dn.display_name= ''
        array_dn.geo_location= 'POINT(-70 40)'
        db.session.add(array_dn)
        db.session.commit()

        data = json.dumps({'description':'update'})
        response = self.client.put(url_for('main.update_array', id=1), headers=headers, data=data)
        self.assertTrue(response.status_code == 409)

        # Create valid array object, update with geo_location empty, expect failure
        array_gl = Array(array_code='GL')
        array_gl.array_name  = 'name'
        array_gl.description = 'description...'
        array_gl.display_name= 'display name'
        array_gl.geo_location= 'POINT(-70 40)'
        db.session.add(array_gl)
        db.session.commit()

        data = json.dumps({'geo_location':''})
        response = self.client.put(url_for('main.update_array', id=1), headers=headers, data=data)
        self.assertTrue(response.status_code == 409)