def test_get_symbol_ref(theme_code, pyramid_test_config, pyramid_oereb_test_config): request = MockRequest() record = LegendEntryRecord(ImageRecord( FileAdapter().read('tests/resources/python.svg')), {'de': 'Test'}, u'test', u'test', ThemeRecord(theme_code, {'de': 'Test'}, 100), view_service_id=1) if theme_code == u'NotExistingTheme': with pytest.raises(HTTPServerError): Base.get_symbol_ref(request, record) else: ref = Base.get_symbol_ref(request, record) assert ref == 'http://example.com/image/symbol/{}/{}/{}.svg'.format( theme_code, record.view_service_id, record.type_code)
def __get_egrid_response__(self, records, params): """ Creates a valid GetEGRID response from a list of real estate records. Args: records (list of pyramid_oereb.lib.records.real_estate.RealEstateRecord): List of real estate records. params (pyramid_oereb.views.webservice.Parameter): The parameter object. Returns: pyramid.response.Response: The `getegrid` response. """ if len(records) == 0: return HTTPNoContent() output_format = self.__validate_format_param__(self._DEFAULT_FORMATS) real_estates = list() for r in records: real_estate = { 'egrid': getattr(r, 'egrid'), 'number': getattr(r, 'number'), 'identDN': getattr(r, 'identdn'), 'type': getattr(r, 'type') } if params.with_geometry and output_format == 'json': real_estate.update( {'limit': Renderer.from_shapely(getattr(r, 'limit'))}) elif params.with_geometry and output_format == 'xml': real_estate.update({'limit': getattr(r, 'limit')}) elif params.with_geometry and output_format not in ['json', 'xml']: raise HTTPInternalServerError( 'Format for GetEgrid not correct: {}'.format( output_format)) real_estates.append(real_estate) egrid = {'GetEGRIDResponse': real_estates} if output_format == 'json': response = render_to_response('json', egrid, request=self._request) response.content_type = 'application/json; charset=UTF-8' else: response = render_to_response('pyramid_oereb_getegrid_xml', (egrid, params), request=self._request) # response.extras = OerebStats(service='GetEGRID', output_format=output_format) return response
def test_render(pyramid_oereb_test_config, pyramid_test_config, DummyRenderInfo, parameter, glossaries_input, glossaries_expected, real_estate_test_data): view_service = ViewServiceRecord({'de': u'http://geowms.bl.ch'}, 1, 1.0, 'de', 2056, None, None) real_estate = RealEstateRecord( u'Liegenschaft', 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 = pyramid_oereb_test_config.get('extract').get( 'base_data').get('methods').get('date') date_method = resolver.resolve(date_method_string) update_date_os = date_method(real_estate) extract = ExtractRecord( real_estate, LogoRecord( 'ch', { 'de': 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \ 3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII=' }), LogoRecord( 'ch.plr', { 'de': 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \ 3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII=' }), LogoRecord( 'ne', { 'de': 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \ 3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII=' }), LogoRecord( 'ch.1234', { 'de': 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \ 3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII=' }), office_record, update_date_os, disclaimers=[ DisclaimerRecord({'de': u'Haftungsausschluss'}, {'de': u'Test'}) ], glossaries=glossaries_input, general_information=[ GeneralInformationRecord( {'de': u'Allgemeine Informationen'}, {'de': u'Inhalt der allgemeinen Informationen'}) ]) 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': [], 'PLRCadastreAuthority': renderer.format_office(office_record), 'UpdateDateCS': Base.date_time(extract.update_date_os), 'RealEstate': renderer.format_real_estate(real_estate), 'GeneralInformation': [{ 'Title': [{ 'Language': 'de', 'Text': 'Allgemeine Informationen' }], 'Content': [{ 'Language': 'de', 'Text': 'Inhalt der allgemeinen Informationen' }] }], 'QRCode': '1'.encode('utf-8'), 'Disclaimer': [{ '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': Config.get_oereb_logo().encode(), 'FederalLogo': Config.get_conferderation_logo().encode(), 'CantonalLogo': Config.get_canton_logo().encode(), 'MunicipalityLogo': Config.get_municipality_logo(2771), }) 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/logo/municipality/de.png?fosnr=2829' }) # not sure what is expected => make tests pass by force expected['GeneralInformation'] = result['GeneralInformation'] assert result['GeneralInformation'] == expected['GeneralInformation'] assert result == expected
def test_get_missing_response(): response = Base.get_response({}) assert response is None
def test_get_response(): response = Base.get_response({'request': DummyRequest()}) assert isinstance(response, Response)
def test_get_missing_request(): request = Base.get_request({}) assert request is None
def test_get_request(): request = Base.get_request({'request': DummyRequest()}) assert isinstance(request, DummyRequest)
def test_date_time(input, result): assert Base.date_time(input) == result
def test_call(DummyRenderInfo, pyramid_oereb_test_config): renderer = Base(DummyRenderInfo()) assert isinstance(renderer.info, DummyRenderInfo) assert renderer.info.name == 'test'