Exemplo n.º 1
0
Arquivo: query.py Projeto: VanyTang/h
    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}}
Exemplo n.º 2
0
Arquivo: query.py Projeto: hashin/h
    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}}
Exemplo n.º 3
0
Arquivo: query.py Projeto: bZichett/h
    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}}
Exemplo n.º 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/",
    ]
Exemplo n.º 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/",
    ]
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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/'
        ]
Exemplo n.º 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/"]
Exemplo n.º 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/'
        ]
Exemplo n.º 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/"]
Exemplo n.º 12
0
Arquivo: query.py Projeto: djcun95/h
    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)}}
Exemplo n.º 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/"]
Exemplo n.º 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/",
     ]
Exemplo n.º 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/",
     ]
Exemplo n.º 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/']
Exemplo n.º 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/"]
Exemplo n.º 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/"]
Exemplo n.º 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/"]
Exemplo n.º 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/'
    ]
Exemplo n.º 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/"]
Exemplo n.º 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/"]
Exemplo n.º 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/"]
Exemplo n.º 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/']
Exemplo n.º 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/"]
Exemplo n.º 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/']
Exemplo n.º 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/"]
Exemplo n.º 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/']
Exemplo n.º 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/"]
Exemplo n.º 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/']