def test_make_labels(config):
    doc = {
        'id': 'xxxx',
        '_id': 'yyyy',
        'type': 'street',
        'name': 'rue des Lilas',
        'city': 'Paris',
        'postcode': '75010',
        'lat': '49.32545',
        'lon': '4.2565',
        'housenumbers': {
            '1 bis': {
                'lat': '48.325451',
                'lon': '2.25651'
            }
        }
    }
    process_documents(json.dumps(doc))
    result = Result(get_document('d|yyyy'))
    result.housenumber = '1 bis'  # Simulate match_housenumber
    make_labels(None, result)
    assert result.labels == [
        '1 bis rue des Lilas 75010 Paris', 'rue des Lilas 75010 Paris',
        '1 bis rue des Lilas 75010', 'rue des Lilas 75010',
        '1 bis rue des Lilas Paris', 'rue des Lilas Paris',
        '1 bis rue des Lilas', 'rue des Lilas'
    ]
Example #2
0
 def on_get(self, req, resp, doc_id, **kwargs):
     try:
         result = Result.from_id(doc_id)
     except ValueError:
         raise falcon.HTTPNotFound()
     else:
         self.json(req, resp, result.format())
Example #3
0
File: http.py Project: xlqian/addok
 def get(self, doc_id):
     try:
         result = Result.from_id(doc_id)
     except ValueError:
         raise NotFound()
     else:
         return self.json(result.to_geojson())
Example #4
0
 def on_get(self, req, resp, doc_id, **kwargs):
     try:
         result = Result.from_id(doc_id)
     except ValueError:
         raise falcon.HTTPNotFound()
     else:
         self.json(req, resp, result.format())
Example #5
0
def test_make_municipality_labels(config):
    doc = {
        'id': 'xxxx',
        '_id': 'yyyy',
        'type': 'municipality',
        'name': 'Lille',
        'city': 'Lille',
        'postcode': '59000',
        'lat': '49.32545',
        'lon': '4.2565',
    }
    process_documents(json.dumps(doc))
    result = Result(get_document('d|yyyy'))
    make_labels(None, result)
    assert result.labels == ['Lille 59000', '59000 Lille', 'Lille']
Example #6
0
def follow_successor(helper, result):
    if result.successors:
        id = result.successors
        try:
            successor = Result.from_id(id)
        except ValueError:
            # https://github.com/addok/addok-geozones/issues/1
            print('Unable to find successor {0.successors} from id '
                  '{0._id}'.format(result))
            return
        # Sometimes name does not change (merge).
        if successor.name != result.name:
            result.labels = ['{} (anciennement {})'.format(
                             successor.name, result.name)]
            result._cache = {}
            result._doc = successor._doc
Example #7
0
def test_from_id(factory):
    factory(name="avenue de Paris", type="street", id="123")
    doc = Result.from_id("123")
    assert doc.id == "123"
Example #8
0
def test_from_id(factory):
    doc = factory(name="avenue de Paris", type="street", id="123")
    result = Result.from_id(doc['_id'])
    assert result.id == "123"
Example #9
0
def test_make_labels_merged_cities(config):
    doc = {
        "_id":
        "53543a313139353538390000",
        "id":
        "53543a313139353538390000",
        "type":
        "street",
        "postcode":
        "49120",
        "hexacleStreet":
        "492812226P",
        "lat":
        "47.1469",
        "lon":
        "-0.75745",
        "context":
        "49, Maine-et-Loire, Pays de la Loire",
        "importance":
        1,
        "userLabel":
        "RUE PIERRE LEPOUREAU",
        "name":
        "RUE PIERRE LEPOUREAU",
        "housenumbers": {
            "2 BIS": {
                "hexacleNumber": "49281222UE",
                "lat": "47.1504",
                "lon": "-0.757414"
            }
        },
        "cityAfnorLabel":
        "CHEMILLE EN ANJOU",
        "userCityLabel":
        "ST GEORGES DES GARDES (CHEMILLE EN ANJOU)",
        "cityAliasAfnorLabel":
        "ST GEORGES DES GARDES",
        "city": [
            "ST GEORGES DES GARDES (CHEMILLE EN ANJOU)",
            "ST GEORGES DES GARDES", "CHEMILLE EN ANJOU",
            "SAINT GEORGES DES GARDES"
        ]
    }

    process_documents(json.dumps(doc))
    result = Result(get_document('d|53543a313139353538390000'))
    result.housenumber = '2 bis'  # Simulate match_housenumber
    make_labels(None, result)

    assert result.labels == [
        '2 bis RUE PIERRE LEPOUREAU 49120 ST GEORGES DES GARDES (CHEMILLE EN ANJOU)',
        'RUE PIERRE LEPOUREAU 49120 ST GEORGES DES GARDES (CHEMILLE EN ANJOU)',
        '2 bis RUE PIERRE LEPOUREAU ST GEORGES DES GARDES (CHEMILLE EN ANJOU)',
        'RUE PIERRE LEPOUREAU ST GEORGES DES GARDES (CHEMILLE EN ANJOU)',
        '2 bis RUE PIERRE LEPOUREAU 49120 SAINT GEORGES DES GARDES',
        '2 bis RUE PIERRE LEPOUREAU 49120 ST GEORGES DES GARDES',
        'RUE PIERRE LEPOUREAU 49120 SAINT GEORGES DES GARDES',
        '2 bis RUE PIERRE LEPOUREAU SAINT GEORGES DES GARDES',
        '2 bis RUE PIERRE LEPOUREAU 49120 CHEMILLE EN ANJOU',
        'RUE PIERRE LEPOUREAU 49120 ST GEORGES DES GARDES',
        '2 bis RUE PIERRE LEPOUREAU ST GEORGES DES GARDES',
        'RUE PIERRE LEPOUREAU SAINT GEORGES DES GARDES',
        'RUE PIERRE LEPOUREAU 49120 CHEMILLE EN ANJOU',
        '2 bis RUE PIERRE LEPOUREAU CHEMILLE EN ANJOU',
        'RUE PIERRE LEPOUREAU ST GEORGES DES GARDES',
        'RUE PIERRE LEPOUREAU CHEMILLE EN ANJOU',
        '2 bis RUE PIERRE LEPOUREAU 49120', 'RUE PIERRE LEPOUREAU 49120',
        '2 bis RUE PIERRE LEPOUREAU', 'RUE PIERRE LEPOUREAU'
    ]