def test_copy(document_type_record): record = DocumentRecord( document_type_record, 'wrong_type', 'law_status', 'wrong_title', 'office_record', 'date_from', 'date_until', 'text_at_web', 'abbreviation', 'official_number', 'only_in_municipality', 'article_numbers', 1 ) copy = record.copy() assert isinstance(copy.document_type, DocumentTypeRecord) assert isinstance(copy.title, str) assert isinstance(copy.index, str) assert isinstance(copy.responsible_office, str) assert isinstance(copy.abbreviation, str) assert isinstance(copy.official_number, str) assert isinstance(copy.only_in_municipality, str) assert isinstance(copy.text_at_web, str) assert isinstance(copy.law_status, str) assert isinstance(copy.published_from, str) assert isinstance(copy.published_until, str) assert isinstance(copy.article_numbers, list) assert isinstance(copy.file, int)
def testarticle_numbers_init(document_type_record): record = DocumentRecord( document_type_record, 'wrong_type', 'law_status', 'wrong_title', 'office_record', 'date_from', 'date_until', 'text_at_web', 'abbreviation', 'official_number', 'only_in_municipality', 'article_numbers', 1 ) assert len(record.article_numbers) == 0 record = DocumentRecord( document_type_record, 'wrong_type', 'law_status', 'wrong_title', 'office_record', 'date_from', 'date_until', 'text_at_web', 'abbreviation', 'official_number', 'only_in_municipality', [1], 1 ) assert len(record.article_numbers) == 1
def test_serialize(document_type_record): record = DocumentRecord( document_type_record, 'wrong_type', 'law_status', 'wrong_title', 'office_record', 'date_from', 'date_until', 'text_at_web', 'abbreviation', 'official_number', 'only_in_municipality', 'article_numbers', 1 ) assert isinstance(record.__str__(), str)
def test_invalid_document_type(office_record): with pytest.raises(AttributeError): DocumentRecord( 'invalid', 1, 'AenderungMitVorwirkung', {'en': 'title'}, office_record, datetime.date(1985, 8, 29) )
def test_format_real_estate(DummyRenderInfo, real_estate_test_data): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = Parameter('json', 'reduced', True, False, 'BL0200002829', '1000', 'CH775979211712', 'de') geometry = MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]) view_service = ViewServiceRecord({'de': u'http://geowms.bl.ch'}, 1, 1.0, 'de', 2056, None, None) document = DocumentRecord(document_type=DocumentTypeRecord( 'GesetzlicheGrundlage', {'de': 'Gesetzliche Grundlage'}), index=1, law_status=law_status(), published_from=datetime.date.today(), title={u'de': u'Test Dokument'}, responsible_office=OfficeRecord({u'de': u'BUD'}), text_at_web={'de': 'http://mein.dokument.ch'}) real_estate = RealEstateRecord(u'Liegenschaft', u'BL', u'Liestal', 2829, 11395, geometry, u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712', u'Subunit', [], references=[document]) real_estate.set_view_service(view_service) real_estate.set_main_page_view_service(view_service) result = renderer.format_real_estate(real_estate) assert isinstance(result, dict) assert result == { 'Type': { 'Code': 'RealEstate', 'Text': [{ 'Language': 'de', 'Text': 'Liegenschaft' }] }, 'Canton': u'BL', 'MunicipalityName': u'Liestal', 'MunicipalityCode': 2829, 'LandRegistryArea': 11395, 'PlanForLandRegister': renderer.format_map(view_service), 'PlanForLandRegisterMainPage': renderer.format_map(view_service), 'Limit': renderer.from_shapely(geometry), 'Number': u'1000', 'IdentDN': u'BL0200002829', 'EGRID': u'CH775979211712', 'SubunitOfLandRegister': u'Subunit', 'MetadataOfGeographicalBaseData': u'http://www.geocat.ch', 'Reference': [renderer.format_document(document)] }
def test_legal_provision(law_test_data, law_status_record, office_record, document_type_record): legal_provision = DocumentRecord( document_type_record, 1, law_status_record, {'de': 'title'}, office_record, datetime.date(1985, 8, 29) ) assert isinstance(legal_provision.document_type, DocumentTypeRecord) assert legal_provision.document_type.code == 'GesetzlicheGrundlage'
def test_published(published_from, published_until, result, law_status_record, office_record, document_type_record): # noqa: E501 record = DocumentRecord( document_type_record, 1, law_status_record, {'en': 'title'}, office_record, published_from, published_until=published_until, text_at_web={'en': 'http://my.document.com'} ) assert record.published == result
def test_init(law_status_record, office_record, document_type_record): record = DocumentRecord( document_type_record, 1, law_status_record, {'en': 'title'}, office_record, datetime.date(1985, 8, 29), text_at_web={'en': 'http://my.document.com'} ) assert isinstance(record.document_type, DocumentTypeRecord) assert isinstance(record.index, int) assert isinstance(record.law_status, LawStatusRecord) assert isinstance(record.published_from, datetime.date) assert isinstance(record.title, dict) assert isinstance(record.responsible_office, OfficeRecord) assert isinstance(record.text_at_web, dict) assert record.published_until is None assert record.abbreviation is None assert record.official_number is None assert record.only_in_municipality is None assert record.article_numbers == [] assert record.published
def test_format_plr(DummyRenderInfo, parameter): renderer = Renderer(DummyRenderInfo()) renderer._language = 'de' renderer._params = parameter renderer._request = MockRequest() document = DocumentRecord(document_type=DocumentTypeRecord( 'GesetzlicheGrundlage', {'de': 'Gesetzliche Grundlage'}), index=1, law_status=law_status(), published_from=datetime.date.today(), title={u'de': u'Test Dokument'}, responsible_office=OfficeRecord({u'de': u'BUD'}), text_at_web={'de': 'http://mein.dokument.ch'}) documents = [document] theme = ThemeRecord(u'ch.BelasteteStandorte', {u'de': u'Test theme'}, 410) subTheme = None # subTheme = ThemeRecord( # u'ch.BelasteteStandorte', # {u'de': u'SubTheme'}, 411, u'SubCodech.BelasteteStandorte' # ) 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({'de': 'http://geowms.bl.ch'}, 1, 1.0, 'de', 2056, None, [legend_entry]) geometry = GeometryRecord(law_status(), datetime.date.today(), None, Point(1, 1)) plr = PlrRecord(theme, legend_entry, law_status(), datetime.date.today(), None, office, ImageRecord( FileAdapter().read('tests/resources/python.svg')), view_service, [geometry], subTheme, type_code='CodeA', type_code_list='TypeCodeList', documents=documents, view_service_id=1) plr.part_in_percent = 0.5 result = renderer.format_plr([plr]) assert isinstance(result, list) assert len(result) == 1 assert isinstance(result[0], dict) expected = { 'LegendText': renderer.get_multilingual_text(plr.legend_text), 'Theme': renderer.format_theme(plr.theme), 'Lawstatus': { 'Code': 'inKraft', 'Text': [{ 'Language': 'de', 'Text': 'Rechtskräftig' }] }, 'ResponsibleOffice': renderer.format_office(plr.responsible_office), 'Map': renderer.format_map(plr.view_service), '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: result = renderer.format_plr([plr]) assert isinstance(result, list) assert len(result) == 1 assert isinstance(result[0], dict) expected = { 'LegendText': renderer.get_multilingual_text(plr.legend_text), 'Theme': renderer.format_theme(plr.theme), 'Lawstatus': { 'Code': 'inKraft', 'Text': [{ 'Language': 'de', 'Text': 'Rechtskräftig' }] }, 'ResponsibleOffice': renderer.format_office(plr.responsible_office), 'Map': renderer.format_map(plr.view_service), '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='ch.BelasteteStandorte', view_service_id=1, code='CodeA') }) assert result[0] == expected
'http://example.com/image/symbol/{theme}/{view_service_id}/{code}.svg' .format(theme='ch.BelasteteStandorte', view_service_id=1, code='CodeA') }) assert result[0] == expected @pytest.mark.parametrize( 'document,result_dict', [(DocumentRecord(document_type=DocumentTypeRecord( 'Rechtsvorschrift', {"de": "Rechtsvorschrift"}), index=2, law_status=law_status(), title={'de': 'Test Rechtsvorschrift'}, published_from=datetime.date.today(), responsible_office=OfficeRecord({'de': 'AGI'}), text_at_web={'de': 'http://meine.rechtsvorschrift.ch'}, official_number={'de': 'rv.test.1'}, abbreviation={'de': 'Test'}, article_numbers=['Art.1', 'Art.2', 'Art.3']), { 'Type': { 'Code': 'Rechtsvorschrift', 'Text': [{ 'Language': 'de', 'Text': 'Rechtsvorschrift' }] }, 'Index': 2,
def test_mandatory_fields(): with pytest.raises(TypeError): DocumentRecord('AenderungMitVorwirkung', datetime.date(1985, 8, 29),)
def _get_document_records(self, document, language): """ Converts the received documents into records. Args: document (geolink_formatter.entity.Document): The geoLink document to be returned as document record. language (str): The language of the returned documents. Returns: list of pyramid_oereb.core.records.documents.DocumentRecord: The converted record. """ # Cancel if document contains no files if len(document.files) == 0: log.warning('Document with OEREBlex ID {0} has been skipped because of missing file.'.format( document.id )) return [] enactment_date = document.enactment_date authority = document.authority if document.doctype == 'notice': # Oereblex notices documents can have no enactment_date while it is require by pyramid_oereb to # have one. Add a fake default one that is identifiable and always older than now (01.0.1.1970). if enactment_date is None: enactment_date = datetime.date(1970, 1, 1) # Oereblex notices documents can have no `authority` while it is require by pyramid_oereb to # have one. Replace None by '-' in this case. if authority is None: authority = '-' # Cancel if enactment_date is not set if enactment_date is None: log.warning('Document with OEREBlex ID {0} has been skipped because of missing enactment_date.' .format(document.id)) return [] # Check mandatory attributes if document.title is None: raise AssertionError('Missing title for document #{0}'.format(document.id)) if authority is None: raise AssertionError('Missing authority for document #{0}'.format(document.id)) # Get document type document_type = Config.get_document_type_by_data_code(self._code, document.doctype) # Create related office record office = OfficeRecord({language: authority}, office_at_web=document.authority_url) # Get files records = [] for f in document.files: arguments = { 'document_type': document_type, 'index': document.index, 'law_status': Config.get_law_status_by_data_code(self._code, u'inKraft'), 'title': self._get_multilingual(f.title or document.title, language), 'responsible_office': office, 'published_from': enactment_date, # TODO: Use "publication_date" instead? 'published_until': None, # TODO: Use "abrogation_date"? 'text_at_web': self._get_multilingual(f.href, language), 'abbreviation': self._get_multilingual(document.abbreviation, language), 'official_number': self._get_multilingual(document.number, language), 'only_in_municipality': None, # TODO: Use "municipality" from OEREBlex? 'article_numbers': None } records.append(DocumentRecord(**arguments)) return records