Exemplo n.º 1
0
def test_it_normalizes_document_meta_claimant(req):
    docmeta_1 = models.DocumentMeta(_claimant='http://example.org/',
                                    _claimant_normalized='http://example.org',
                                    type='title',
                                    value=['Test Title'])
    docmeta_2 = models.DocumentMeta(_claimant='http://example.net/',
                                    _claimant_normalized='http://example.net',
                                    type='title',
                                    value=['Test Title'])

    req.db.add(models.Document(meta=[docmeta_1, docmeta_2]))
    req.db.flush()

    normalize_uris.normalize_document_meta(req)

    assert docmeta_1.claimant_normalized == 'httpx://example.org'
    assert docmeta_2.claimant_normalized == 'httpx://example.net'
Exemplo n.º 2
0
def test_it_deletes_duplicate_document_meta_objects(req):
    docmeta_1 = models.DocumentMeta(_claimant="http://example.org/",
                                    type="title",
                                    value=["Test Title"])
    docmeta_1._claimant_normalized = "http://example.org"
    docmeta_2 = models.DocumentMeta(_claimant="https://example.org/",
                                    type="title",
                                    value=["Test Title"])
    docmeta_2._claimant_normalized = "https://example.org"

    req.db.add_all(
        [models.Document(meta=[docmeta_1]),
         models.Document(meta=[docmeta_2])])
    req.db.flush()

    normalize_uris.normalize_document_meta(req)

    assert req.db.query(models.DocumentMeta).count() == 1
Exemplo n.º 3
0
    def test_asdict_does_not_render_other_meta_than_title(self, db_session):
        document = models.Document(
            title='Foo',
            meta=[
                models.DocumentMeta(type='title',
                                    value=['Foo'],
                                    claimant='http://foo.com'),
                models.DocumentMeta(type='twitter.url',
                                    value=['http://foo.com'],
                                    claimant='http://foo.com'),
                models.DocumentMeta(type='facebook.title',
                                    value=['FB Title'],
                                    claimant='http://foo.com')
            ])
        db_session.add(document)
        db_session.flush()

        presenter = DocumentJSONPresenter(document)
        assert {'title': ['Foo']} == presenter.asdict()
Exemplo n.º 4
0
def test_it_normalizes_document_meta_claimant(req):
    docmeta_1 = models.DocumentMeta(
        _claimant="http://example.org/",
        _claimant_normalized="http://example.org",
        type="title",
        value=["Test Title"],
    )
    docmeta_2 = models.DocumentMeta(
        _claimant="http://example.net/",
        _claimant_normalized="http://example.net",
        type="title",
        value=["Test Title"],
    )

    req.db.add(models.Document(meta=[docmeta_1, docmeta_2]))
    req.db.flush()

    normalize_uris.normalize_document_meta(req)

    assert docmeta_1.claimant_normalized == "httpx://example.org"
    assert docmeta_2.claimant_normalized == "httpx://example.net"
Exemplo n.º 5
0
    def test_asdict_does_not_render_other_meta_than_title(self, db_session):
        document = models.Document(
            title="Foo",
            meta=[
                models.DocumentMeta(type="title",
                                    value=["Foo"],
                                    claimant="http://foo.com"),
                models.DocumentMeta(
                    type="twitter.url",
                    value=["http://foo.com"],
                    claimant="http://foo.com",
                ),
                models.DocumentMeta(type="facebook.title",
                                    value=["FB Title"],
                                    claimant="http://foo.com"),
            ],
        )
        db_session.add(document)
        db_session.flush()

        presenter = DocumentJSONPresenter(document)
        assert {"title": ["Foo"]} == presenter.asdict()