def test_read(): base_path = os.path.abspath('./tests/resources') file_adapter = FileAdapter(base_path) content = file_adapter.read('file_adapter_dummy.txt').decode('utf-8') assert content.startswith( 'If the content looks like this, the test has been successful.')
def test_cd(): base_path = os.path.abspath('.') file_adapter = FileAdapter() file_adapter.cd('test') assert file_adapter.cwd == os.path.join(base_path, 'test')
def test_init(): base_path = os.path.abspath('.') file_adapter_1 = FileAdapter() assert file_adapter_1.cwd == base_path file_adapter_2 = FileAdapter('test') assert file_adapter_2.cwd == os.path.join(base_path, 'test')
def test_read_no_file(): base_path = os.path.abspath('./tests/resources') file_adapter = FileAdapter(base_path) with pytest.raises(IOError) as exc_info: file_adapter.read('plr119') assert 'Not a file:' in str(exc_info.value)
def test_render(parameter, glossaries_input, glossaries_expected): date = datetime.datetime.now() with pyramid_oereb_test_config(): view_service = ViewServiceRecord(u'http://geowms.bl.ch', 1, 1.0, {'de': u'http://geowms.bl.ch'}, None) real_estate = RealEstateRecord(u'RealEstate', u'BL', u'Liestal', 2829, 11395, MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]), u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712') real_estate.set_view_service(view_service) real_estate.set_main_page_view_service(view_service) office_record = OfficeRecord({'de': u'AGI'}) resolver = DottedNameResolver() date_method_string = Config.get('extract').get('base_data').get('methods').get('date') date_method = resolver.resolve(date_method_string) av_update_date = date_method(real_estate) base_data = Config.get_base_data(av_update_date) av_provider_method_string = Config.get('extract').get('base_data').get('methods').get('provider') av_provider_method = resolver.resolve(av_provider_method_string) cadaster_state = date theme = ThemeRecord(u'TEST', {'de': u'TEST TEXT'}) datasources = [DatasourceRecord(theme, date, office_record)] plr_cadastre_authority = Config.get_plr_cadastre_authority() embeddable = EmbeddableRecord( cadaster_state, plr_cadastre_authority, av_provider_method(real_estate), av_update_date, datasources ) extract = ExtractRecord( real_estate, ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')), ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')), ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')), ImageRecord(FileAdapter().read('tests/resources/python.svg')), office_record, base_data, embeddable, exclusions_of_liability=[ ExclusionOfLiabilityRecord({'de': u'Haftungsausschluss'}, {'de': u'Test'}) ], glossaries=glossaries_input, general_information={'de': u'Allgemeine Informationen'}, certification={'de': u'certification'}, certification_at_web={'de': u'certification_at_web'}, ) extract.qr_code = '1'.encode('utf-8') extract.electronic_signature = 'Signature' renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._request = MockRequest() if parameter is None: with pytest.raises(TypeError): renderer._render(extract, None) else: result = renderer._render(extract, parameter) assert isinstance(result, dict) expected = { 'ExtractIdentifier': extract.extract_identifier, 'CreationDate': Base.date_time(extract.creation_date), 'ConcernedTheme': [], 'NotConcernedTheme': [], 'ThemeWithoutData': [], 'isReduced': True, 'PLRCadastreAuthority': renderer.format_office(office_record), 'BaseData': renderer.get_multilingual_text(Config.get_base_data(av_update_date)), 'RealEstate': renderer.format_real_estate(real_estate), 'Certification': [{'Language': 'de', 'Text': 'certification'}], 'CertificationAtWeb': [{'Language': 'de', 'Text': 'certification_at_web'}], 'GeneralInformation': [{'Language': 'de', 'Text': 'Allgemeine Informationen'}], 'QRCode': '1'.encode('utf-8'), 'ExclusionOfLiability': [{ 'Title': [{'Language': 'de', 'Text': 'Haftungsausschluss'}], 'Content': [{'Language': 'de', 'Text': 'Test'}] }], 'ElectronicSignature': 'Signature' } if glossaries_expected: expected['Glossary'] = glossaries_expected if parameter.images: expected.update({ 'LogoPLRCadastre': ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')) .encode(), 'FederalLogo': ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')) .encode(), 'CantonalLogo': ImageRecord(FileAdapter().read('tests/resources/logo_canton.png')) .encode(), 'MunicipalityLogo': ImageRecord(FileAdapter().read('tests/resources/python.svg')) .encode(), }) else: expected.update({ 'LogoPLRCadastreRef': u'http://example.com/image/logo/oereb/de.png', 'FederalLogoRef': u'http://example.com/image/logo/confederation/de.png', 'CantonalLogoRef': u'http://example.com/image/logo/canton/de.png', 'MunicipalityLogoRef': u'http://example.com/image/municipality/2829.svg' }) assert result == expected
def test_format_plr(parameter): with pyramid_oereb_test_config(): renderer = Renderer(DummyRenderInfo()) renderer._language = 'de' renderer._params = parameter renderer._request = MockRequest() document = DocumentRecord( 'Law', law_status(), datetime.date.today(), {u'de': u'Test Dokument'}, OfficeRecord({u'de': u'BUD'}), {'de': 'http://mein.dokument.ch'} ) if parameter.flavour == 'reduced': documents = [document] else: documents = None theme = ThemeRecord(u'ContaminatedSites', {u'de': u'Test theme'}) office = OfficeRecord({'de': 'Test Office'}) legend_entry = LegendEntryRecord( ImageRecord(FileAdapter().read('tests/resources/python.svg')), {'de': 'Test'}, 'CodeA', 'TypeCodeList', theme, view_service_id=1) view_service = ViewServiceRecord('http://geowms.bl.ch', 1, 1.0, {'de': u'http://geowms.bl.ch'}, [legend_entry]) geometry = GeometryRecord(law_status(), datetime.date.today(), Point(1, 1)) plr = PlrRecord( theme, {'de': 'Test'}, law_status(), datetime.date.today(), office, ImageRecord(FileAdapter().read('tests/resources/python.svg')), view_service, [geometry], sub_theme={ 'de': 'Subtopic' }, other_theme='Additional topic', type_code='CodeA', type_code_list='TypeCodeList', documents=documents, view_service_id=1 ) plr.part_in_percent = 0.5 if parameter.flavour == 'full': with pytest.raises(ValueError): renderer.format_plr([plr]) else: result = renderer.format_plr([plr]) assert isinstance(result, list) assert len(result) == 1 assert isinstance(result[0], dict) expected = { 'Information': renderer.get_multilingual_text(plr.information), 'Theme': renderer.format_theme(plr.theme), 'Lawstatus': { 'Code': 'inForce', 'Text': {'Language': 'de', 'Text': 'In Kraft'} }, 'ResponsibleOffice': renderer.format_office(plr.responsible_office), 'Map': renderer.format_map(plr.view_service), 'SubTheme': 'Subtopic', 'OtherTheme': 'Additional topic', 'TypeCode': 'CodeA', 'TypeCodelist': 'TypeCodeList', 'LegalProvisions': [renderer.format_document(document)], 'PartInPercent': 0.5 } if parameter.images: expected.update({ 'Symbol': ImageRecord(FileAdapter().read('tests/resources/python.svg')).encode() }) else: expected.update({ 'SymbolRef': 'http://example.com/image/symbol/{theme}/{view_service_id}/{code}.svg' .format( theme='ContaminatedSites', view_service_id=1, code='CodeA' ) }) assert result[0] == expected