def test_init_with_relation():
    office_record = OfficeRecord({'en': 'name'})
    law_status = LawStatusRecord.from_config(u'inForce')
    articles = [ArticleRecord(law_status, datetime.date(1985, 8, 29), '123.4')]
    references = [
        DocumentRecord('Law', law_status, datetime.date(1985, 8,
                                                        29), {'de': 'Titel 1'},
                       office_record, {'en': 'http://my.document.com'})
    ]
    record = DocumentRecord('Hint',
                            law_status,
                            datetime.date(1985, 8, 29), {'de': 'title'},
                            office_record, {'en': 'http://my.document.com'},
                            articles=articles,
                            references=references,
                            article_numbers=['test'])
    assert isinstance(record.document_type, str)
    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.abbreviation is None
    assert record.official_number is None
    assert record.official_title is None
    assert record.canton is None
    assert record.municipality is None
    assert record.article_numbers == ['test']
    assert isinstance(record.articles, list)
    assert isinstance(record.references, list)
def test_future_document(law_status):
    office_record = OfficeRecord({'en': 'name'})
    record = DocumentRecord(
        law_status,
        (datetime.datetime.now().date() + datetime.timedelta(days=7)),
        {'en': 'title'}, office_record, {'en': 'http://my.document.com'})
    assert not record.published
def test_format_real_estate(config):
    assert isinstance(config._config, dict)
    renderer = Renderer(DummyRenderInfo())
    renderer._language = u'de'
    renderer._params = Parameter(
        'reduced', 'json', True, False, 'BL0200002829', '1000', 'CH775979211712', 'de')
    geometry = MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])])
    view_service = ViewServiceRecord(u'http://geowms.bl.ch', u'http://geowms.bl.ch')
    document = DocumentRecord(law_status(), datetime.date.today(), {u'de': u'Test Dokument'},
                              OfficeRecord({u'de': u'BUD'}), {'de': 'http://mein.dokument.ch'})
    real_estate = RealEstateRecord(u'RealEstate', u'BL', u'Liestal', 2829, 11395,
                                   geometry, u'http://www.geocat.ch', u'1000', u'BL0200002829',
                                   u'CH775979211712', u'Subunit', [], references=[document])
    real_estate.plan_for_land_register = view_service
    result = renderer.format_real_estate(real_estate)
    assert isinstance(result, dict)
    assert result == {
        'Type': u'RealEstate',
        'Canton': u'BL',
        'Municipality': u'Liestal',
        'FosNr': 2829,
        'LandRegistryArea': 11395,
        'PlanForLandRegister': 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_future_document():
    office_record = OfficeRecord({'en': 'name'})
    law_status = LawStatusRecord.from_config(u'inForce')
    record = DocumentRecord(
        'Hint', law_status,
        (datetime.datetime.now().date() + datetime.timedelta(days=7)),
        {'en': 'title'}, office_record, {'en': 'http://my.document.com'})
    assert not record.published
Exemple #5
0
def test_get_document_type():
    document = DocumentRecord(LawStatusRecord.from_config('inForce'),
                              datetime.date.today(), {'de': 'Test'},
                              OfficeRecord({'de': 'Test'}))
    legal_provision = LegalProvisionRecord(
        LawStatusRecord.from_config('inForce'), datetime.date.today(),
        {'de': 'Test'}, OfficeRecord({'de': 'Test'}))
    assert Renderer._get_document_type(document) == 'data:Document'
    assert Renderer._get_document_type(
        legal_provision) == 'data:LegalProvisions'
def test_init(law_status):
    office_record = OfficeRecord({'en': 'name'})
    record = DocumentRecord(law_status, datetime.date(1985, 8,
                                                      29), {'en': 'title'},
                            office_record, {'en': 'http://my.document.com'})
    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.abbreviation is None
    assert record.official_number is None
    assert record.official_title is None
    assert record.canton is None
    assert record.municipality is None
    assert record.article_numbers == []
    assert isinstance(record.articles, list)
    assert isinstance(record.references, list)
    assert record.published
def test_mandatory_fields():
    with pytest.raises(TypeError):
        DocumentRecord('runningModifications', datetime.date(1985, 8, 29))
def test_invalid_document_type():
    office_record = OfficeRecord({'en': 'name'})
    with pytest.raises(AttributeError):
        DocumentRecord('invalid', 'runningModifications',
                       datetime.date(1985, 8, 29), {'en': 'title'},
                       office_record)
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(
            base64.b64encode('1'.encode('utf-8'))), {'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('1'.encode('utf-8')),
                        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':
                    base64.b64encode('1'.encode('utf-8')).decode('ascii')
                })
            else:
                expected.update({
                    'SymbolRef':
                    'http://example.com/image/symbol/{theme}/{view_service_id}/{code}'
                    .format(theme='ContaminatedSites',
                            view_service_id=1,
                            code='CodeA')
                })
            assert result[0] == expected
                            view_service_id=1,
                            code='CodeA')
                })
            assert result[0] == expected


@pytest.mark.parametrize('document,result_dict', [
    (LegalProvisionRecord(
        law_status(), datetime.date.today(), {'de': 'Test Rechtsvorschrift'},
        OfficeRecord({'de': 'AGI'
                      }), {'de': 'http://meine.rechtsvorschrift.ch'},
        {'de': 'Test'}, 'rv.test.1', {'de': 'Rechtsvorschrift Test'}, 'BL',
        'Liestal', ['Art.1', 'Art.2', 'Art.3'], '1'.encode('utf-8'),
        [ArticleRecord(law_status(), datetime.date.today(), 'art.1')], [
            DocumentRecord('Law', law_status(), datetime.date.today(),
                           {'de': 'Test Dokument'}, OfficeRecord({
                               'de': 'BUD'
                           }), {'de': 'http://mein.dokument.ch'})
        ]), {
            'DocumentType':
            'LegalProvision',
            'Lawstatus': {
                'Code': 'inForce',
                'Text': {
                    'Language': 'de',
                    'Text': 'In Kraft'
                }
            },
            'TextAtWeb': [
                {
                    'Language': 'de',
                    'Text': 'http://meine.rechtsvorschrift.ch'