# -*- coding: utf-8 -*-
from django.test import TestCase
from django.conf import settings

from geotrek.sensitivity.factories import SensitiveAreaFactory, SpeciesFactory


class SensitiveAreaModelTest(TestCase):

    def test_specific_radius(self):
        specie = SpeciesFactory.create(radius=50)
        sensitive_area = SensitiveAreaFactory.create(species=specie)
        self.assertEqual(sensitive_area.radius, 50)

    def test_no_radius(self):
        sensitive_area = SensitiveAreaFactory.create()
        self.assertEqual(sensitive_area.radius, settings.SENSITIVITY_DEFAULT_RADIUS)

    def test_get_lang_published(self):
        sensitive_area = SensitiveAreaFactory.create()
        self.assertEqual(sensitive_area.published_langs, list(settings.MODELTRANSLATION_LANGUAGES))

    def test_get_lang_not_published(self):
        sensitive_area = SensitiveAreaFactory.create()
        sensitive_area.published = False
        self.assertEqual(sensitive_area.published_langs, [])

    def test_get_extent(self):
        sensitive_area = SensitiveAreaFactory.create(
            geom='POLYGON((700000 6600000, 700000 6600100, 700100 6600100, 700100 6600000, 700000 6600000))')
        self.assertEqual(sensitive_area.extent,
                         (2.9999999999999996, 46.499999992565094, 3.001303976720215, 46.50090044978422))

    def test_get_kml(self):
        sensitive_area = SensitiveAreaFactory.create()
        self.assertIn('<coordinates>3.0,46.5,0.0 3.0,46.5000270135,0.0 3.00003911867,46.5000270135,0.0 3.00003911866,'
                      '46.5,0.0 3.0,46.5,0.0</coordinates>', sensitive_area.kml())

    def test_get_kml_point(self):
        sensitive_area = SensitiveAreaFactory.create(geom='POINT(700000 6600000)')
        # Create a buffer around the point with 100 (settings.SENSITIVITY_DEFAULT_RADIUS)
        self.assertIn('<coordinates>3.00130395519,46.4999999926,0.0 3.0012046899,46.4996554064,0.0 3.00092202479,'
                      '46.4993632821,0.0 3.00049899443,46.4991680917,0.0 3.0,46.4990995501,0.0 2.99950100557,'
                      '46.4991680917,0.0 2.99907797521,46.4993632821,0.0 2.9987953101,46.4996554064,0.0 2.99869604481,'
                      '46.4999999926,0.0 2.99879529488,46.5003445809,0.0 2.99907795368,46.5006367104,0.0 2.99950099034,'
                      '46.500831906,0.0 3.0,46.5009004498,0.0 3.00049900966,46.500831906,0.0 3.00092204632,'
                      '46.5006367104,0.0 3.00120470512,46.5003445809,0.0 3.00130395519,46.4999999926,0.0</coordinates>',
                      sensitive_area.kml())

    def test_is_public(self):
        sensitive_area = SensitiveAreaFactory.create()
        self.assertTrue(sensitive_area.is_public())
        sensitive_area.published = False
        self.assertFalse(sensitive_area.is_public())

@@ -1254,26 +1254,11 @@
    (
-2.9999999999999996
+3.0
 , 46
@@ -1274,11 +1274,10 @@
 2565
-094
+11
 , 3.
@@ -1291,16 +1291,17 @@
 76720215
+4
 , 46.500
@@ -1311,16 +1311,17 @@
 44978422
+6
 ))%0A%0A    

Fix geometry