コード例 #1
0
 def test_add_or_update_checks_for_uri_clashes_before_adding(self):
     self._mock_mongo.pois.find_one.return_value = {
         '_id': 'abcdef', 'sources': [Source(url='http://www.example.com', version=1, attribution='OSM')]
     }
     poi = PointOfInterest(slug='test:test')
     self._pois.add_or_update(poi)
     poi_dict = poi._asdict()
     poi_dict.update({'_id': 'abcdef'})
     self.assertFalse(self._mock_mongo.db.pois.insert.called)
     self._mock_mongo.pois.update.assert_called_once_with({'slug': 'test:test'}, poi_dict)
コード例 #2
0
    def search_name(self, search_terms):
        results = self._search.search(
            {
                'query': {
                    'bool': {
                        'should': [
                            {'match': {'names': search_terms}},
                            {'term': {'identifiers': search_terms}}
                        ]
                    }
                }
            },
            index=self._instance_name,
            doc_type='poi'
        )
        slugs = [result['_id'] for result in results['hits']['hits']]
        if len(slugs) > 0:
            poi_dicts = {
                data['slug']: PointOfInterest.from_dict(data)
                    for data in self._collection.find({'$or': [{'slug': slug} for slug in slugs]})
            }

            return [poi_dicts[slug] for slug in slugs]
        else:
            return []
コード例 #3
0
    def test_geojson_is_deserialised(self):
        point = Point(-2.14, 53.28)

        poi = PointOfInterest.from_dict(
            {"geography": self._point_to_geojson(point), "location": self._point_to_geojson(point)}
        )

        self.assertEquals(point.wkt, poi.location.wkt)
        self.assertEquals(point.wkt, poi.geography.wkt)
コード例 #4
0
    def _build_point_of_interest(self, elem, atco_code, stop_type):
        poi = PointOfInterest()
        poi.slug = 'atco:' + atco_code
        poi.categories.append(self._get_category(stop_type, atco_code))

        poi.identifiers.add(Identifier(namespace=ATCO_NAMESPACE, value=atco_code))
        self._add_identifier(poi, elem, CRS_NAMESPACE, self._CRS_CODE_XPATH)
        self._add_identifier(poi, elem, TIPLOC_NAMESPACE, self._TIPLOC_CODE_XPATH)

        self._add_location(poi, elem)

        poi.sources.append(Source(
            url=self._source_url + '/' + self._source_file,
            version=elem.attrib.get('RevisionNumber', '0'),
            attribution=self._ATTRIBUTION
        ))

        return poi
コード例 #5
0
    def test_add_indexes(self):
        poi = PointOfInterest()
        poi.slug = 'osm:N12345'
        poi.names = [LocalisedName(name='Test', lang='en')]
        poi.descriptions = [LocalisedName(name='Descriptions', lang='en')]
        poi.geography = Point(-1.6, 54.0)
        poi.identifiers = [Identifier(namespace='foo', value='bar')]

        self._pois.add_or_update(poi)
コード例 #6
0
 def test_geography_is_serialised_to_geojson(self):
     poi = PointOfInterest(geography=Point(-2.14, 53.28))
     self.assertEquals(self._point_to_geojson(poi.location), poi._asdict().get("location"))
     self.assertEquals(self._point_to_geojson(poi.geography), poi._asdict().get("geography"))
コード例 #7
0
 def test_add_adds_to_database(self):
     poi = PointOfInterest()
     self._pois.add_or_update(poi)
     self._mock_mongo.pois.insert.assert_called_once_with(poi._asdict())
コード例 #8
0
 def select_by_slug(self, slug):
     poi_dict = self._collection.find_one({'slug': slug})
     return PointOfInterest.from_dict(poi_dict) if poi_dict else None