Exemple #1
0
def test_get_group_housenumbers(get, url):
    street = GroupFactory()
    hn1 = HouseNumberFactory(number="1", parent=street)
    hn2 = HouseNumberFactory(number="2", parent=street)
    hn3 = HouseNumberFactory(number="3", parent=street)
    resp = get(url('group-housenumbers', identifier=street.id))
    assert resp.status == falcon.HTTP_200
    assert resp.json['total'] == 3
    # loads/dumps to compare string dates to string dates.
    assert resp.json['collection'][0] == json.loads(dumps(hn1.as_list))
    assert resp.json['collection'][1] == json.loads(dumps(hn2.as_list))
    assert resp.json['collection'][2] == json.loads(dumps(hn3.as_list))
Exemple #2
0
def test_get_group_housenumbers(get):
    street = GroupFactory()
    hn1 = HouseNumberFactory(number="1", parent=street)
    hn2 = HouseNumberFactory(number="2", parent=street)
    hn3 = HouseNumberFactory(number="3", parent=street)
    resp = get('/housenumber?group={}'.format(street.id))
    assert resp.status_code == 200
    assert resp.json['total'] == 3
    assert resp.json['collection'][0] == json.loads(
        dumps({
            'attributes': None,
            'laposte': None,
            'ordinal': 'bis',
            'parent': street.id,
            'id': hn1.id,
            'version': 1,
            'postcode': None,
            'number': '1',
            'resource': 'housenumber',
            'cia': hn1.cia,
            'ign': None,
        }))
    assert resp.json['collection'][1] == json.loads(
        dumps({
            'attributes': None,
            'laposte': None,
            'ordinal': 'bis',
            'parent': street.id,
            'id': hn2.id,
            'version': 1,
            'postcode': None,
            'number': '2',
            'resource': 'housenumber',
            'cia': hn2.cia,
            'ign': None,
        }))
    assert resp.json['collection'][2] == json.loads(
        dumps({
            'attributes': None,
            'laposte': None,
            'ordinal': 'bis',
            'parent': street.id,
            'id': hn3.id,
            'version': 1,
            'postcode': None,
            'number': '3',
            'resource': 'housenumber',
            'cia': hn3.cia,
            'ign': None,
        }))
Exemple #3
0
def abort(code, headers=None, **kwargs):
    description = dumps(kwargs)
    response = Response(status=code,
                        mimetype='application/json',
                        response=description,
                        headers=headers)
    raise HTTPException(description=description, response=response)
def test_get_group_housenumbers(get):
    street = GroupFactory()
    hn1 = HouseNumberFactory(number="1", parent=street)
    hn2 = HouseNumberFactory(number="2", parent=street)
    hn3 = HouseNumberFactory(number="3", parent=street)
    resp = get('/housenumber?group={}'.format(street.id))
    assert resp.status_code == 200
    assert resp.json['total'] == 3
    assert resp.json['collection'][0] == json.loads(dumps({
        'attributes': None,
        'laposte': None,
        'ordinal': 'bis',
        'parent': street.id,
        'id': hn1.id,
        'version': 1,
        'postcode': None,
        'number': '1',
        'resource': 'housenumber',
        'cia': hn1.cia,
        'ign': None,
    }))
    assert resp.json['collection'][1] == json.loads(dumps({
        'attributes': None,
        'laposte': None,
        'ordinal': 'bis',
        'parent': street.id,
        'id': hn2.id,
        'version': 1,
        'postcode': None,
        'number': '2',
        'resource': 'housenumber',
        'cia': hn2.cia,
        'ign': None,
    }))
    assert resp.json['collection'][2] == json.loads(dumps({
        'attributes': None,
        'laposte': None,
        'ordinal': 'bis',
        'parent': street.id,
        'id': hn3.id,
        'version': 1,
        'postcode': None,
        'number': '3',
        'resource': 'housenumber',
        'cia': hn3.cia,
        'ign': None,
    }))
Exemple #5
0
def test_get_municipality_groups_collection(get):
    municipality = MunicipalityFactory(name="Cabour")
    street = GroupFactory(municipality=municipality, name="Rue de la Plage")
    resp = get('/group?municipality={}'.format(municipality.id))
    assert resp.status_code == 200
    # loads/dumps to compare date strings to date strings.
    assert resp.json['collection'][0] == json.loads(dumps(street.as_relation))
    assert resp.json['total'] == 1
Exemple #6
0
def test_housenumber_with_two_positions_is_not_duplicated_in_bbox(get):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(1.1, 1.1), housenumber=position.housenumber)
    resp = get('/housenumber?north=2&south=0&west=0&east=2')
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    data = json.loads(dumps(position.housenumber.as_relation))
    assert resp.json['collection'][0] == data
def test_get_housenumber_collection_can_be_filtered_by_bbox(get):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(-1, -1))
    resp = get('/housenumber?north=2&south=0&west=0&east=2')
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    resource = position.housenumber.as_relation
    assert resp.json['collection'][0] == json.loads(dumps(resource))
def test_get_municipality_groups_collection(get):
    municipality = MunicipalityFactory(name="Cabour")
    street = GroupFactory(municipality=municipality, name="Rue de la Plage")
    resp = get('/group?municipality={}'.format(municipality.id))
    assert resp.status_code == 200
    # loads/dumps to compare date strings to date strings.
    assert resp.json['collection'][0] == json.loads(dumps(street.as_relation))
    assert resp.json['total'] == 1
Exemple #9
0
def test_get_housenumber_collection_can_be_filtered_by_bbox(get):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(-1, -1))
    resp = get('/housenumber?north=2&south=0&west=0&east=2')
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    resource = position.housenumber.as_relation
    assert resp.json['collection'][0] == json.loads(dumps(resource))
def test_get_position_collection_can_be_filtered_by_bbox(get, url):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(-1, -1))
    resp = get("/position?north=2&south=0&west=0&east=2")
    assert resp.json["total"] == 1
    # JSON transforms internals tuples to lists.
    resource = position.as_relation
    assert resp.json["collection"][0] == json.loads(dumps(resource))
Exemple #11
0
def test_export_resources():
    mun = factories.MunicipalityFactory()
    street = factories.GroupFactory(municipality=mun)
    hn = factories.HouseNumberFactory(parent=street)
    factories.PositionFactory(housenumber=hn)
    path = Path(__file__).parent / 'data/export.sjson'
    resources(path)

    with path.open() as f:
        lines = f.readlines()
        assert len(lines) == 3
        # loads/dumps to compare string dates to string dates.
        assert json.loads(lines[0]) == json.loads(dumps(mun.as_list))
        assert json.loads(lines[1]) == json.loads(dumps(street.as_list))
        # Plus, JSON transform internals tuples to lists.
        assert json.loads(lines[2]) == json.loads(dumps(hn.as_list))
    path.unlink()
def test_housenumber_with_two_positions_is_not_duplicated_in_bbox(get):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(1.1, 1.1), housenumber=position.housenumber)
    resp = get('/housenumber?north=2&south=0&west=0&east=2')
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    data = json.loads(dumps(position.housenumber.as_relation))
    assert resp.json['collection'][0] == data
Exemple #13
0
def test_housenumber_with_two_positions_is_not_duplicated_in_bbox(get, url):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(1.1, 1.1), housenumber=position.housenumber)
    bbox = dict(north=2, south=0, west=0, east=2)
    resp = get(url('housenumber', query_string=bbox))
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    data = json.loads(dumps(position.housenumber.as_resource))
    assert resp.json['collection'][0] == data
Exemple #14
0
def test_get_housenumber_collection_can_be_filtered_by_bbox(get, url):
    position = PositionFactory(center=(1, 1))
    PositionFactory(center=(-1, -1))
    bbox = dict(north=2, south=0, west=0, east=2)
    resp = get(url('housenumber', query_string=bbox))
    assert resp.json['total'] == 1
    # JSON transform internals tuples to lists.
    resource = position.housenumber.as_resource
    assert resp.json['collection'][0] == json.loads(dumps(resource))
Exemple #15
0
def test_export_resources():
    mun = factories.MunicipalityFactory()
    street = factories.GroupFactory(municipality=mun)
    hn = factories.HouseNumberFactory(parent=street)
    factories.PositionFactory(housenumber=hn)
    deleted = factories.PositionFactory(housenumber=hn)
    deleted.mark_deleted()
    path = Path(__file__).parent / 'data/export.sjson'
    resources(path)

    with path.open() as f:
        lines = f.readlines()
        assert len(lines) == 3
        # loads/dumps to compare string dates to string dates.
        assert json.loads(lines[0]) == json.loads(dumps(mun.as_resource))
        assert json.loads(lines[1]) == json.loads(dumps(street.as_resource))
        # Plus, JSON transform internals tuples to lists.
        assert json.loads(lines[2]) == json.loads(dumps(hn.as_resource))
    path.unlink()
Exemple #16
0
 def wrapper(*args, **kwargs):
     rv = func(*args, **kwargs)
     if not isinstance(rv, tuple):
         rv = [rv]
     else:
         rv = list(rv)
     rv[0] = dumps(rv[0], sort_keys=True)
     resp = make_response(tuple(rv))
     resp.mimetype = 'application/json'
     return resp
Exemple #17
0
 def wrapper(*args, **kwargs):
     rv = func(*args, **kwargs)
     if not isinstance(rv, tuple):
         rv = [rv]
     else:
         rv = list(rv)
     rv[0] = dumps(rv[0])
     resp = make_response(tuple(rv))
     resp.mimetype = 'application/json'
     return resp
Exemple #18
0
def resources(path, **kwargs):
    """Export database as resources in json stream format.

    path    path of file where to write resources
    """
    resources = [models.PostCode, models.Municipality, models.Group,
                 models.HouseNumber]
    with Path(path).open(mode='w', encoding='utf-8') as f:
        for resource in resources:
            for data in resource.select().serialize({'*': {}}):
                f.write(dumps(data) + '\n')
                reporter.notice(resource.__name__, data)
def test_export_group():
    street = factories.GroupFactory()
    path = Path(__file__).parent / 'data'
    resources('Group', path)

    filepath = path.joinpath('group.ndjson')
    with filepath.open() as f:
        lines = f.readlines()
        assert len(lines) == 1
        # loads/dumps to compare string dates to string dates.
        assert json.loads(lines[0]) == json.loads(dumps(street.as_export))
    filepath.unlink()
def test_export_housenumber():
    hn = factories.HouseNumberFactory(number='1')
    path = Path(__file__).parent / 'data'
    resources('HouseNumber', path)

    filepath = path.joinpath('housenumber.ndjson')
    with filepath.open() as f:
        lines = f.readlines()
        assert len(lines) == 1
        # Plus, JSON transform internals tuples to lists.
        assert json.loads(lines[0]) == json.loads(dumps(hn.as_export))
    filepath.unlink()
def test_export_postcode():
    pc = factories.PostCodeFactory()
    path = Path(__file__).parent / 'data'
    resources('PostCode', path)

    filepath = path.joinpath('postcode.ndjson')
    with filepath.open() as f:
        lines = f.readlines()
        assert len(lines) == 1
        # Plus, JSON transform internals tuples to lists.
        assert json.loads(lines[0]) == json.loads(dumps(pc.as_export))
    filepath.unlink()
def test_export_municipality():
    mun = factories.MunicipalityFactory()
    path = Path(__file__).parent / 'data'
    resources('Municipality', path)

    filepath = path.joinpath('municipality.ndjson')
    with filepath.open() as f:
        lines = f.readlines()
        assert len(lines) == 1
        # loads/dumps to compare string dates to string dates.
        assert json.loads(lines[0]) == json.loads(dumps(mun.as_export))
    filepath.unlink()
Exemple #23
0
def resources(path, **kwargs):
    """Export database as resources in json stream format.

    path    path of file where to write resources
    """
    resources = [
        models.PostCode, models.Municipality, models.Group, models.HouseNumber
    ]
    with Path(path).open(mode='w', encoding='utf-8') as f:
        for resource in resources:
            for data in resource.select().serialize({'*': {}}):
                f.write(dumps(data) + '\n')
                reporter.notice(resource.__name__, data)
Exemple #24
0
def resources(path, **kwargs):
    """Export database as resources in json stream format.

    path    path of file where to write resources
    """
    resources = [models.PostCode, models.Municipality, models.Locality,
                 models.Street, models.HouseNumber]
    with Path(path).open(mode='w', encoding='utf-8') as f:
        for resource in resources:
            for data in resource.select().as_resource_list():
                f.write(dumps(data) + '\n')
                # Memory consumption when exporting all France housenumbers?
                report(resource.__name__, data, report.NOTICE)
Exemple #25
0
def resources(path, **kwargs):
    """Export database as resources in json stream format.

    path    path of file where to write resources
    """
    resources = [
        models.PostCode, models.Municipality, models.Locality, models.Street,
        models.HouseNumber
    ]
    with Path(path).open(mode='w', encoding='utf-8') as f:
        for resource in resources:
            for data in resource.select().as_resource_list():
                f.write(dumps(data) + '\n')
                # Memory consumption when exporting all France housenumbers?
                report(resource.__name__, data, report.NOTICE)
Exemple #26
0
 def serialize(self):
     return dumps(self.as_resource)
Exemple #27
0
 def json(self, **kwargs):
     self.body = dumps(kwargs)
Exemple #28
0
def test_get_housenumber_collection(get, url):
    objs = HouseNumberFactory.create_batch(5)
    resp = get(url('housenumber'))
    assert resp.json['total'] == 5
    for obj in objs:
        assert json.loads(dumps(obj.as_resource)) in resp.json['collection']
Exemple #29
0
 def check(position):
     data = position.as_list
     # postgis uses tuples for coordinates, while json does not know
     # tuple and transforms everything to lists.
     assert json.loads(dumps(data)) in resp.json['collection']
Exemple #30
0
def test_get_housenumber_with_postcode(get, url):
    postcode = PostCodeFactory(code="12345")
    housenumber = HouseNumberFactory(postcode=postcode)
    resp = get(url('housenumber-resource', identifier=housenumber.id))
    assert resp.json['postcode'] == json.loads(dumps(postcode.as_relation))
Exemple #31
0
 def json(self, **kwargs):
     self.body = dumps(kwargs)
Exemple #32
0
def test_get_housenumber_collection(get):
    objs = HouseNumberFactory.create_batch(5)
    resp = get('/housenumber')
    assert resp.json['total'] == 5
    for obj in objs:
        assert json.loads(dumps(obj.as_relation)) in resp.json['collection']
Exemple #33
0
def openapi():
    return dumps(app._schema)
Exemple #34
0
def process_resource(*rows):
    with database.execution_context():  # Reset connection in current process.
        results = []
        for row in rows:
            results.append(dumps(row.as_export))
        return results
Exemple #35
0
def bal_post():
    """Import file at BAL format."""
    data = request.files['data']
    bal(StringIO(data.read().decode('utf-8-sig')))
    reporter = context.get('reporter')
    return dumps({'report': reporter})
Exemple #36
0
 def serialize(self, fields=None):
     return dumps(self._serialize(self._meta.fields))
Exemple #37
0
 def check(position):
     data = position.as_relation
     # postgis uses tuples for coordinates, while json does not know
     # tuple and transforms everything to lists.
     assert json.loads(dumps(data)) in resp.json['collection']
Exemple #38
0
 def serialize(self, fields=None):
     return dumps(self._serialize(self._meta.fields))
Exemple #39
0
def abort(code, headers=None, **kwargs):
    description = dumps(kwargs)
    response = Response(status=code, mimetype='application/json',
                        response=description, headers=headers)
    raise HTTPException(description=description, response=response)