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_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_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_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()
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_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 assert json.loads(lines[0]) == mun.as_list assert json.loads(lines[1]) == street.as_list resource = hn.as_list # JSON transform internals tuples to lists. resource['center']['coordinates'] = list(resource['center']['coordinates']) # noqa assert json.loads(lines[2]) == resource path.unlink()
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()
def test_cannot_export_wrong_resource(): pc = factories.PostCodeFactory() path = Path(__file__).parent / 'data' with pytest.raises(SystemExit): resources('toto', path)