Exemple #1
0
    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}}
Exemple #2
0
    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}}
Exemple #3
0
    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}}
Exemple #4
0
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/",
    ]
Exemple #5
0
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/",
    ]
Exemple #6
0
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)
Exemple #7
0
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)
Exemple #8
0
    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/'
        ]
Exemple #9
0
    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/"]
Exemple #10
0
    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/'
        ]
Exemple #11
0
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/"]
Exemple #12
0
    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)}}
Exemple #13
0
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/"]
Exemple #14
0
 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/",
     ]
Exemple #15
0
 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/",
     ]
Exemple #16
0
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/']
Exemple #17
0
    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/"]
Exemple #18
0
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/"]
Exemple #19
0
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/"]
Exemple #20
0
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/'
    ]
Exemple #21
0
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/"]
Exemple #22
0
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/"]
Exemple #23
0
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/"]
Exemple #24
0
 def test_expand_uri_no_document(self, db_session):
     actual = storage.expand_uri(db_session, 'http://example.com/')
     assert actual == ['http://example.com/']
Exemple #25
0
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/"]
Exemple #26
0
 def test_expand_uri_no_document(self, db_session):
     actual = storage.expand_uri(db_session, 'http://example.com/')
     assert actual == ['http://example.com/']
Exemple #27
0
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/"]
Exemple #28
0
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/']
Exemple #29
0
 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/"]
Exemple #30
0
    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/']