def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None scopes = [uri.normalize(u) for u in storage.expand_uri(uristr)] return {"terms": {"target.scope": scopes}}
def __call__(self, params): uristr = params.pop('uri', None) if uristr is None: return None uris = storage.expand_uri(self.request.db, uristr) scopes = [uri.normalize(u) for u in uris] return {"terms": {"target.scope": scopes}}
def test_expand_uri_document_uris(document_model): document_model.get_by_uri.return_value.uris.return_value = [ "http://foo.com/", "http://bar.com/", ] assert storage.expand_uri("http://example.com/") == [ "http://foo.com/", "http://bar.com/", ]
def _expand_uris(clause): uris = clause['value'] expanded = set() if not isinstance(uris, list): uris = [uris] for item in uris: expanded.update(storage.expand_uri(item)) clause['value'] = list(expanded)
def _expand_uris(request, clause): uris = clause['value'] expanded = set() if not isinstance(uris, list): uris = [uris] for item in uris: expanded.update(storage.expand_uri(request, item)) clause['value'] = list(expanded)
def test_expand_uri_document_uris(self, db_session): document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://bar.com'), DocumentURI(uri='http://bar.com/', claimant='http://bar.com'), ]) db_session.add(document) db_session.flush() assert storage.expand_uri(db_session, 'http://foo.com/') == [ 'http://foo.com/', 'http://bar.com/' ]
def test_expand_uri_document_doesnt_expand_canonical_uris(self, db_session): document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://example.com'), DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com'), ]) db_session.add(document) db_session.flush() assert storage.expand_uri(db_session, "http://example.com/") == [ "http://example.com/"]
def test_expand_uri_document_doesnt_expand_canonical_uris(document_model): document = document_model.get_by_uri.return_value document.get.return_value = [ {"href": "http://foo.com/"}, {"href": "http://bar.com/"}, {"href": "http://example.com/", "rel": "canonical"}, ] document.uris.return_value = [ "http://foo.com/", "http://bar.com/", "http://example.com/", ] assert storage.expand_uri("http://example.com/") == ["http://example.com/"]
def __call__(self, params): if 'uri' not in params: return None query_uris = [v for k, v in params.items() if k == 'uri'] del params['uri'] uris = set() for query_uri in query_uris: us = [uri.normalize(u) for u in storage.expand_uri(self.request.db, query_uri)] uris.update(us) return {"terms": {"target.scope": list(uris)}}
def test_expand_uri_elastic_document_doesnt_expand_canonical_uris(postgres_enabled, document_model): postgres_enabled.return_value = False request = DummyRequest() document = document_model.get_by_uri.return_value type(document).document_uris = uris = mock.PropertyMock() uris.return_value = [ mock.Mock(uri='http://foo.com/'), mock.Mock(uri='http://bar.com/'), mock.Mock(uri='http://example.com/', type='rel-canonical'), ] assert storage.expand_uri(request, "http://example.com/") == [ "http://example.com/"]
def test_expand_uri_elastic_document_uris(self, postgres_enabled, models): postgres_enabled.return_value = False request = DummyRequest() document = models.elastic.Document.get_by_uri.return_value type(document).document_uris = uris = mock.PropertyMock() uris.return_value = [ mock.Mock(uri="http://foo.com/"), mock.Mock(uri="http://bar.com/"), ] assert storage.expand_uri(request, "http://example.com/") == [ "http://foo.com/", "http://bar.com/", ]
def test_expand_uri_postgres_document_uris(postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://bar.com'), DocumentURI(uri='http://bar.com/', claimant='http://bar.com'), ]) db.Session.add(document) db.Session.flush() assert storage.expand_uri( request, 'http://foo.com/') == ['http://foo.com/', 'http://bar.com/']
def test_expand_uri_document_doesnt_expand_canonical_uris( self, db_session): document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://example.com'), DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com'), ]) db_session.add(document) db_session.flush() assert storage.expand_uri( db_session, "http://example.com/") == ["http://example.com/"]
def test_expand_uri_elastic_document_doesnt_expand_canonical_uris( postgres_enabled, document_model): postgres_enabled.return_value = False request = DummyRequest() document = document_model.get_by_uri.return_value type(document).document_uris = uris = mock.PropertyMock() uris.return_value = [ mock.Mock(uri='http://foo.com/'), mock.Mock(uri='http://bar.com/'), mock.Mock(uri='http://example.com/', type='rel-canonical'), ] assert storage.expand_uri( request, "http://example.com/") == ["http://example.com/"]
def test_expand_uri_postgres_document_doesnt_expand_canonical_uris(postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://example.com'), DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com'), ]) db.Session.add(document) db.Session.flush() assert storage.expand_uri(request, "http://example.com/") == [ "http://example.com/"]
def test_expand_uri_postgres_document_uris(postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://bar.com'), DocumentURI(uri='http://bar.com/', claimant='http://bar.com'), ]) db.Session.add(document) db.Session.flush() assert storage.expand_uri(request, 'http://foo.com/') == [ 'http://foo.com/', 'http://bar.com/' ]
def test_expand_uri_postgres_document_doesnt_expand_canonical_uris( postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True document = Document(document_uris=[ DocumentURI(uri='http://foo.com/', claimant='http://example.com'), DocumentURI(uri='http://bar.com/', claimant='http://example.com'), DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com'), ]) db.Session.add(document) db.Session.flush() assert storage.expand_uri( request, "http://example.com/") == ["http://example.com/"]
def test_expand_uri_document_doesnt_expand_canonical_uris(document_model): document = document_model.get_by_uri.return_value document.get.return_value = [ { "href": "http://foo.com/" }, { "href": "http://bar.com/" }, { "href": "http://example.com/", "rel": "canonical" }, ] document.uris.return_value = [ "http://foo.com/", "http://bar.com/", "http://example.com/", ] assert storage.expand_uri("http://example.com/") == ["http://example.com/"]
def test_expand_uri_no_document(document_model): document_model.get_by_uri.return_value = None assert storage.expand_uri("http://example.com/") == ["http://example.com/"]
def test_expand_uri_no_document(self, db_session): actual = storage.expand_uri(db_session, 'http://example.com/') assert actual == ['http://example.com/']
def test_expand_uri_elastic_no_document(postgres_enabled, document_model): postgres_enabled.return_value = False request = DummyRequest() document_model.get_by_uri.return_value = None assert storage.expand_uri(request, "http://example.com/") == [ "http://example.com/"]
def test_expand_uri_postgres_no_document(postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True actual = storage.expand_uri(request, 'http://example.com/') assert actual == ['http://example.com/']
def test_expand_uri_elastic_no_document(self, postgres_enabled, models): postgres_enabled.return_value = False request = DummyRequest() models.elastic.Document.get_by_uri.return_value = None assert storage.expand_uri(request, "http://example.com/") == [ "http://example.com/"]
def test_expand_uri_postgres_no_document(self, postgres_enabled): request = DummyRequest(db=db.Session) postgres_enabled.return_value = True actual = storage.expand_uri(request, 'http://example.com/') assert actual == ['http://example.com/']