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))
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)
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)
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, {})
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'})
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, {})
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, {})
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'}
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 == {}
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 == {}
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 == {}
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 == {}
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'}
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 == {}
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, {})
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, {})
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 == {}
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 == {}