# -*- coding: utf-8 -*-
from . import FixtureTest


class MinZoomFromNETest(FixtureTest):

    def setUp(self):
        import dsl

        super(MinZoomFromNETest, self).setUp()

        self.lon, self.lat = (-3.2765753, 54.7023545)

        self.generate_fixtures(
            # https://www.openstreetmap.org/node/838090640
            dsl.point(838090640, (self.lon, self.lat), {
                'name': u'United Kingdom',
                'place': u'country',
                'population': u'61792000',
                'source': u'openstreetmap.org',
                'wikidata': u'Q145',
                'wikipedia': u'de:United Kingdom',  # LOL, de:
                # NOTE: these aren't in the data from OSM, but are joined at
                # database query time from the Natural Earth data.
                '__ne_min_zoom': 1.7,
                '__ne_max_zoom': 6.7,
            }),
        )

    def test_uk_should_show_up_zooms_1_to_6(self):
        from tilequeue.tile import deg2num
        # should show up in zooms within the range 1-6

        for zoom in xrange(1, 6):
            x, y = deg2num(self.lat, self.lon, zoom)
            self.assert_has_feature(
                zoom, x, y, 'places', {
                    'id': 838090640,
                    'min_zoom': 1.7,
                    'max_zoom': 6.7,
                })

    def test_uk_should_not_show_up_zoom_0(self):
        # shouldn't be in the zoom 0 tile because min_zoom >= 1
        self.assert_no_matching_feature(
            0, 0, 0, 'places', {'id': 838090640})

    def test_uk_should_not_show_up_zoom_7(self):
        # shouldn't be in the zoom 0 tile because max_zoom < 7
        from tilequeue.tile import deg2num

        zoom = 7
        x, y = deg2num(self.lat, self.lon, zoom)
        self.assert_no_matching_feature(
            zoom, x, y, 'places', {'id': 838090640})

Add test for NE data min/max zoom join to places.
Add test for NE data min/max zoom join to places.
