def setup(self):
        """Prepare each test"""
        # Setup a dummy datastore.
        self.dataset = package_create(TestViewCreated.context, {'name': 'map-test-dataset'})
        self.resource = datastore_create(TestViewCreated.context, {
            'resource': {
                'package_id': self.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'latitude', 'type': 'double precision'},
                {'id': 'longitude', 'type': 'double precision'},
                {'id': 'long2', 'type': 'double precision'},
                {'id': 'text', 'type': 'text'},
                {'id': 'big', 'type': 'double precision'},
            ],
            'primary_key': 'id'
        })

        # Add some data.
        datastore_upsert(TestViewCreated.context, {
            'resource_id': self.resource['resource_id'],
            'method': 'upsert',
            'records': [{
                            'id': 1,
                            'latitude': -11,
                            'longitude': -15,
                            'long2': 22,
                            'text': 'hello',
                            'big': '-1000'
                        }, {
                            'id': 2,
                            'latitude': 23,
                            'longitude': 48,
                            'long2': -12,
                            'text': 'hello',
                            'big': '199'
                        }]
        })

        # Base dict for view creation/update methods
        self.base_data_dict = {
            'description': u'',
            'title': u'test',
            'resource_id': self.resource['resource_id'],
            'plot_marker_color': u'#EE0000',
            'enable_plot_map': u'True',
            'overlapping_records_view': u'',
            'longitude_field': u'longitude',
            'heat_intensity': u'0.1',
            'view_type': u'tiledmap',
            'utf_grid_title': u'_id',
            'plot_marker_line_color': u'#FFFFFF',
            'latitude_field': u'latitude',
            'enable_utf_grid': u'True',
            'grid_base_color': u'#F02323'
        }
    def setup(self):
        """Prepare each test"""
        # Setup a dummy datastore.
        self.dataset = package_create(TestMapActions.context, {'name': 'map-test-dataset'})
        self.resource = datastore_create(TestMapActions.context, {
            'resource': {
                'package_id': self.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'latitude', 'type': 'double precision'},
                {'id': 'longitude', 'type': 'double precision'},
                {'id': 'skip', 'type': 'text'},
                {'id': 'lat2', 'type': 'double precision'},
                {'id': 'long2', 'type': 'double precision'}
            ],
            'primary_key': 'id'
        })

        # Add some data.
        datastore_upsert(TestMapActions.context, {
            'resource_id': self.resource['resource_id'],
            'method': 'upsert',
            'records': [{
                            'id': 1,
                            'latitude': -11,
                            'longitude': -15,
                            'skip': 'no',
                            'lat2': 1,
                            'long2': 1
                        }, {
                            'id': 2,
                            'latitude': 23,
                            'longitude': 48,
                            'skip': 'no',
                            'lat2': 2,
                            'long2': 2
                        }, {
                            'id': 3,
                            'latitude': None,
                            'longitude': None,
                            'skip': 'yes',
                            'lat2': None,
                            'long2': None
                        }, {
                            'id': 4,
                            'latitude': 1234,
                            'longitude': 1234,
                            'skip': 'yes',
                            'lat2': None,
                            'long2': None
                        }]
        })
    def setup_class(cls, mock_flash):
        """Prepare the test"""
        # We need datastore for these tests.
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")

        # Setup a test app
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        ctd.CreateTestData.create()
        cls.context = {'model': ckan.model,
                       'session': ckan.model.Session,
                       'user': ckan.model.User.get('testsysadmin').name}

        # Load plugins
        p.load('tiledmap')
        p.load('datastore')

        # Set windshaft host/port as these settings do not have a default.
        # TODO: Test that calls fail if not set
        tm_config.update({
            'tiledmap.windshaft.host': '127.0.0.1',
            'tiledmap.windshaft.port': '4000'
        })

        # Copy tiledmap settings
        cls.config = dict(tm_config.items())

        # Setup a dummy datastore.
        cls.dataset = package_create(cls.context, {'name': 'map-test-dataset'})
        cls.resource = datastore_create(cls.context, {
            'resource': {
                'package_id': cls.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'latitude', 'type': 'numeric'},
                {'id': 'longitude', 'type': 'numeric'},
                {'id': 'some_field_1', 'type': 'text'},
                {'id': 'some_field_2', 'type': 'text'}
            ],
            'primary_key': 'id'
        })

        # Add some data. We add 4 records such that:
        # - The first three records have 'some_field_1' set to 'hello' ;
        # - The third record does not have a geom ;
        # - The fourth record has a geom, but 'some_field_1' is set to something elese.
        datastore_upsert(cls.context, {
            'resource_id': cls.resource['resource_id'],
            'method': 'upsert',
            'records': [{
                'id': '1',
                'latitude': -15,
                'longitude': -11,
                'some_field_1': 'hello',
                'some_field_2': 'world'
            }, {
                'id': 2,
                'latitude': 48,
                'longitude': 23,
                'some_field_1': 'hello',
                'some_field_2': 'again'
            }, {
                'id': 3,
                'latitude': None,
                'longitude': None,
                'some_field_1': 'hello',
                'some_field_2': 'hello'
            }, {
                'id': 4,
                'latitude': 80,
                'longitude': 80,
                'some_field_1': 'all your bases',
                'some_field_2': 'are belong to us'
            }]
        })

        # Create a tiledmap resource view. This process itself is fully tested in test_view_create.py.
        # This will also generate the geometry column - that part of the process is fully tested in test_actions
        data_dict = {
            'description': u'',
            'title': u'test',
            'resource_id': cls.resource['resource_id'],
            'plot_marker_color': u'#EE0000',
            'enable_plot_map': u'True',
            'overlapping_records_view': u'',
            'longitude_field': u'longitude',
            'heat_intensity': u'0.1',
            'view_type': u'tiledmap',
            'utf_grid_title': u'_id',
            'plot_marker_line_color': u'#FFFFFF',
            'latitude_field': u'latitude',
            'enable_utf_grid': u'True',
            'utf_grid_fields' : ['some_field_1', 'some_field_2'],
            'grid_base_color': u'#F02323',
            'enable_heat_map': u'True',
            'enable_grid_map': u'True'
        }

        resource_view_create = p.toolkit.get_action('resource_view_create')
        cls.resource_view = resource_view_create(cls.context, data_dict)

        # Create a resource that does not have spatial fields
        cls.non_spatial_resource = datastore_create(cls.context, {
            'resource': {
                'package_id': cls.dataset['id']
            },
            'fields': [
                {'id': 'id', 'type': 'integer'},
                {'id': 'some_field', 'type': 'text'}
            ],
            'primary_key': 'id'
        })