Exemple #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)
    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)
Exemple #3
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)
    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)
    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)
    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)
Exemple #7
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)
    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)
Exemple #9
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)
    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)
Exemple #11
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)
Exemple #12
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)