Ejemplo n.º 1
0
    def test_parse_invalid_query(self):
        """Raise for malformed queries."""
        query = {'type': 'exact'}
        record = Record(self.data)

        with pytest.raises(InvalidQuery) as excinfo:
            _type, match, values, extras = _parse(query, record)
        self.assertIn('not defined in query', str(excinfo.value))
Ejemplo n.º 2
0
def test_parse_invalid_query(app, simple_record):
    """Raise for malformed queries."""
    with app.app_context():
        query = {'type': 'exact'}
        record = Record(simple_record)

        with pytest.raises(InvalidQuery) as excinfo:
            _type, match, values, extras = _parse(query, record)
        assert 'not defined in query' in str(excinfo.value)
Ejemplo n.º 3
0
def test_parse_invalid_query(app, simple_record):
    """Raise for malformed queries."""
    with app.app_context():
        query = {'type': 'exact'}
        record = Record(simple_record)

        with pytest.raises(InvalidQuery) as excinfo:
            _type, match, values, extras = _parse(query, record)
        assert 'not defined in query' in str(excinfo.value)
Ejemplo n.º 4
0
    def test_parse_query_can_override_values(self):
        """Parse a query overriding the extracted values."""
        query = {'type': 'exact', 'match': 'titles.title', 'values': ['qux quux']}
        record = Record(self.data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'titles.title')
        self.assertEqual(values, ['qux quux'])
        self.assertEqual(extras, {})
Ejemplo n.º 5
0
    def test_parse_query_with_extras(self):
        """Parse a query preserving other keyword arguments."""
        query = {'type': 'exact', 'match': 'titles.title', 'foo': 'bar'}
        record = Record(self.data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'titles.title')
        self.assertEqual(values, ['foo bar'])
        self.assertEqual(extras, {'foo': 'bar'})
Ejemplo n.º 6
0
    def test_parse_query_with_with(self):
        """Parse a query with the 'with' keyword."""
        query = {'type': 'exact', 'match': 'titles.title', 'with': 'oldtitles.title'}
        record = Record(self.data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'oldtitles.title')
        self.assertEqual(values, ['foo bar'])
        self.assertEqual(extras, {})
Ejemplo n.º 7
0
    def test_parse_simple_query(self):
        """Parse a simple query."""
        query = {'type': 'exact', 'match': 'titles.title'}
        record = Record(self.data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'titles.title')
        self.assertEqual(values, ['foo bar'])
        self.assertEqual(extras, {})
Ejemplo n.º 8
0
def test_parse_query_with_extras(app, simple_record):
    """Parse a query preserving other keyword arguments."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'foo': 'bar'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'title'
        assert values == ['foo bar']
        assert extras == {'foo': 'bar'}
Ejemplo n.º 9
0
def test_parse_query_can_override_values(app, simple_record):
    """Parse a query overriding the extracted values."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'values': ['qux quux']}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'title'
        assert values == ['qux quux']
        assert extras == {}
Ejemplo n.º 10
0
def test_parse_query_accepts_dotted_values(app, record):
    """Parse a query accepting dotted values."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'titles.title'}
        record = Record(record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'titles.title'
        assert values == ['foo bar']
        assert extras == {}
Ejemplo n.º 11
0
def test_parse_query_with_with(app, simple_record):
    """Parse a query with the 'with' keyword."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'with': 'titles.title'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'titles.title'
        assert values == ['foo bar']
        assert extras == {}
Ejemplo n.º 12
0
def test_parse_query_can_override_values(app, simple_record):
    """Parse a query overriding the extracted values."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'values': ['qux quux']}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'title'
        assert values == ['qux quux']
        assert extras == {}
Ejemplo n.º 13
0
def test_parse_query_with_extras(app, simple_record):
    """Parse a query preserving other keyword arguments."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'foo': 'bar'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'title'
        assert values == ['foo bar']
        assert extras == {'foo': 'bar'}
Ejemplo n.º 14
0
def test_parse_query_with_with(app, simple_record):
    """Parse a query with the 'with' keyword."""
    with app.app_context():
        query = {'type': 'exact', 'match': 'title', 'with': 'titles.title'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'titles.title'
        assert values == ['foo bar']
        assert extras == {}
Ejemplo n.º 15
0
    def test_parse_query_with_invalid_path(self):
        """Parse a query on a record with invalid_path.

        We want to make sure that, even when we give an invalid path
        to the Record API we get back an empty list.
        """
        query = {'type': 'exact', 'match': 'titles.title'}
        record = Record(self.simple_data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'titles.title')
        self.assertEqual(values, [])
        self.assertEqual(extras, {})
Ejemplo n.º 16
0
    def test_parse_query_without_lists(self):
        """Parse a query on a record without lists.

        We want to make sure that, even when the Record API does not
        return a list, we are getting a list for the 'values' variable.
        """
        query = {'type': 'exact', 'match': 'title'}
        record = Record(self.simple_data)

        _type, match, values, extras = _parse(query, record)

        self.assertEqual(_type, 'exact')
        self.assertEqual(match, 'title')
        self.assertEqual(values, ['foo bar'])
        self.assertEqual(extras, {})
Ejemplo n.º 17
0
def test_parse_query_with_invalid_path(app, simple_record):
    """Parse a query on a record with invalid_path.

    We want to make sure that, even when we give an invalid path
    to the Record API we get back an empty list.
    """
    with app.app_context():
        query = {'type': 'exact', 'match': 'titles.title'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'titles.title'
        assert values == []
        assert extras == {}
Ejemplo n.º 18
0
def test_parse_query_with_invalid_path(app, simple_record):
    """Parse a query on a record with invalid_path.

    We want to make sure that, even when we give an invalid path
    to the Record API we get back an empty list.
    """
    with app.app_context():
        query = {'type': 'exact', 'match': 'titles.title'}
        record = Record(simple_record)

        _type, match, values, extras = _parse(query, record)

        assert _type == 'exact'
        assert match == 'titles.title'
        assert values == []
        assert extras == {}