def test_asdict(self, db_session): document = models.Document( title='Foo', document_uris=[ models.DocumentURI(uri='http://foo.com', claimant='http://foo.com'), models.DocumentURI(uri='http://foo.org', claimant='http://foo.com', type='rel-canonical') ]) db_session.add(document) db_session.flush() presenter = DocumentJSONPresenter(document) expected = {'title': ['Foo']} assert expected == presenter.asdict()
def test_it_merges_documents_when_duplicates_found(req): docuri_1 = models.DocumentURI(claimant='http://example.org/', uri='http://example.org/', type='self-claim') docuri_2 = models.DocumentURI(claimant='https://example.net/', uri='https://example.org/', type='rel-canonical') req.db.add_all([ models.Document(document_uris=[docuri_1]), models.Document(document_uris=[docuri_2]), ]) req.db.flush() normalize_uris.normalize_document_uris(req) assert req.db.query(models.Document).count() == 1
def test_it_deletes_duplicate_document_uri_objects(req): docuri_1 = models.DocumentURI(_claimant='http://example.org/', _claimant_normalized='http://example.org', _uri='http://example.org/', _uri_normalized='http://example.org', type='self-claim') docuri_2 = models.DocumentURI(_claimant='https://example.org/', _claimant_normalized='https://example.org', _uri='https://example.org/', _uri_normalized='https://example.org', type='self-claim') req.db.add(models.Document(document_uris=[docuri_1, docuri_2])) req.db.flush() normalize_uris.normalize_document_uris(req) assert req.db.query(models.DocumentURI).count() == 1
def test_asdict(self, db_session): document = models.Document( title="Foo", document_uris=[ models.DocumentURI(uri="http://foo.com", claimant="http://foo.com"), models.DocumentURI( uri="http://foo.org", claimant="http://foo.com", type="rel-canonical", ), ], ) db_session.add(document) db_session.flush() presenter = DocumentJSONPresenter(document) expected = {"title": ["Foo"]} assert expected == presenter.asdict()
def test_it_normalizes_document_uris_claimant(req): docuri_1 = models.DocumentURI(_claimant='http://example.org/', _claimant_normalized='http://example.org', _uri='http://example.org/', _uri_normalized='http://example.org', type='self-claim') docuri_2 = models.DocumentURI(_claimant='http://example.org/', _claimant_normalized='http://example.org', _uri='https://example.org/', _uri_normalized='https://example.org', type='rel-canonical') req.db.add(models.Document(document_uris=[docuri_1, docuri_2])) req.db.flush() normalize_uris.normalize_document_uris(req) assert docuri_1.claimant_normalized == 'httpx://example.org' assert docuri_2.claimant_normalized == 'httpx://example.org'
def document(session, uri): """Add a new Document for the given uri to the db and return it.""" document_ = models.Document() session.add(document_) # Flush the session so that document.id gets generated. session.flush() session.add(models.DocumentURI( claimant=uri, document_id=document_.id, uri=uri)) return document_
def test_it_normalizes_document_uris_claimant(req): docuri_1 = models.DocumentURI( _claimant="http://example.org/", _claimant_normalized="http://example.org", _uri="http://example.org/", _uri_normalized="http://example.org", type="self-claim", ) docuri_2 = models.DocumentURI( _claimant="http://example.org/", _claimant_normalized="http://example.org", _uri="https://example.org/", _uri_normalized="https://example.org", type="rel-canonical", ) req.db.add(models.Document(document_uris=[docuri_1, docuri_2])) req.db.flush() normalize_uris.normalize_document_uris(req) assert docuri_1.claimant_normalized == "httpx://example.org" assert docuri_2.claimant_normalized == "httpx://example.org"