Esempio n. 1
0
def test_default_deduplication_validator(app, simple_record, mocker):
    """Make sure default deduplication validator works."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.api.execute', duplicated_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        expected = [MatchResult(1, record, 1)]
        result = list(match(
            record,
            index="records",
            doc_type="record",
            queries=queries,
            validator=None,
        ))

        assert expected == result

        # Test the same again to see if validator resets
        expected = [MatchResult(1, record, 1)]
        result = list(match(
            record,
            index="records",
            doc_type="record",
            queries=queries,
            validator=None,
        ))

        assert expected == result
Esempio n. 2
0
def test_default_deduplication_validator(app, simple_record, mocker):
    """Make sure default deduplication validator works."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.api.execute', duplicated_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        expected = [MatchResult(1, record, 1)]
        result = list(
            match(
                record,
                index="records",
                doc_type="record",
                queries=queries,
                validator=None,
            ))

        assert expected == result

        # Test the same again to see if validator resets
        expected = [MatchResult(1, record, 1)]
        result = list(
            match(
                record,
                index="records",
                doc_type="record",
                queries=queries,
                validator=None,
            ))

        assert expected == result
Esempio n. 3
0
    def test_match_no_queries(self):
        """Raise when no query are defined."""
        record = Record(self.data)

        with pytest.raises(NoQueryDefined) as excinfo:
            list(match(record))
        self.assertIn('passed or defined', str(excinfo.value))
Esempio n. 4
0
    def test_match_with_configured_queries(self):
        """Search using configured queries."""
        record = Record(self.data)

        expected = []
        result = list(match(record))

        self.assertEqual(expected, result)
Esempio n. 5
0
    def test_match_with_passed_queries(self):
        """Search using queries passed as an argument."""
        record = Record(self.data)
        queries = [{'type': 'exact', 'match': 'titles.title'}]

        expected = [MatchResult(record, 1)]
        result = list(match(record, queries=queries))

        self.assertEqual(expected, result)
Esempio n. 6
0
def test_match_no_queries(app, simple_record):
    """Raise when no query is defined."""
    from invenio_records import Record

    with app.app_context():
        record = Record(simple_record)

        with pytest.raises(NoQueryDefined) as excinfo:
            list(match(record, index="records", doc_type="record"))
        assert 'No query defined' in str(excinfo.value)
Esempio n. 7
0
def test_match_no_queries(app, simple_record):
    """Raise when no query is defined."""
    from invenio_records import Record

    with app.app_context():
        record = Record(simple_record)

        with pytest.raises(NoQueryDefined) as excinfo:
            list(match(record, index="records", doc_type="record"))
        assert 'No query defined' in str(excinfo.value)
Esempio n. 8
0
def test_match_no_queries_config(app, simple_record):
    """Raise when no query is defined properly in config."""
    from invenio_records import Record

    app.config.update(dict(MATCHER_QUERIES={"records": {"record": []}}))
    with app.app_context():
        record = Record(simple_record)

        with pytest.raises(NoQueryDefined) as excinfo:
            list(match(record, index="records", doc_type="record"))
        assert 'No query passed or defined' in str(excinfo.value)
Esempio n. 9
0
def test_match_no_queries_config(app, simple_record):
    """Raise when no query is defined properly in config."""
    from invenio_records import Record

    app.config.update(dict(MATCHER_QUERIES={"records": {"record": []}}))
    with app.app_context():
        record = Record(simple_record)

        with pytest.raises(NoQueryDefined) as excinfo:
            list(match(record, index="records", doc_type="record"))
        assert 'No query passed or defined' in str(excinfo.value)
Esempio n. 10
0
    def test_match_with_validator(self):
        """Validate results with a validator function."""
        record = Record(self.data)
        queries = [{'type': 'exact', 'match': 'titles.title'}]

        def validator(record, result):
            return record['titles'][0]['title'] == 'bar foo'

        expected = []
        result = list(match(record, queries=queries, validator=validator))

        self.assertEqual(expected, result)
Esempio n. 11
0
def test_match_with_passed_queries(app, simple_record, mocker):
    """Search using queries passed as an argument."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', one_search_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        expected = [MatchResult(1, record, 1)]
        result = list(
            match(record, index="records", doc_type="record", queries=queries))
        assert expected == result
Esempio n. 12
0
def test_match_with_configured_queries(app, simple_record,
                                       matcher_config, mocker):
    """Search using queries from config."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', empty_search_result)

    app.config.update(dict(MATCHER_QUERIES=matcher_config))
    with app.app_context():
        record = Record(simple_record)

        expected = []
        result = list(match(record, index="records", doc_type="record"))

        assert expected == result
Esempio n. 13
0
def test_match_with_configured_queries(app, simple_record, matcher_config,
                                       mocker):
    """Search using queries from config."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', empty_search_result)

    app.config.update(dict(MATCHER_QUERIES=matcher_config))
    with app.app_context():
        record = Record(simple_record)

        expected = []
        result = list(match(record, index="records", doc_type="record"))

        assert expected == result
Esempio n. 14
0
def test_match_with_passed_queries(app, simple_record, mocker):
    """Search using queries passed as an argument."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', one_search_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        expected = [MatchResult(1, record, 1)]
        result = list(match(
            record,
            index="records",
            doc_type="record",
            queries=queries
        ))
        assert expected == result
Esempio n. 15
0
def test_match_with_validator(app, simple_record, mocker):
    """Validate results with a validator function."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', one_search_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        def validator(record, result):
            return record['title'] == 'bar foo'

        expected = []
        result = list(match(
            record,
            index="records",
            doc_type="record",
            queries=queries,
            validator=validator,
        ))

        assert expected == result
Esempio n. 16
0
def test_match_with_validator(app, simple_record, mocker):
    """Validate results with a validator function."""
    from invenio_records import Record
    mocker.patch('invenio_matcher.engine.search', one_search_result)

    with app.app_context():
        record = Record(simple_record)
        queries = [{'type': 'exact', 'match': 'title'}]

        def validator(record, result):
            return record['title'] == 'bar foo'

        expected = []
        result = list(
            match(
                record,
                index="records",
                doc_type="record",
                queries=queries,
                validator=validator,
            ))

        assert expected == result