def test_load_dive_eid(self): output = StringIO() structure = StructureFactory.create(name='structure') filename = os.path.join(os.path.dirname(__file__), 'data', 'dive.shp') DiveFactory.create(name='name', eid='eid1', depth=10) call_command('loaddive', filename, name_field='name', depth_field='depth', eid_field='eid', practice_default='Practice', structure_default='structure', verbosity=2, stdout=output) self.assertIn('Dives will be linked to %s' % structure, output.getvalue()) self.assertIn('2 objects created.', output.getvalue()) value = Dive.objects.filter(name='name') self.assertEqual( 5, value[0].depth ) # The dive was updated because has the same eid (eid1) self.assertEqual('Practice', value[0].practice.name) self.assertEqual(value.count(), 1) self.assertEqual(Dive.objects.count(), 2) self.assertAlmostEqual(value[0].geom.x, -436345.704831, places=5) self.assertAlmostEqual(value[0].geom.y, 1176487.742917, places=5)
def test_load_dive_wrong_structure_default(self): output = StringIO() StructureFactory.create(name='structure') filename = os.path.join(os.path.dirname(__file__), 'data', 'dive.shp') DiveFactory.create(name='name', eid='eid1', depth=10) call_command('loaddive', filename, name_field='name', depth_field='depth', practice_default='Practice', structure_default='wrong_structure_default', verbosity=2, stdout=output) self.assertIn("Structure wrong_structure_default set in options doesn't exist", output.getvalue())
def setUp(self): self.model = Dive self.none = DiveFactory.create(geom="POINT EMPTY") self.basic = DiveFactory.create(geom='SRID=%s;LINESTRING(0 0, 10 0)' % settings.SRID) self.outside = DiveFactory.create( geom='SRID=%s;LINESTRING(0 10, 10 10)' % settings.SRID) self.filter = PythonPolygonFilter()
def test_levels_display(self): """Test if levels_display works""" l1 = LevelFactory.create() l2 = LevelFactory.create() d = DiveFactory() d.levels.set([l1, l2]) self.assertEquals(d.levels_display, "{0}, {1}".format(l1, l2))
def setUp(self): self.spot = DiveFactory.create(name="Empty") class DiveFilterSet(MapEntityFilterSet): class Meta: model = Dive fields = () self.filterset_class = DiveFilterSet
def setUpClass(cls): super(SyncRandoTestCase, cls).setUpClass() cls.practice_dive = PracticeFactory.create(order=0) cls.dive = DiveFactory.create(practice=cls.practice_dive, published=True, geom='SRID=2154;POINT(700001 6600001)') cls.attachment_dive = AttachmentFactory.create(content_object=cls.dive, attachment_file=get_dummy_uploaded_image()) cls.poi_dive = POIFactory.create(name="dive_poi", published=True) AttachmentFactory.create(content_object=cls.poi_dive, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=cls.poi_dive, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=cls.poi_dive, attachment_file=get_dummy_uploaded_file()) cls.touristic_content = TouristicContentFactory( geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True) cls.touristic_event = TouristicEventFactory( geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True) cls.attachment_touristic_content = AttachmentFactory.create(content_object=cls.touristic_content, attachment_file=get_dummy_uploaded_image()) cls.attachment_touristic_event = AttachmentFactory.create(content_object=cls.touristic_event, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=cls.touristic_content, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=cls.touristic_event, attachment_file=get_dummy_uploaded_image()) cls.source_a = RecordSourceFactory() cls.source_b = RecordSourceFactory() cls.portal_a = TargetPortalFactory() cls.portal_b = TargetPortalFactory() cls.dive_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True, geom='SRID=2154;POINT(700002 6600002)', portals=(cls.portal_a,), sources=(cls.source_a,)) cls.dive_other_portal_source = DiveFactory.create(practice=cls.practice_dive, published=True, geom='SRID=2154;POINT(700002 6600002)', portals=(cls.portal_b,), sources=(cls.source_b,))
def setUp(self): self.point1 = DiveFactory.create() self.point1.themes.add(ThemeFactory.create(label="Tag1")) self.point1.themes.add(ThemeFactory.create(label="Tag2")) self.line1 = DiveFactory.create(geom='SRID=%s;LINESTRING(0 0, 10 0)' % settings.SRID) self.multiline = DiveFactory.create( geom='SRID=%s;MULTILINESTRING((10 10, 20 20, 10 40),' '(40 40, 30 30, 40 20, 30 10))' % settings.SRID) self.multipoint = DiveFactory.create( geom='SRID=%s;MULTIPOINT((1 1), (2 2))' % settings.SRID) self.polygon = DiveFactory.create( geom='SRID=%s;POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))' % settings.SRID) self.multipolygon = DiveFactory.create( geom='SRID=%s;MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)),' '((2 2, 2 3, 3 3, 3 2, 2 2)))' % settings.SRID) self.serializer = ZipShapeSerializer() response = HttpResponse() self.serializer.serialize(Dive.objects.all(), stream=response, fields=['id', 'name'], delete=False)
def test_prefixed_category_id_with_practice(self): practice = PracticeFactory.create(name="special") dive = DiveFactory.create() dive.practice = practice dive.save() self.assertEqual(dive.prefixed_category_id, "D%s" % practice.id)
def test_rando_url_split_by_category(self): practice = PracticeFactory.create(name="special") dive = DiveFactory.create() dive.practice = practice dive.save() self.assertEqual(dive.rando_url, "special/dive/")
def setUpClass(cls): super(DiveModelTest, cls).setUpClass() cls.dive = DiveFactory.create(practice=None)
def setUp(self): self.source_a = RecordSourceFactory() self.source_b = RecordSourceFactory() self.portal_a = TargetPortalFactory() self.portal_b = TargetPortalFactory() information_desks = InformationDeskFactory.create() self.practice_trek = PracticeTrekFactory.create(order=1) self.practice_trek_first = PracticeTrekFactory.create(order=0) self.trek_1 = TrekWithPublishedPOIsFactory.create(practice=self.practice_trek, sources=(self.source_a, ), portals=(self.portal_b,), published=True) self.trek_1.information_desks.add(information_desks) self.attachment_1 = AttachmentFactory.create(content_object=self.trek_1, attachment_file=get_dummy_uploaded_image()) self.trek_2 = TrekFactory.create(sources=(self.source_b,), published=True) self.trek_3 = TrekFactory.create(portals=(self.portal_b, self.portal_a), published=True) self.trek_4 = TrekFactory.create(practice=self.practice_trek, portals=(self.portal_a,), published=True) self.trek_5 = TrekFactory.create(practice=self.practice_trek_first, portals=(self.portal_a,), published=True, name="other") self.practice_dive = PracticeDiveFactory.create(order=0) self.dive_1 = DiveFactory.create(practice=self.practice_dive, sources=(self.source_a,), portals=(self.portal_b,), published=True, geom='SRID=2154;POINT(700001 6600001)') self.attachment_dive = AttachmentFactory.create(content_object=self.dive_1, attachment_file=get_dummy_uploaded_image()) self.dive_2 = DiveFactory.create(sources=(self.source_b,), published=True, geom='SRID=2154;LINESTRING (700000 6600000, 700100 6600100)') self.dive_3 = DiveFactory.create(portals=(self.portal_b, self.portal_a), published=True, geom='POLYGON((700000 6600000, 700000 6600100, ' '700100 6600100, 700100 6600000, 700000 6600000))') self.dive_4 = DiveFactory.create(practice=self.practice_dive, portals=(self.portal_a,), published=True) self.poi_1 = trek_models.POI.objects.first() self.poi_dive = POIFactory.create(name="dive_poi", published=True) self.attachment_poi_image_1 = AttachmentFactory.create(content_object=self.poi_1, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=self.poi_dive, attachment_file=get_dummy_uploaded_image()) self.attachment_poi_image_2 = AttachmentFactory.create(content_object=self.poi_1, attachment_file=get_dummy_uploaded_image()) AttachmentFactory.create(content_object=self.poi_dive, attachment_file=get_dummy_uploaded_file()) self.attachment_poi_file = AttachmentFactory.create(content_object=self.poi_1, attachment_file=get_dummy_uploaded_file()) if settings.TREKKING_TOPOLOGY_ENABLED: infrastructure = InfrastructureFactory.create(no_path=True, name="INFRA_1") infrastructure.add_path(self.trek_1.paths.first(), start=0, end=0) signage = SignageFactory.create(no_path=True, name="SIGNA_1") signage.add_path(self.trek_1.paths.first(), start=0, end=0) else: InfrastructureFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="INFRA_1") SignageFactory.create(geom='SRID=2154;POINT(700000 6600000)', name="SIGNA_1") area = SensitiveAreaFactory.create(published=True) area.species.practices.add(SportPracticeFactory.create(name='Terrestre')) area.save() self.touristic_content = TouristicContentFactory( geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True) self.touristic_event = TouristicEventFactory( geom='SRID=%s;POINT(700001 6600001)' % settings.SRID, published=True) self.attachment_touristic_content = AttachmentFactory.create(content_object=self.touristic_content, attachment_file=get_dummy_uploaded_image()) self.attachment_touristic_event = AttachmentFactory.create(content_object=self.touristic_event, attachment_file=get_dummy_uploaded_image())
def setUp(self): self.point = DiveFactory.create(name="Test") self.point.themes.add(ThemeFactory.create(label="Tag1")) self.point.themes.add(ThemeFactory.create(label="Tag2")) self.serializer = CSVSerializer() self.stream = StringIO()